Documentation
¶
Index ¶
- Constants
- func IntervalToTime(i interface{}) time.Duration
- type APIError
- func NewAPIError(statusCode int, errorType ErrorType, message string, url string, err error) *APIError
- func NewAPIErrorFromStatusCode(statusCode int, message string, url string, err error) *APIError
- func NewBusinessLogicError(message string, url string) *APIError
- func NewNetworkError(message string, url string, err error) *APIError
- func NewNotModifiedError() *APIError
- func NewParseError(message string, err error) *APIError
- type AliveMap
- type AnyTlsHandler
- type AnyTlsNode
- type BaseConfig
- type Client
- func (c *Client) Debug(enable bool)
- func (c *Client) GetNodeInfo(ctx context.Context) (node *NodeInfo, err error)
- func (c *Client) GetUserList(ctx context.Context) ([]UserInfo, error)
- func (c *Client) ReportNodeOnlineUsers(ctx context.Context, data map[int][]string) error
- func (c *Client) ReportUserTraffic(ctx context.Context, userTraffic []UserTraffic) error
- type CommonNode
- type Config
- type EncSettings
- type ErrorType
- type Hysteria2Handler
- type Hysteria2Node
- type HysteriaHandler
- type HysteriaNode
- type Node
- type NodeHandler
- type NodeInfo
- type OnlineUser
- type RawDNS
- type RealityConfig
- type Route
- type Rules
- type ShadowsocksHandler
- type ShadowsocksNode
- type TlsSettings
- type TrojanHandler
- type TrojanNode
- type TuicHandler
- type TuicNode
- type UserInfo
- type UserListBody
- type UserTraffic
- type VMessHandler
- type VMessNode
- type VlessHandler
- type VlessNode
Constants ¶
const ( None = 0 Tls = 1 Reality = 2 )
Security type
const ( Shadowsocks = "shadowsocks" Trojan = "trojan" Vmess = "vmess" Vless = "vless" Tuic = "tuic" Hysteria = "hysteria" Hysteria2 = "hysteria2" AnyTls = "anytls" )
Node types
Variables ¶
This section is empty.
Functions ¶
func IntervalToTime ¶
Helper function to convert dynamic interval types to time.Duration
Types ¶
type APIError ¶
type APIError struct {
StatusCode int // HTTP Status Code
Type ErrorType // Error Type
Message string // Error Message
URL string // Request URL
Err error // Original Error
}
APIError custom API error type
func NewAPIError ¶
func NewAPIError(statusCode int, errorType ErrorType, message string, url string, err error) *APIError
NewAPIError creates a new API error
func NewAPIErrorFromStatusCode ¶
NewAPIErrorFromStatusCode infers error type from status code automatically
func NewBusinessLogicError ¶
NewBusinessLogicError creates a business logic error Business logic errors usually come from the Message field in API response, default treated as Server Error (500)
func NewNetworkError ¶
NewNetworkError creates a network error
func NewNotModifiedError ¶
func NewNotModifiedError() *APIError
NewNotModifiedError creates a 304 Not Modified error
func NewParseError ¶
NewParseError creates a parse error
func (*APIError) IsNetworkError ¶
IsNetworkError checks if it is a network error
func (*APIError) IsNotModified ¶
IsNotModified checks if it is 304 Not Modified
func (*APIError) IsParseError ¶
IsParseError checks if it is a parse error
func (*APIError) IsServerError ¶
IsServerError checks if it is a server error (4xx/5xx)
type AnyTlsHandler ¶ added in v0.0.6
type AnyTlsHandler struct{}
-- AnyTls --
func (*AnyTlsHandler) ParseConfig ¶ added in v0.0.6
func (h *AnyTlsHandler) ParseConfig(info *NodeInfo, data []byte) (*CommonNode, error)
type AnyTlsNode ¶
type AnyTlsNode struct {
CommonNode
PaddingScheme []string `json:"padding_scheme,omitempty"`
}
func (*AnyTlsNode) GetCommonNode ¶ added in v0.0.4
func (n *AnyTlsNode) GetCommonNode() *CommonNode
type BaseConfig ¶
type Client ¶
type Client struct {
APIHost string
APISendIP string
Token string
NodeType string
NodeId int
UserList *UserListBody
AliveMap *AliveMap
// contains filtered or unexported fields
}
Client APIClient create a api client to the panel.
func (*Client) GetNodeInfo ¶
func (*Client) GetUserList ¶
GetUserList will pull user from v2board
func (*Client) ReportNodeOnlineUsers ¶
func (*Client) ReportUserTraffic ¶
func (c *Client) ReportUserTraffic(ctx context.Context, userTraffic []UserTraffic) error
Upload/Download are type int64 in UserTraffic struct in model.go
type CommonNode ¶
type CommonNode struct {
Host string `json:"host"`
ServerPort int `json:"server_port"`
ServerName string `json:"server_name"`
Routes []Route `json:"routes"`
BaseConfig *BaseConfig `json:"base_config"`
}
type Config ¶
type Config struct {
APIHost string
APISendIP string
NodeID int
Key string
NodeType string
Timeout int // seconds
Debug bool
}
Config api config
type EncSettings ¶
type ErrorType ¶
type ErrorType string
ErrorType defines the type of error
const ( // HTTP Errors ErrorTypeServerError ErrorType = "ServerError" // 5xx Server Error // Special Error Types ErrorTypeNetworkError ErrorType = "NetworkError" // Network Connection Error ErrorTypeParseError ErrorType = "ParseError" // Response Parse Error ErrorTypeNotModified ErrorType = "NotModified" // 304 Not Modified ErrorTypeUnknown ErrorType = "Unknown" // Unknown Error )
type Hysteria2Handler ¶ added in v0.0.6
type Hysteria2Handler struct{}
-- Hysteria2 --
func (*Hysteria2Handler) ParseConfig ¶ added in v0.0.6
func (h *Hysteria2Handler) ParseConfig(info *NodeInfo, data []byte) (*CommonNode, error)
type Hysteria2Node ¶
type Hysteria2Node struct {
CommonNode
Ignore_Client_Bandwidth bool `json:"ignore_client_bandwidth"`
UpMbps int `json:"up_mbps"`
DownMbps int `json:"down_mbps"`
ObfsType string `json:"obfs"`
ObfsPassword string `json:"obfs-password"`
}
func (*Hysteria2Node) GetCommonNode ¶ added in v0.0.4
func (n *Hysteria2Node) GetCommonNode() *CommonNode
type HysteriaHandler ¶ added in v0.0.6
type HysteriaHandler struct{}
-- Hysteria --
func (*HysteriaHandler) ParseConfig ¶ added in v0.0.6
func (h *HysteriaHandler) ParseConfig(info *NodeInfo, data []byte) (*CommonNode, error)
type HysteriaNode ¶
type HysteriaNode struct {
CommonNode
UpMbps int `json:"up_mbps"`
DownMbps int `json:"down_mbps"`
Obfs string `json:"obfs"`
}
func (*HysteriaNode) GetCommonNode ¶ added in v0.0.4
func (n *HysteriaNode) GetCommonNode() *CommonNode
type Node ¶ added in v0.0.4
type Node interface {
GetCommonNode() *CommonNode
}
Node interface for polymorphic handling
type NodeHandler ¶ added in v0.0.6
type NodeHandler interface {
// ParseConfig parses the raw JSON body and assigns the result to the matching field in NodeInfo.
// It returns the CommonNode for shared processing.
ParseConfig(node *NodeInfo, data []byte) (*CommonNode, error)
}
NodeHandler defines the interface that all protocol handlers must implement.
type NodeInfo ¶
type NodeInfo struct {
Id int
Type string
Security int
PushInterval time.Duration
PullInterval time.Duration
RawDNS RawDNS
Rules Rules
// origin
VMess *VMessNode
Vless *VlessNode
Shadowsocks *ShadowsocksNode
Trojan *TrojanNode
Tuic *TuicNode
AnyTls *AnyTlsNode
Hysteria *HysteriaNode
Hysteria2 *Hysteria2Node
Common *CommonNode
}
func (*NodeInfo) ProcessCommonNode ¶ added in v0.0.6
func (node *NodeInfo) ProcessCommonNode(cm *CommonNode)
ProcessCommonNode handles the common node configuration like routes and DNS.
type RealityConfig ¶
type ShadowsocksHandler ¶ added in v0.0.6
type ShadowsocksHandler struct{}
-- Shadowsocks --
func (*ShadowsocksHandler) ParseConfig ¶ added in v0.0.6
func (h *ShadowsocksHandler) ParseConfig(info *NodeInfo, data []byte) (*CommonNode, error)
type ShadowsocksNode ¶
type ShadowsocksNode struct {
CommonNode
Cipher string `json:"cipher"`
ServerKey string `json:"server_key"`
Obfs string `json:"obfs"`
ObfsSettings json.RawMessage `json:"obfs_settings"`
}
func (*ShadowsocksNode) GetCommonNode ¶ added in v0.0.4
func (n *ShadowsocksNode) GetCommonNode() *CommonNode
type TlsSettings ¶
type TrojanHandler ¶ added in v0.0.6
type TrojanHandler struct{}
-- Trojan --
func (*TrojanHandler) ParseConfig ¶ added in v0.0.6
func (h *TrojanHandler) ParseConfig(info *NodeInfo, data []byte) (*CommonNode, error)
type TrojanNode ¶
type TrojanNode struct {
CommonNode
Network string `json:"network"`
NetworkSettings json.RawMessage `json:"networkSettings"`
}
func (*TrojanNode) GetCommonNode ¶ added in v0.0.4
func (n *TrojanNode) GetCommonNode() *CommonNode
type TuicHandler ¶ added in v0.0.6
type TuicHandler struct{}
-- Tuic --
func (*TuicHandler) ParseConfig ¶ added in v0.0.6
func (h *TuicHandler) ParseConfig(info *NodeInfo, data []byte) (*CommonNode, error)
type TuicNode ¶
type TuicNode struct {
CommonNode
CongestionControl string `json:"congestion_control"`
ZeroRTTHandshake bool `json:"zero_rtt_handshake"`
}
func (*TuicNode) GetCommonNode ¶ added in v0.0.4
func (n *TuicNode) GetCommonNode() *CommonNode
type UserListBody ¶
type UserListBody struct {
Users []UserInfo `json:"users"`
}
type UserTraffic ¶
type VMessHandler ¶ added in v0.0.6
type VMessHandler struct{}
-- VMess --
func (*VMessHandler) ParseConfig ¶ added in v0.0.6
func (h *VMessHandler) ParseConfig(info *NodeInfo, data []byte) (*CommonNode, error)
type VMessNode ¶
type VMessNode struct {
CommonNode
Tls int `json:"tls"`
TlsSettings TlsSettings `json:"tls_settings"`
TlsSettingsBack *TlsSettings `json:"tlsSettings"`
Network string `json:"network"`
NetworkSettings json.RawMessage `json:"network_settings"`
NetworkSettingsBack json.RawMessage `json:"networkSettings"`
Encryption string `json:"encryption"`
EncryptionSettings EncSettings `json:"encryption_settings"`
ServerName string `json:"server_name"`
}
VMessNode is vmess node info
func (*VMessNode) GetCommonNode ¶ added in v0.0.4
func (n *VMessNode) GetCommonNode() *CommonNode
type VlessHandler ¶ added in v0.0.6
type VlessHandler struct{}
-- VLESS --
func (*VlessHandler) ParseConfig ¶ added in v0.0.6
func (h *VlessHandler) ParseConfig(info *NodeInfo, data []byte) (*CommonNode, error)
type VlessNode ¶
type VlessNode struct {
CommonNode
Tls int `json:"tls"`
TlsSettings TlsSettings `json:"tls_settings"`
TlsSettingsBack *TlsSettings `json:"tlsSettings"`
Network string `json:"network"`
NetworkSettings json.RawMessage `json:"network_settings"`
NetworkSettingsBack json.RawMessage `json:"networkSettings"`
Encryption string `json:"encryption"`
EncryptionSettings EncSettings `json:"encryption_settings"`
ServerName string `json:"server_name"`
Flow string `json:"flow"`
RealityConfig RealityConfig `json:"-"`
}
VlessNode is vless node info
func (*VlessNode) GetCommonNode ¶ added in v0.0.4
func (n *VlessNode) GetCommonNode() *CommonNode