pkg

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2026 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	None    = 0
	Tls     = 1
	Reality = 2
)

Security type

View Source
const (
	Shadowsocks = "shadowsocks"
	Trojan      = "trojan"
	Vmess       = "vmess"
	Vless       = "vless"
	Tuic        = "tuic"
	Hysteria    = "hysteria"
	Hysteria2   = "hysteria2"
	AnyTls      = "anytls"
)

Node types

View Source
const (
	RouteActionBlock      = "block"
	RouteActionBlockIP    = "block_ip"
	RouteActionBlockPort  = "block_port"
	RouteActionProtocol   = "protocol"
	RouteActionDNS        = "dns"
	RouteActionRoute      = "route"
	RouteActionRouteIP    = "route_ip"
	RouteActionDefaultOut = "default_out"
)

Variables

This section is empty.

Functions

func IntervalToTime

func IntervalToTime(i interface{}) time.Duration

Helper function to convert dynamic interval types to time.Duration

func IsBlockRouteAction added in v0.0.9

func IsBlockRouteAction(action string) bool

func IsCustomRouteAction added in v0.0.9

func IsCustomRouteAction(action string) bool

func IsDefaultOutboundRouteAction added in v0.0.9

func IsDefaultOutboundRouteAction(action string) bool

func NormalizeRouteMatch added in v0.0.9

func NormalizeRouteMatch(match interface{}) []string

func SplitBlockRouteMatches added in v0.0.9

func SplitBlockRouteMatches(matches []string) ([]string, []string)

func TrimRouteValues added in v0.0.9

func TrimRouteValues(values []string) []string

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

func NewAPIErrorFromStatusCode(statusCode int, message string, url string, err error) *APIError

NewAPIErrorFromStatusCode infers error type from status code automatically

func NewBusinessLogicError

func NewBusinessLogicError(message string, url string) *APIError

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

func NewNetworkError(message string, url string, err error) *APIError

NewNetworkError creates a network error

func NewNotModifiedError

func NewNotModifiedError() *APIError

NewNotModifiedError creates a 304 Not Modified error

func NewParseError

func NewParseError(message string, err error) *APIError

NewParseError creates a parse error

func (*APIError) Error

func (e *APIError) Error() string

Error implements error interface

func (*APIError) GoString added in v0.0.10

func (e *APIError) GoString() string

func (*APIError) IsNetworkError

func (e *APIError) IsNetworkError() bool

IsNetworkError checks if it is a network error

func (*APIError) IsNotModified

func (e *APIError) IsNotModified() bool

IsNotModified checks if it is 304 Not Modified

func (*APIError) IsParseError

func (e *APIError) IsParseError() bool

IsParseError checks if it is a parse error

func (*APIError) IsServerError

func (e *APIError) IsServerError() bool

IsServerError checks if it is a server error (4xx/5xx)

func (*APIError) Unwrap

func (e *APIError) Unwrap() error

Unwrap implements errors.Unwrap interface

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

func (AnyTlsNode) GoString added in v0.0.10

func (n AnyTlsNode) GoString() string

func (AnyTlsNode) String added in v0.0.10

func (n AnyTlsNode) String() string

type BaseConfig

type BaseConfig struct {
	PushInterval any `json:"push_interval"`
	PullInterval any `json:"pull_interval"`
}

func (BaseConfig) GoString added in v0.0.10

func (c BaseConfig) GoString() string

func (BaseConfig) String added in v0.0.10

func (c BaseConfig) String() string

type Client

type Client struct {

	// Deprecated: this field is informational; mutating it does not affect client behavior.
	APIHost string
	// Deprecated: this field is informational; mutating it does not affect client behavior.
	APISendIP string
	// Deprecated: this field is informational; mutating it does not affect client behavior.
	Token string
	// Deprecated: this field is informational; mutating it does not affect client behavior.
	NodeType string
	// Deprecated: this field is informational; mutating it does not affect client behavior.
	NodeId int
	// contains filtered or unexported fields
}

