pkg

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorUserNotModified = NewNotModifiedError()

ErrorUserNotModified 用户数据未修改错误 (304)

Functions

func AsConfig

func AsConfig[T NodeConfig](nc NodeConfig) (T, error)

func MarshalTrafficStats added in v0.0.7

func MarshalTrafficStats(stats *TrafficStats) ([]byte, error)

func MarshalTraffics added in v0.0.7

func MarshalTraffics(traffics []*UserTraffic) ([]byte, error)

func UnmarshalConfig added in v0.0.12

func UnmarshalConfig[T any](data []byte) (*T, error)

UnmarshalConfig 是一个通用的泛型反序列化函数

func UnmarshalUsers

func UnmarshalUsers(data []byte) (*[]User, error)

Types

type APIError added in v0.1.0

type APIError struct {
	StatusCode int       // HTTP状态码
	Type       ErrorType // 错误类型
	Message    string    // 错误消息
	URL        string    // 请求的URL
	Err        error     // 原始错误
}

APIError 自定义API错误类型

func NewAPIError added in v0.1.0

func NewAPIError(statusCode int, errorType ErrorType, message string, url string, err error) *APIError

NewAPIError 创建一个新的API错误

func NewAPIErrorFromStatusCode added in v0.1.0

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

NewAPIErrorFromStatusCode 根据状态码自动推断错误类型

func NewBusinessLogicError added in v0.1.0

func NewBusinessLogicError(message string, url string) *APIError

NewBusinessLogicError 创建业务逻辑错误 业务逻辑错误通常来自API响应中的Message字段,默认视为服务端错误(500)

func NewNetworkError added in v0.1.0

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

NewNetworkError 创建网络错误

func NewNotModifiedError added in v0.1.0

func NewNotModifiedError() *APIError

NewNotModifiedError 创建304未修改错误

func NewParseError added in v0.1.0

func NewParseError(message string, err error) *APIError

NewParseError 创建解析错误

func (*APIError) Error added in v0.1.0

func (e *APIError) Error() string

Error 实现error接口

func (*APIError) IsNetworkError added in v0.1.0

func (e *APIError) IsNetworkError() bool

IsNetworkError 判断是否为网络错误

func (*APIError) IsNotModified added in v0.1.0

func (e *APIError) IsNotModified() bool

IsNotModified 判断是否为304未修改

func (*APIError) IsParseError added in v0.1.0

func (e *APIError) IsParseError() bool

IsParseError 判断是否为解析错误

func (*APIError) IsServerError added in v0.1.0

func (e *APIError) IsServerError() bool

IsServerError 判断是否为服务端错误 (4xx/5xx)

func (*APIError) Unwrap added in v0.1.0

func (e *APIError) Unwrap() error

Unwrap 实现errors.Unwrap接口

type AnyTLSConfig added in v0.0.12

type AnyTLSConfig struct {
	ID            int    `json:"id"`
	ServerPort    int    `json:"server_port"`
	AllowInsecure int    `json:"allow_insecure"`
	ServerName    string `json:"server_name"`
	PaddingRules  string `json:"padding_rules"`
}

func AsAnyTLSConfig added in v0.0.12

func AsAnyTLSConfig(nc NodeConfig) (*AnyTLSConfig, error)

func UnmarshalAnyTLSConfig added in v0.0.12

func UnmarshalAnyTLSConfig(data []byte) (*AnyTLSConfig, error)

func (*AnyTLSConfig) String added in v0.0.12

func (n *AnyTLSConfig) String() string

func (*AnyTLSConfig) TypeName added in v0.0.12

func (n *AnyTLSConfig) TypeName() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client APIClient create a api client to the panel.

func New

func New(apiConfig *Config) *Client

New creat a api instance

func (*Client) Config

func (c *Client) Config(nodeId NodeId, nodeType NodeType) (config NodeConfig, err error)

Config get node config by nodeId

func (*Client) Debug

func (c *Client) Debug(enable bool)

Debug set the client debug for client

func (*Client) Heartbeat

func (c *Client) Heartbeat(registerId string, nodeType NodeType, nodeIp string) error

func (*Client) RawConfig

func (c *Client) RawConfig(nodeId NodeId, nodeType NodeType) (rawData []byte, err error)

RawConfig get node config by nodeId

func (*Client) RawUsers

func (c *Client) RawUsers(registerId string, nodeType NodeType) (rawData []byte, err error)

func (*Client) Register added in v0.1.0

func (c *Client) Register(nodeId NodeId, nodeType NodeType, hostname string, port int, nodeIp string) (registerId string, err error)

