config

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRegistry = NewGeneratorRegistry()

DefaultRegistry 默认注册表

View Source
var DefaultTestScenarios = []TestScenario{
	{
		Name:        "vmess-tcp",
		Description: "VMess over TCP",
		Protocol:    ProtocolVMess,
		Transport:   TransportTCP,
		TLS:         TLSNone,
		TestURLs:    []string{"http://www.gstatic.com/generate_204", "https://www.google.com/generate_204"},
	},
	{
		Name:        "vmess-ws-tls",
		Description: "VMess over WebSocket with TLS",
		Protocol:    ProtocolVMess,
		Transport:   TransportWS,
		TLS:         TLS,
		TestURLs:    []string{"http://www.gstatic.com/generate_204", "https://www.google.com/generate_204"},
	},
	{
		Name:        "vless-reality",
		Description: "VLESS with Reality",
		Protocol:    ProtocolVLESS,
		Transport:   TransportTCP,
		TLS:         TLSReality,
		TestURLs:    []string{"http://www.gstatic.com/generate_204", "https://www.google.com/generate_204"},
	},
	{
		Name:        "trojan-tls",
		Description: "Trojan with TLS",
		Protocol:    ProtocolTrojan,
		Transport:   TransportTCP,
		TLS:         TLS,
		TestURLs:    []string{"http://www.gstatic.com/generate_204", "https://www.google.com/generate_204"},
	},
	{
		Name:        "ss-tcp",
		Description: "Shadowsocks over TCP",
		Protocol:    ProtocolShadowsocks,
		Transport:   TransportTCP,
		TLS:         TLSNone,
		TestURLs:    []string{"http://www.gstatic.com/generate_204"},
	},
	{
		Name:        "hysteria2",
		Description: "Hysteria2 over QUIC",
		Protocol:    ProtocolHysteria2,
		Transport:   TransportQUIC,
		TLS:         TLS,
		TestURLs:    []string{"http://www.gstatic.com/generate_204", "https://www.google.com/generate_204"},
	},
}

DefaultTestScenarios 默认测试场景

Functions

func GenerateConfig

func GenerateConfig(generatorName string, cfg *ClientConfig) ([]byte, error)

GenerateConfig 生成配置(便捷方法)

func ToJSON

func ToJSON(v any) ([]byte, error)

ToJSON 辅助函数:转换为格式化的 JSON

func ToJSONCompact

func ToJSONCompact(v any) ([]byte, error)

ToJSONCompact 辅助函数:转换为紧凑的 JSON

Types

type ClientConfig

type ClientConfig struct {
	Name   string
	Server ServerConfig
	User   UserConfig

	// 测试相关
	TestURLs []string // 测试用的 URL 列表
	Timeout  int      // 超时时间(秒)
}

ClientConfig 客户端配置(用于测试)

type Generator

type Generator interface {
	// Name 返回生成器名称
	Name() string

	// Generate 生成客户端配置
	Generate(cfg *ClientConfig) ([]byte, error)

	// GenerateFromScenario 从测试场景生成配置
	GenerateFromScenario(scenario TestScenario, server ServerConfig, user UserConfig) ([]byte, error)

	// SupportedProtocols 返回支持的协议列表
	SupportedProtocols() []Protocol

	// IsProtocolSupported 检查协议是否支持
	IsProtocolSupported(p Protocol) bool
}

Generator 配置生成器接口

type GeneratorRegistry

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

GeneratorRegistry 配置生成器注册表

func NewGeneratorRegistry

func NewGeneratorRegistry() *GeneratorRegistry

NewGeneratorRegistry 创建新的生成器注册表

func (*GeneratorRegistry) Get

func (r *GeneratorRegistry) Get(name string) (Generator, error)

Get 获取生成器

func (*GeneratorRegistry) List

func (r *GeneratorRegistry) List() []string

List 列出所有生成器

func (*GeneratorRegistry) Register

func (r *GeneratorRegistry) Register(g Generator)

Register 注册生成器

type MihomoConfig

type MihomoConfig struct {
	Port               int              `yaml:"port"`
	SocksPort          int              `yaml:"socks-port"`
	MixedPort          int              `yaml:"mixed-port"`
	AllowLan           bool             `yaml:"allow-lan"`
	BindAddress        string           `yaml:"bind-address"`
	Mode               string           `yaml:"mode"`
	LogLevel           string           `yaml:"log-level"`
	IPv6               bool             `yaml:"ipv6"`
	ExternalController string           `yaml:"external-controller"`
	Proxies            []map[string]any `yaml:"proxies"`
	ProxyGroups        []map[string]any `yaml:"proxy-groups"`
	Rules              []string         `yaml:"rules"`
	DNS                map[string]any   `yaml:"dns"`
}

type MihomoGenerator

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

MihomoGenerator Mihomo (Clash.Meta) 配置生成器

func NewMihomoGenerator

func NewMihomoGenerator() *MihomoGenerator

NewMihomoGenerator 创建 Mihomo 配置生成器

func (*MihomoGenerator) Generate

func (g *MihomoGenerator) Generate(cfg *ClientConfig) ([]byte, error)

Generate 生成 Mihomo 客户端配置

func (*MihomoGenerator) GenerateClashProxies

func (g *MihomoGenerator) GenerateClashProxies(configs []*ClientConfig) ([]map[string]any, error)

GenerateClashProxies 生成 Clash 代理配置片段

func (*MihomoGenerator) GenerateClashSubscription

func (g *MihomoGenerator) GenerateClashSubscription(configs []*ClientConfig) ([]byte, error)

GenerateClashSubscription 生成 Clash 订阅格式

func (*MihomoGenerator) GenerateFromScenario

func (g *MihomoGenerator) GenerateFromScenario(scenario TestScenario, server ServerConfig, user UserConfig) ([]byte, error)

GenerateFromScenario 从测试场景生成配置

func (*MihomoGenerator) IsProtocolSupported

func (g *MihomoGenerator) IsProtocolSupported(p Protocol) bool

IsProtocolSupported 检查协议是否支持

func (*MihomoGenerator) Name

func (g *MihomoGenerator) Name() string

Name 返回生成器名称

func (*MihomoGenerator) SupportedProtocols

func (g *MihomoGenerator) SupportedProtocols() []Protocol

SupportedProtocols 返回支持的协议列表

type Protocol

type Protocol string

Protocol 协议类型

const (
	ProtocolVMess       Protocol = "vmess"
	ProtocolVLESS       Protocol = "vless"
	ProtocolTrojan      Protocol = "trojan"
	ProtocolShadowsocks Protocol = "shadowsocks"
	ProtocolHysteria2   Protocol = "hysteria2"
	ProtocolTUIC        Protocol = "tuic"
)

type ServerConfig

type ServerConfig struct {
	Host     string // 服务器地址
	Port     int    // 服务器端口
	Protocol Protocol

	// TLS 配置
	TLSType  TLSType
	SNI      string // Server Name Indication
	Insecure bool   // 跳过证书验证

	// Reality 配置
	PublicKey string
	ShortID   string
	SpiderX   string

	// 传输层配置
	Transport     TransportType
	TransportWS   *TransportWSConfig
	TransportGRPC *TransportGRPCConfig

	// 协议特定配置
	UUID     string // VMess/VLESS UUID
	Password string // Trojan/SS 密码
	Method   string // SS 加密方法
	Flow     string // VLESS flow (xtls-rprx-vision)
}

ServerConfig 服务端配置

type TLSType

type TLSType string

TLSType TLS 类型

const (
	TLSNone    TLSType = "none"
	TLS        TLSType = "tls"
	TLSReality TLSType = "reality"
)

type TestScenario

type TestScenario struct {
	Name        string
	Description string
	Protocol    Protocol
	Transport   TransportType
	TLS         TLSType
	TestURLs    []string
}

TestScenario 测试场景

type TransportGRPCConfig

type TransportGRPCConfig struct {
	ServiceName string
}

TransportGRPCConfig gRPC 传输配置

type TransportType

type TransportType string

TransportType 传输层类型

const (
	TransportTCP   TransportType = "tcp"
	TransportWS    TransportType = "ws"
	TransportGRPC  TransportType = "grpc"
	TransportHTTP2 TransportType = "h2"
	TransportQUIC  TransportType = "quic"
)

type TransportWSConfig