Client APIClient create a api client to the panel.

func New

func New(c *Config) *Client

New creates an API client for the panel and returns nil when config validation fails.

func NewWithError added in v0.0.10

func NewWithError(c *Config) (*Client, error)

func (*Client) CachedUserList added in v0.0.10

func (c *Client) CachedUserList() []UserInfo

CachedUserList returns a copy of the cached users.

func (*Client) Debug

func (c *Client) Debug(enable bool)

Debug is disabled because request debug logging can expose authentication credentials and tokens. Deprecated: configure application-level sanitized logging instead.

func (*Client) GetAliveList added in v0.0.9

func (c *Client) GetAliveList(ctx context.Context) (map[int]int, error)

func (*Client) GetNodeInfo

func (c *Client) GetNodeInfo(ctx context.Context) (node *NodeInfo, err error)

func (*Client) GetUserList

func (c *Client) GetUserList(ctx context.Context) ([]UserInfo, error)

GetUserList will pull user from v2board

func (*Client) GoString added in v0.0.10

func (c *Client) GoString() string

func (*Client) ReportNodeOnlineUsers

func (c *Client) ReportNodeOnlineUsers(ctx context.Context, data map[int][]netip.Addr) error

func (*Client) ReportUserTraffic

func (c *Client) ReportUserTraffic(ctx context.Context, userTraffic []UserTraffic) error

func (*Client) String added in v0.0.10

func (c *Client) String() string

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"`
}

func (CommonNode) GoString added in v0.0.10

func (n CommonNode) GoString() string

func (CommonNode) String added in v0.0.10

func (n CommonNode) String() string

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 EncSettings struct {
	Mode          string `json:"mode"`
	Ticket        string `json:"ticket"`
	ServerPadding string `json:"server_padding"`
	PrivateKey    string `json:"private_key"`
}

func (EncSettings) GoString added in v0.0.10

func (e EncSettings) GoString() string

func (EncSettings) String added in v0.0.10

func (e EncSettings) String() string

type ErrorType

type ErrorType string

ErrorType defines the type of error

const (
	// HTTP Errors
	ErrorTypeServerError ErrorType = "ServerError" // HTTP 4xx/5xx response

	// 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
	Version               int    `json:"version"`
	IgnoreClientBandwidth 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

func (Hysteria2Node) GoString added in v0.0.10

func (n Hysteria2Node) GoString() string

func (Hysteria2Node) String added in v0.0.10

func (n Hysteria2Node) String() string

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
	Version  int    `json:"version"`
	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

func (HysteriaNode) GoString added in v0.0.10

func (n HysteriaNode) GoString() string

func (HysteriaNode) String added in v0.0.10

func (n HysteriaNode) String() string

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
	Routes       []Route

	// origin
	VMess       *VMessNode
	Vless       *VlessNode
	Shadowsocks *ShadowsocksNode
	Trojan      *TrojanNode
	Tuic        *TuicNode
	AnyTls      *AnyTlsNode
	Hysteria    *HysteriaNode
	Hysteria2   *Hysteria2Node
	Common      *CommonNode
}

func (NodeInfo) GoString added in v0.0.10

func (n NodeInfo) GoString() string

func (*NodeInfo) ProcessCommonNode added in v0.0.6

func (node *NodeInfo) ProcessCommonNode(cm *CommonNode)

ProcessCommonNode handles the common node configuration like routes and DNS.

func (NodeInfo) String added in v0.0.10

func (n NodeInfo) String() string

type OnlineUser

type OnlineUser struct {
	UID int
	IP  string
}

User structures

func (OnlineUser) GoString added in v0.0.10

func (u OnlineUser) GoString() string

func (OnlineUser) String added in v0.0.10

func (u OnlineUser) String() string

type RawDNS

type RawDNS struct {
	DNSMap  map[string]map[string]interface{}
	DNSJson []byte
}

func (RawDNS) GoString added in v0.0.10

func (d RawDNS) GoString() string

func (RawDNS) String added in v0.0.10

