pkg

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

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

Security type

Variables

This section is empty.

Functions

func IntervalToTime

func IntervalToTime(i interface{}) time.Duration

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

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) 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 AliveMap

type AliveMap struct {
	Alive map[int]int `json:"alive"`
}

type AnyTlsNode

type AnyTlsNode struct {
	CommonNode
	PaddingScheme []string `json:"padding_scheme,omitempty"`
}

type BaseConfig

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

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 New

func New(c *Config) *Client

New creat a api instance

func (*Client) Debug

func (c *Client) Debug(enable bool)

Debug set the client debug for client

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 GetUserList will pull user from v2board

func (*Client) ReportNodeOnlineUsers

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

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

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

type HysteriaNode

type HysteriaNode struct {
	CommonNode
	UpMbps   int    `json:"up_mbps"`
	DownMbps int    `json:"down_mbps"`
	Obfs     string `json:"obfs"`
}

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
}

type OnlineUser

type OnlineUser struct {
	UID int
	IP  string
}

User structures

type RawDNS

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

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

type Rules

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

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

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

type TrojanNode

type TrojanNode struct {
	CommonNode
	Network         string          `json:"network"`
	NetworkSettings json.RawMessage `json:"networkSettings"`
}

type TuicNode

type TuicNode struct {
	CommonNode
	CongestionControl string `json:"congestion_control"`
	ZeroRTTHandshake  bool   `json:"zero_rtt_handshake"`
}

type UserInfo

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

type UserListBody

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

type UserTraffic

type UserTraffic struct {
	UID      int
	Upload   int64
	Download int64
}

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

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

Jump to

Keyboard shortcuts

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