Register register node and return register_id

func (*Client) Submit

func (c *Client) Submit(registerId string, nodeType NodeType, userTraffic []*UserTraffic) error

Submit reports the user traffic

func (*Client) SubmitStatsWithAgent

func (c *Client) SubmitStatsWithAgent(registerId string, nodeType NodeType, stats *TrafficStats) error

func (*Client) SubmitWithAgent

func (c *Client) SubmitWithAgent(registerId string, nodeType NodeType, userTraffic []*UserTraffic) error

func (*Client) Unregister added in v0.1.0

func (c *Client) Unregister(nodeType NodeType, registerId string) error

func (*Client) Users

func (c *Client) Users(registerId string, nodeType NodeType) (UserList *[]User, err error)

Users will pull users form server

func (*Client) Verify added in v0.1.1

func (c *Client) Verify(registerId string, nodeType NodeType) (bool, error)

Verify check if registerId is valid

type Config

type Config struct {
	APIHost string
	Token   string
	Timeout time.Duration
	Debug   bool
}

Config api config

type ErrorType added in v0.1.0

type ErrorType string

ErrorType 定义错误类型

const (
	// HTTP错误
	ErrorTypeServerError ErrorType = "ServerError" // 5xx 服务端错误

	// 特殊错误类型
	ErrorTypeNetworkError ErrorType = "NetworkError" // 网络连接错误
	ErrorTypeParseError   ErrorType = "ParseError"   // 响应解析错误
	ErrorTypeNotModified  ErrorType = "NotModified"  // 304 Not Modified
	ErrorTypeUnknown      ErrorType = "Unknown"      // 未知错误
)

type Hysteria2Config

type Hysteria2Config struct {
	ID                 int    `json:"id"`
	ServerPort         int    `json:"server_port"`
	Obfs               string `json:"obfs"`
	UpMbps             int    `json:"up_mbps"`
	DownMbps           int    `json:"down_mbps"`
	IgnoreCliBandWidth bool   `json:"ignore_cli_band_width"`
	DisableUDP         bool   `json:"disable_udp"`
}

func AsHysteria2Config

func AsHysteria2Config(nc NodeConfig) (*Hysteria2Config, error)

func UnmarshalHysteria2Config

func UnmarshalHysteria2Config(data []byte) (*Hysteria2Config, error)

使用泛型函数重写原有的 Unmarshal 函数

func (*Hysteria2Config) String

func (n *Hysteria2Config) String() string

func (*Hysteria2Config) TypeName

func (n *Hysteria2Config) TypeName() string

type HysteriaConfig

type HysteriaConfig struct {
	ID                  int    `json:"id"`
	ServerPort          int    `json:"server_port"`
	Protocol            string `json:"protocol"`
	Obfs                string `json:"obfs"`
	UpMbps              int    `json:"up_mbps"`
	DownMbps            int    `json:"down_mbps"`
	DisableMTUDiscovery bool   `json:"disable_mtu_discovery"`
	DisableUdp          bool   `json:"disable_udp"`
}

func AsHysteriaConfig

func AsHysteriaConfig(nc NodeConfig) (*HysteriaConfig, error)

func UnmarshalHysteriaConfig

func UnmarshalHysteriaConfig(data []byte) (*HysteriaConfig, error)

func (*HysteriaConfig) String

func (n *HysteriaConfig) String() string

func (*HysteriaConfig) TypeName

func (n *HysteriaConfig) TypeName() string

type NodeConfig

type NodeConfig interface {
	String() string
	TypeName() string
}

type NodeId

type NodeId int

type NodeType

type NodeType string
const (
	Trojan      NodeType = "trojan"
	ShadowSocks NodeType = "shadowsocks"
	Hysteria    NodeType = "hysteria"
	Hysteria2   NodeType = "hysteria2"
	VMess       NodeType = "vmess"
	AnyTLS      NodeType = "anytls"
	Tuic        NodeType = "tuic"
)

func (NodeType) String

func (n NodeType) String() string

type RespConfig

type RespConfig struct {
	Data    NodeConfig `json:"data"`
	Message string     `json:"message"`
}

type RespHeartBeat

type RespHeartBeat RespSubmit

type RespRegister added in v0.1.0

type RespRegister struct {
	Data struct {
		RegisterId string `json:"register_id"`
	} `json:"data"`
	Message string `json:"message"`
}

type RespSubmit

type RespSubmit struct {
	Data    bool   `json:"data"`
	Message string `json:"message"`
}