func (d RawDNS) String() string

type RealityConfig

type RealityConfig struct {
	Xver         uint64 `json:"Xver"`
	MinClientVer string `json:"MinClientVer"`
	MaxClientVer string `json:"MaxClientVer"`
	MaxTimeDiff  string `json:"MaxTimeDiff"`
}

type Route

type Route struct {
	Id          int         `json:"id"`
	Match       interface{} `json:"match"`
	Action      string      `json:"action"`
	ActionValue string      `json:"action_value"`
}

func (Route) DNSMatches added in v0.0.10

func (r Route) DNSMatches() []string

func (Route) GoString added in v0.0.10

func (r Route) GoString() string

func (Route) Matches added in v0.0.9

func (r Route) Matches() []string

func (Route) String added in v0.0.10

func (r Route) String() string

type Rules

type Rules struct {
	Regexp   []string
	Protocol []string
}

func (Rules) GoString added in v0.0.10

func (r Rules) GoString() string

func (Rules) String added in v0.0.10

func (r Rules) String() string

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

func (ShadowsocksNode) GoString added in v0.0.10

func (n ShadowsocksNode) GoString() string

func (ShadowsocksNode) String added in v0.0.10

func (n ShadowsocksNode) String() string

type TlsSettings

type TlsSettings struct {
	ServerName  string `json:"server_name"`
	Dest        string `json:"dest"`
	ServerPort  string `json:"server_port"`
	ShortId     string `json:"short_id"`
	PrivateKey  string `json:"private_key"`
	Mldsa65Seed string `json:"mldsa65Seed"`
	Xver        uint64 `json:"xver,string"`
}

func (TlsSettings) GoString added in v0.0.10

func (t TlsSettings) GoString() string

func (TlsSettings) String added in v0.0.10

func (t TlsSettings) String() string

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

func (TrojanNode) GoString added in v0.0.10

func (n TrojanNode) GoString() string

func (TrojanNode) String added in v0.0.10

func (n TrojanNode) String() string

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

func (TuicNode) GoString added in v0.0.10

func (n TuicNode) GoString() string

func (TuicNode) String added in v0.0.10

func (n TuicNode) String() string

type UserInfo

type UserInfo struct {
	Id          int    `json:"id"`
	Uuid        string `json:"uuid"`
	SpeedLimit  int    `json:"speed_limit"`
	DeviceLimit int    `json:"device_limit"`
}

func (UserInfo) GoString added in v0.0.10

func (u UserInfo) GoString() string

func (UserInfo) String added in v0.0.10

func (u UserInfo) String() string

type UserListBody

type UserListBody struct {
	Users []UserInfo `json:"users"`
}

func (UserListBody) GoString added in v0.0.10

func (u UserListBody) GoString() string

func (UserListBody) String added in v0.0.10

func (u UserListBody) String() string

type UserTraffic

type UserTraffic struct {
	UID      int
	Upload   int64
	Download int64
}

type VMessHandler added in v0.0.6

type VMessHandler struct{}

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"`
	Network            string          `json:"network"`
	NetworkSettings    json.RawMessage `json:"networkSettings"`
	Encryption         string          `json:"encryption"`
	EncryptionSettings EncSettings     `json:"encryption_settings"`
}

VMessNode is vmess node info

func (*VMessNode) GetCommonNode added in v0.0.4

func (n *VMessNode) GetCommonNode() *CommonNode

func (VMessNode) GoString added in v0.0.10

func (n VMessNode) GoString() string

func (VMessNode) String added in v0.0.10

func (n VMessNode) String() string

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"`
	Network            string          `json:"network"`
	NetworkSettings    json.RawMessage `json:"networkSettings"`
	Encryption         string          `json:"encryption"`
	EncryptionSettings EncSettings     `json:"encryption_settings"`
	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

func (VlessNode) GoString added in v0.0.10

func (n VlessNode) GoString() string

func (VlessNode) String added in v0.0.10

func (n VlessNode) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL