helper

package
v0.0.0-...-61ba746 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SSParser = JSONParser{
	Filed: map[string]FieldParser{
		"protocol": JSONPath("protocol"),
		"port":     JSONPath("port"),
		"method":   JSONPath("settings.method"),
		"password": JSONPath("settings.password"),
	},
	DefaultField: map[string]string{
		"host": "",
	},
	PostHandler: func(m map[string]string, tag string) (Endpoint, error) {
		su := ShadowsocksURL{
			Host:     m["host"],
			Port:     m["port"],
			Method:   m["method"],
			Password: m["password"],
			Tag:      tag,
		}

		return &su, nil
	},
}

SSParser parse shadowsocks node in v2ray config

View Source
var VmessParser = JSONParser{
	Filed: map[string]FieldParser{
		"protocol":      JSONPath("protocol"),
		"port":          JSONPath("port"),
		"id":            JSONPath("settings.clients.0.id"),
		"alterId":       JSONPath("settings.clients.0.alterId"),
		"network":       JSONPathWithValue("streamSettings.network", "tcp"),
		"security":      JSONPath("streamSettings.security"),
		"http.host":     JSONPath("streamSettings.httpSettings.host.0"),
		"http.path":     JSONPath("streamSettings.httpSettings.path"),
		"ws.host":       JSONPath("streamSettings.wsSettings.headers.Host"),
		"ws.path":       JSONPath("streamSettings.wsSettings.path"),
		"kcp.type":      JSONPath("streamSettings.kcpSettings.header.type"),
		"quic.type":     JSONPath("streamSettings.quicSettings.header.type"),
		"quic.security": JSONPath("streamSettings.quicSettings.security"),
		"quic.key":      JSONPath("streamSettings.quicSettings.key"),
		"servername":    JSONPath("tlsSettings.serverName"),
	},
	DefaultField: map[string]string{
		"add": "",
	},
	PostHandler: func(m map[string]string, tag string) (Endpoint, error) {
		alterID, err := strconv.Atoi(m["alterId"])
		if err != nil {
			return nil, errors.Wrap(err, "VmessParser")
		}

		vu := VmessURL{
			Ps:       tag,
			Port:     m["port"],
			ID:       m["id"],
			AlterID:  Number(alterID),
			Network:  m["network"],
			Security: m["security"],
			Add:      m["add"],
			Version:  2,
		}

		if m["network"] == "http" {
			vu.FakeHost = m["http.host"]
			vu.FakePath = m["http.path"]
			vu.Network = "h2"
		} else if m["network"] == "ws" {
			vu.FakeHost = m["ws.host"]
			vu.FakePath = m["ws.path"]
		} else if m["network"] == "kcp" {
			if m["kcp.type"] == "" {
				m["kcp.type"] = "none"
			}
			vu.FakeType = m["kcp.type"]
		} else if m["network"] == "quic" {
			if m["quic.type"] == "" {
				m["quic.type"] = "none"
			}
			vu.FakeType = m["quic.type"]
			vu.FakeHost = m["quic.security"]
			vu.FakePath = m["quic.key"]
		}

		if vu.Port == "443" {
			vu.Security = "tls"
		}

		return &vu, nil
	},
}

VmessParser parse vmess node in v2ray config

Functions

func Base64Decode

func Base64Decode(data string) (string, error)

Base64Decode try base64 decode

func FmtStringReplace

func FmtStringReplace(format string, m map[string]string) string

FmtStringReplace replace {key} ,key in map

func JSONPath

func JSONPath(p string) func(result gjson.Result) string

JSONPath -

func JSONPathWithValue

func JSONPathWithValue(p, value string) func(result gjson.Result) string

JSONPathWithValue json path with default value

func ReadLines

func ReadLines(path string) ([]string, error)

ReadLines reads a whole file into memory and returns a slice of its lines.

Types

type Endpoint

type Endpoint interface {
	String() string
	Addr() string
	Type() string
}

Endpoint endpoint

func ParseEndpoint

func ParseEndpoint(u string) (Endpoint, error)

ParseEndpoint parse endpoint by uri proto

type FieldParser

type FieldParser func(result gjson.Result) string

FieldParser -

type JSONParser

type JSONParser struct {
	TagFmt       string
	Filed        map[string]FieldParser
	DefaultField map[string]string
	PostHandler  func(m map[string]string, tag string) (Endpoint, error)
}

JSONParser -

func (*JSONParser) Parse

func (p *JSONParser) Parse(result gjson.Result) (Endpoint, error)

Parse -

type Number

type Number int

Number support number 1 and "1"

func (Number) MarshalJSON

func (n Number) MarshalJSON() ([]byte, error)

MarshalJSON -

func (*Number) UnmarshalJSON

func (n *Number) UnmarshalJSON(b []byte) error

UnmarshalJSON -

type Proxy

type Proxy struct {
	Url string
}

func ParseProxy

func ParseProxy(url string) (*Proxy, error)

func (*Proxy) Addr

func (p *Proxy) Addr() string

Addr -

func (*Proxy) String

func (p *Proxy) String() string

String -

func (*Proxy) Type

func (p *Proxy) Type() string

Type -

type ShadowsocksURL

type ShadowsocksURL struct {
	Host     string `json:"host"`
	Port     string `json:"port"`
	Method   string `json:"method"`
	Password string `json:"password"`
	Protocol string `json:"protocol"`
	Tag      string `json:"tag"`
}

ShadowsocksURL implement interface Endpoint

func NewShadowsocksURL

func NewShadowsocksURL(u string) (*ShadowsocksURL, error)

NewShadowsocksURL -

func (*ShadowsocksURL) Addr

func (s *ShadowsocksURL) Addr() string

Addr -

func (*ShadowsocksURL) String

func (s *ShadowsocksURL) String() string

String -

func (*ShadowsocksURL) Type

func (s *ShadowsocksURL) Type() string

Type -

type VmessURL

type VmessURL struct {
	Version  Number `json:"v"`
	AlterID  Number `json:"aid"`
	Ps       string `json:"ps"`
	Port     string `json:"port"`
	ID       string `json:"id"`
	Network  string `json:"net"`
	Security string `json:"tls"`
	Add      string `json:"add"`
	FakePath string `json:"path"`
	FakeType string `json:"type"`
	FakeHost string `json:"host"`
}

VmessURL implement interface Endpoint from https://github.com/2dust/v2rayN/wiki/分享链接格式说明(ver-2)

func NewVmessURL

func NewVmessURL(u string) (*VmessURL, error)

NewVmessURL -

func (*VmessURL) Addr

func (v *VmessURL) Addr() string

Addr -

func (*VmessURL) String

func (v *VmessURL) String() string

String -

func (*VmessURL) Type

func (v *VmessURL) Type() string

Type -

Jump to

Keyboard shortcuts

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