type RespSubmitStatsWithAgent

type RespSubmitStatsWithAgent RespSubmit

type RespSubmitWithAgent

type RespSubmitWithAgent RespSubmit

type RespUnregister added in v0.1.0

type RespUnregister RespSubmit

type RespUsers

type RespUsers struct {
	Data    *[]User `json:"data"`
	Message string  `json:"message"`
}

type RespVerify added in v0.1.1

type RespVerify RespSubmit

type ShadowsocksConfig

type ShadowsocksConfig struct {
	ID         int    `json:"id"`
	ServerPort int    `json:"server_port"`
	Method     string `json:"method"`
	Network    string `json:"network"`
}

func AsShadowsocksConfig

func AsShadowsocksConfig(nc NodeConfig) (*ShadowsocksConfig, error)

func UnmarshalShadowsocksConfig

func UnmarshalShadowsocksConfig(data []byte) (*ShadowsocksConfig, error)

func (*ShadowsocksConfig) String

func (n *ShadowsocksConfig) String() string

func (*ShadowsocksConfig) TypeName

func (n *ShadowsocksConfig) TypeName() string

type TrafficStats

type TrafficStats struct {
	Count        int         `json:"count"`
	Requests     int         `json:"requests"`
	UserIds      []int       `json:"user_ids"`
	UserRequests map[int]int `json:"user_requests"`
}

type TrojanConfig

type TrojanConfig struct {
	ID              int                   `json:"id"`
	ServerPort      int                   `json:"server_port"`
	AllowInsecure   int                   `json:"allow_insecure"`
	ServerName      string                `json:"server_name"`
	Network         string                `json:"network"`
	WebSocketConfig *xray.WebSocketConfig `json:"ws_settings,omitempty"`
	GrpcConfig      *xray.GRPCConfig      `json:"grpc_settings,omitempty"`
}

func AsTrojanConfig

func AsTrojanConfig(nc NodeConfig) (*TrojanConfig, error)

func UnmarshalTrojanConfig

func UnmarshalTrojanConfig(data []byte) (*TrojanConfig, error)

func (*TrojanConfig) String

func (n *TrojanConfig) String() string

func (*TrojanConfig) TypeName

func (n *TrojanConfig) TypeName() string

type TuicConfig added in v0.1.2

type TuicConfig struct {
	ID               int    `json:"id"`
	ServerPort       int    `json:"server_port"`
	AllowInsecure    int    `json:"allow_insecure"`
	ServerName       string `json:"server_name"`
	ZeroRttHandshake bool   `json:"zero_rtt_handshake"`
}

func AsTuicConfig added in v0.1.2

func AsTuicConfig(nc NodeConfig) (*TuicConfig, error)

func UnmarshalTuicConfig added in v0.1.2

func UnmarshalTuicConfig(data []byte) (*TuicConfig, error)

func (*TuicConfig) String added in v0.1.2

func (n *TuicConfig) String() string

func (*TuicConfig) TypeName added in v0.1.2

func (n *TuicConfig) TypeName() string

type User

type User struct {
	ID   int    `json:"id"`
	UUID string `json:"uuid"`
}

type UserTraffic

type UserTraffic struct {
	UID      int    `json:"user_id"`
	Upload   uint64 `json:"u"`
	Download uint64 `json:"d"`
	Count    uint64 `json:"n"`
}

type VMessConfig

type VMessConfig struct {
	ID              int                   `json:"id"`
	ServerPort      int                   `json:"server_port"`
	TLS             int                   `json:"tls"`
	Network         string                `json:"network"`
	TlsConfig       *xray.TLSConfig       `json:"tls_settings"`
	WebSocketConfig *xray.WebSocketConfig `json:"ws_settings,omitempty"`
	H2Config        *xray.HTTPConfig      `json:"h2_config"`
	TcpConfig       *xray.TCPConfig       `json:"tcp_settings,omitempty"`
	GrpcConfig      *xray.GRPCConfig      `json:"grpc_settings,omitempty"`
	RouterSettings  *xray.RouterConfig    `json:"router_settings,omitempty"`
	DnsSettings     *xray.DNSConfig       `json:"dns_settings,omitempty"`
}

func AsVMessConfig

func AsVMessConfig(nc NodeConfig) (*VMessConfig, error)

func UnmarshalVMessConfig

func UnmarshalVMessConfig(data []byte) (*VMessConfig, error)

func (*VMessConfig) String

func (n *VMessConfig) String() string

func (*VMessConfig) TypeName

func (n *VMessConfig) TypeName() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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