type TransportWSConfig struct {
	Path    string
	Headers map[string]string
}

TransportWSConfig WebSocket 传输配置

type UserConfig

type UserConfig struct {
	UUID    string
	Email   string
	AlterID int    // VMess only
	Flow    string // VLESS only
}

UserConfig 用户配置

type XrayConfig

type XrayConfig struct {
	Log       *XrayLog       `json:"log"`
	Inbounds  []XrayInbound  `json:"inbounds"`
	Outbounds []XrayOutbound `json:"outbounds"`
	Routing   *XrayRouting   `json:"routing"`
}

type XrayGRPCSettings

type XrayGRPCSettings struct {
	ServiceName string `json:"serviceName,omitempty"`
}

type XrayGenerator

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

XrayGenerator Xray 配置生成器

func NewXrayGenerator

func NewXrayGenerator() *XrayGenerator

NewXrayGenerator 创建 Xray 配置生成器

func (*XrayGenerator) Generate

func (g *XrayGenerator) Generate(cfg *ClientConfig) ([]byte, error)

Generate 生成 Xray 客户端配置

func (*XrayGenerator) GenerateFromScenario

func (g *XrayGenerator) GenerateFromScenario(scenario TestScenario, server ServerConfig, user UserConfig) ([]byte, error)

GenerateFromScenario 从测试场景生成配置

func (g *XrayGenerator) GenerateV2RayLink(cfg *ClientConfig) (string, error)

GenerateV2RayLink 生成 V2Ray 订阅链接

func (*XrayGenerator) IsProtocolSupported

func (g *XrayGenerator) IsProtocolSupported(p Protocol) bool

IsProtocolSupported 检查协议是否支持

func (*XrayGenerator) Name

func (g *XrayGenerator) Name() string

Name 返回生成器名称

func (*XrayGenerator) SupportedProtocols

func (g *XrayGenerator) SupportedProtocols() []Protocol

SupportedProtocols 返回支持的协议列表

type XrayInbound

type XrayInbound struct {
	Port     int            `json:"port"`
	Listen   string         `json:"listen"`
	Tag      string         `json:"tag"`
	Protocol string         `json:"protocol"`
	Settings map[string]any `json:"settings,omitempty"`
}

type XrayLog

type XrayLog struct {
	LogLevel string `json:"logLevel"`
}

type XrayOutbound

type XrayOutbound struct {
	Tag            string              `json:"tag"`
	Protocol       string              `json:"protocol"`
	Settings       map[string]any      `json:"settings,omitempty"`
	StreamSettings *XrayStreamSettings `json:"streamSettings,omitempty"`
}

type XrayRealitySettings

type XrayRealitySettings struct {
	ServerName  string `json:"serverName,omitempty"`
	PublicKey   string `json:"publicKey,omitempty"`
	ShortId     string `json:"shortId,omitempty"`
	SpiderX     string `json:"spiderX,omitempty"`
	Fingerprint string `json:"fingerprint,omitempty"`
}

type XrayRouting

type XrayRouting struct {
	Rules []XrayRoutingRule `json:"rules"`
}

type XrayRoutingRule

type XrayRoutingRule struct {
	Type        string   `json:"type"`
	IP          []string `json:"ip,omitempty"`
	Domain      []string `json:"domain,omitempty"`
	OutboundTag string   `json:"outboundTag"`
}

type XrayStreamSettings

type XrayStreamSettings struct {
	Network         string               `json:"network"`
	Security        string               `json:"security,omitempty"`
	TLSSettings     *XrayTLSSettings     `json:"tlsSettings,omitempty"`
	RealitySettings *XrayRealitySettings `json:"realitySettings,omitempty"`
	WSSettings      *XrayWSSettings      `json:"wsSettings,omitempty"`
	GRPCSettings    *XrayGRPCSettings    `json:"grpcSettings,omitempty"`
}

type XrayTLSSettings

type XrayTLSSettings struct {
	ServerName    string `json:"serverName,omitempty"`
	AllowInsecure bool   `json:"allowInsecure,omitempty"`
}

type XrayWSSettings

type XrayWSSettings struct {
	Path    string            `json:"path,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
}

Jump to

Keyboard shortcuts

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