proxy

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: MPL-2.0 Imports: 20 Imported by: 3

Documentation

Index

Constants

View Source
const (
	SSRServer = iota
	SSRPort
	SSRProtocol
	SSRCipher
	SSROBFS
	SSRSuffix
)

Variables

View Source
var (
	ErrorNotVmessLink          = errors.New("not a correct vmess link")
	ErrorVmessPayloadParseFail = errors.New("vmess link payload parse failed")
)
View Source
var (
	// ErrorNotSSLink is an error type
	ErrorNotSSLink = errors.New("not a correct ss link")
)
View Source
var (
	ErrorNotSSRLink = errors.New("not a correct ssr link")
)
View Source
var (
	ErrorNotTrojanink = errors.New("not a correct trojan link")
)

Functions

func ParseProxyToClash

func ParseProxyToClash(content string) (string, error)

Types

type Base

type Base struct {
	Name    string `yaml:"name" json:"name,omitempty"`
	Server  string `yaml:"server" json:"server,omitempty"`
	Path    string `yaml:"path" json:"path,omitempty,omitempty"`
	Type    string `yaml:"type" json:"type,omitempty"`
	Country string `yaml:"country,omitempty" json:"country,omitempty"`
	Emoji   string `yaml:"emoji" json:"emoji,omitempty"`
	Port    string `yaml:"port" json:"port,omitempty" `
	UDP     bool   `yaml:"udp,omitempty" json:"udp,omitempty"`
	Useable bool   `yaml:"useable,omitempty" json:"useable,omitempty"`
}

Base implements interface Proxy. It's the basic proxy struct. Vmess etc extends Base

func (*Base) AddToName

func (b *Base) AddToName(name string)

func (*Base) BaseInfo

func (b *Base) BaseInfo() *Base

func (*Base) Clone

func (b *Base) Clone() Base

func (*Base) GetCountry

func (b *Base) GetCountry() string

func (*Base) GetServer

func (b *Base) GetServer() string

func (*Base) GetUrl

func (b *Base) GetUrl() string

func (*Base) SetCountry

func (b *Base) SetCountry(country string)

func (*Base) SetEmoji

func (b *Base) SetEmoji(emoji string)

func (*Base) SetIP

func (b *Base) SetIP(ip string)

func (*Base) SetName

func (b *Base) SetName(name string)

func (*Base) SetUseable

func (b *Base) SetUseable(useable bool)

func (*Base) TypeName

func (b *Base) TypeName() string

type Clash

type Clash struct {
	Port      int `yaml:"port"`
	SocksPort int `yaml:"socks-port"`
	// RedirPort          int                      `yaml:"redir-port"`
	// Authentication     []string                 `yaml:"authentication"`
	AllowLan           bool   `yaml:"allow-lan"`
	Mode               string `yaml:"mode"`
	LogLevel           string `yaml:"log-level"`
	ExternalController string `yaml:"external-controller"`
	// ExternalUI         string                   `yaml:"external-ui"`
	// Secret             string                   `yaml:"secret"`
	// Experimental       map[string]interface{} 	`yaml:"experimental"`
	Proxy             []map[string]interface{} `yaml:"proxies"`
	ProxyGroup        []map[string]interface{} `yaml:"proxy-groups"`
	Rule              []string                 `yaml:"rules"`
	CFWByPass         []string                 `yaml:"cfw-bypass"`
	CFWLatencyTimeout int                      `yaml:"cfw-latency-timeout"`
}

type ClashRSSR

type ClashRSSR struct {
	Base
	Password      string `json:"password"`
	Cipher        string `json:"cipher"`
	Protocol      string `json:"protocol"`
	ProtocolParam string `json:"protocol-param"`
	OBFS          string `json:"obfs"`
	OBFSParam     string `json:"obfs-param"`
}
func ParseSSRLink(s string) (*ClashRSSR, error)

func (ClashRSSR) Clone

func (ssr ClashRSSR) Clone() Proxy

func (ClashRSSR) String

func (ssr ClashRSSR) String() string

func (ClashRSSR) ToClash

func (ssr ClashRSSR) ToClash() string

func (ClashRSSR) ToSurge

func (ssr ClashRSSR) ToSurge() string

type ClashSS

type ClashSS struct {
	Base
	Password   string     `json:"password"`
	Cipher     string     `json:"cipher"`
	Plugin     string     `json:"plugin"`
	PluginOpts PluginOpts `json:"plugin-opts"`
}
func ParseSSLink(s string) (*ClashSS, error)

ParseSSLink ParseSSLink() parses an ss link to ss proxy

func (ClashSS) Clone

func (ss ClashSS) Clone() Proxy
func (ss ClashSS) Link() (link string)

Link https://shadowsocks.org/en/config/quick-guide.html Link converts a ss proxy to string

func (ClashSS) String

func (ss ClashSS) String() string

func (ClashSS) ToClash

func (ss ClashSS) ToClash() string

ToClash converts proxy to clash proxy string

func (ClashSS) ToSurge

func (ss ClashSS) ToSurge() string

ToSurge converts proxy to surge proxy string

type ClashVmess

type ClashVmess struct {
	Base
	UUID           string            `json:"uuid,omitempty"`
	AlterID        interface{}       `json:"alterId,omitempty"`
	Cipher         string            `json:"cipher,omitempty"`
	TLS            bool              `json:"tls"`
	Network        string            `json:"network,omitempty"`
	WSPATH         string            `json:"ws-path,omitempty"`
	WSHeaders      map[string]string `json:"ws-headers,omitempty"`
	SkipCertVerify bool              `json:"skip-cert-verify,omitempty"`
	HTTPOpts       *HTTPOptions      `yaml:"http-opts,omitempty" json:"http-opts,omitempty"`
	HTTP2Opts      *HTTP2Options     `yaml:"h2-opts,omitempty" json:"h2-opts,omitempty"`
	ServerName     string            `yaml:"servername,omitempty" json:"servername,omitempty"`
}
func ParseVmessLink(s string) (*ClashVmess, error)

func (ClashVmess) Clone

func (v ClashVmess) Clone() Proxy
func (v ClashVmess) Link() (link string)

func (ClashVmess) String

func (v ClashVmess) String() string

func (ClashVmess) ToClash

func (v ClashVmess) ToClash() string

func (ClashVmess) ToSurge

func (v ClashVmess) ToSurge() string

type HTTP2Options

type HTTP2Options struct {
	Host []string `yaml:"host,omitempty" json:"host,omitempty"`
	Path string   `yaml:"path,omitempty" json:"path,omitempty"` // 暂只处理一个Path
}

type HTTPOptions

type HTTPOptions struct {
	Method  string              `yaml:"method,omitempty" json:"method,omitempty"`
	Path    []string            `yaml:"path,omitempty" json:"path,omitempty"`
	Headers map[string][]string `yaml:"headers,omitempty" json:"headers,omitempty"`
}

type Http

type Http struct {
	Base
	Username string `json:"username"`
	Password string `json:"password"`
	Tls      bool   `json:"tls"`
}
func ParseHttpLink(link string) (*Http, error)

func (Http) Clone

func (h Http) Clone() Proxy
func (h Http) Link() string

func (Http) String

func (h Http) String() string

func (Http) ToClash

func (h Http) ToClash() string

func (Http) ToSurge

func (h Http) ToSurge() string

type PluginOpts

type PluginOpts struct {
	Mode string `json:"mode"`
	Host string `json:"host"`
	Tls  bool   `json:"tls"`
}

type Proxy

type Proxy interface {
	String() string
	ToClash() string
	ToSurge() string
	Link() string
	SetName(name string)
	AddToName(name string)
	SetIP(ip string)
	TypeName() string //ss ssr vmess trojan
	BaseInfo() *Base
	Clone() Proxy
	SetUseable(useable bool)
	SetCountry(country string)
	GetCountry() string
	SetEmoji(emoji string)
}

func ParseProxy

func ParseProxy(content string) (p Proxy, err error)

func ParseProxyFromClashProxy

func ParseProxyFromClashProxy(p map[string]interface{}) (proxy Proxy, err error)

type ProxyList

type ProxyList []Proxy

func (ProxyList) All

func (ss ProxyList) All(fn func(value Proxy) bool) bool

All will return true if all callbacks return true. It follows the same logic as the all() function in Python.

If the list is empty then true is always returned.

func (ProxyList) Any

func (ss ProxyList) Any(fn func(value Proxy) bool) bool

Any will return true if any callbacks return true. It follows the same logic as the any() function in Python.

If the list is empty then false is always returned.

func (ProxyList) Append

func (ss ProxyList) Append(elements ...Proxy) ProxyList

Append will return a new slice with the elements appended to the end.

It is acceptable to provide zero arguments.

func (ProxyList) Bottom

func (ss ProxyList) Bottom(n int) (top ProxyList)

Bottom will return n elements from bottom

that means that elements is taken from the end of the slice for this [1,2,3] slice with n == 2 will be returned [3,2] if the slice has less elements then n that'll return all elements if n < 0 it'll return empty slice.

func (ProxyList) Chunk

func (ss ProxyList) Chunk(chunkSize int, callback func(chunk ProxyList) (stopped bool))

Split slice to chunks

func (ProxyList) Contains

func (ss ProxyList) Contains(lookingFor Proxy) bool

Contains returns true if the element exists in the slice.

When using slices of pointers it will only compare by address, not value.

func (ProxyList) Diff

func (ss ProxyList) Diff(against ProxyList) (added, removed ProxyList)

Diff returns the elements that needs to be added or removed from the first slice to have the same elements in the second slice.

The order of elements is not taken into consideration, so the slices are treated sets that allow duplicate items.

The added and removed returned may be blank respectively, or contain upto as many elements that exists in the largest slice.

func (ProxyList) DropTop

func (ss ProxyList) DropTop(n int) (drop ProxyList)

DropTop will return the rest slice after dropping the top n elements if the slice has less elements then n that'll return empty slice if n < 0 it'll return empty slice.

func (ProxyList) Each

func (ss ProxyList) Each(fn func(Proxy)) ProxyList

Each is more condensed version of Transform that allows an action to happen on each elements and pass the original slice on.

cars.Each(func (car *Car) {
    fmt.Printf("Car color is: %s\n", car.Color)
})

Pie will not ensure immutability on items passed in so they can be manipulated, if you choose to do it this way, for example:

// Set all car colors to Red.
cars.Each(func (car *Car) {
    car.Color = "Red"
})

func (ProxyList) Equals

func (ss ProxyList) Equals(rhs ProxyList) bool

Equals compare elements from the start to the end,

if they are the same is considered the slices are equal if all elements are the same is considered the slices are equal if each slice == nil is considered that they're equal

if element realizes Equals interface it uses that method, in other way uses default compare

func (ProxyList) Extend

func (ss ProxyList) Extend(slices ...ProxyList) (ss2 ProxyList)

Extend will return a new slice with the slices of elements appended to the end.

It is acceptable to provide zero arguments.

func (ProxyList) Filter

func (ss ProxyList) Filter(condition func(Proxy) bool) (ss2 ProxyList)

Filter will return a new slice containing only the elements that return true from the condition. The returned slice may contain zero elements (nil).

FilterNot works in the opposite way of Filter.

func (ProxyList) FilterNot

func (ss ProxyList) FilterNot(condition func(Proxy) bool) (ss2 ProxyList)

FilterNot works the same as Filter, with a negated condition. That is, it will return a new slice only containing the elements that returned false from the condition. The returned slice may contain zero elements (nil).

func (ProxyList) FindFirstUsing

func (ss ProxyList) FindFirstUsing(fn func(value Proxy) bool) int

FindFirstUsing will return the index of the first element when the callback returns true or -1 if no element is found. It follows the same logic as the findIndex() function in Javascript.

If the list is empty then -1 is always returned.

func (ProxyList) First

func (ss ProxyList) First() Proxy

First returns the first element, or zero. Also see FirstOr().

func (ProxyList) FirstOr

func (ss ProxyList) FirstOr(defaultValue Proxy) Proxy

FirstOr returns the first element or a default value if there are no elements.

func (ProxyList) Float64s

func (ss ProxyList) Float64s() pie.Float64s

Float64s transforms each element to a float64.

func (ProxyList) Insert

func (ss ProxyList) Insert(index int, values ...Proxy) ProxyList

Insert a value at an index

func (ProxyList) Ints

func (ss ProxyList) Ints() pie.Ints

Ints transforms each element to an integer.

func (ProxyList) JSONBytes

func (ss ProxyList) JSONBytes() []byte

JSONBytes returns the JSON encoded array as bytes.

One important thing to note is that it will treat a nil slice as an empty slice to ensure that the JSON value return is always an array.

func (ProxyList) JSONBytesIndent

func (ss ProxyList) JSONBytesIndent(prefix, indent string) []byte

JSONBytesIndent returns the JSON encoded array as bytes with indent applied.

One important thing to note is that it will treat a nil slice as an empty slice to ensure that the JSON value return is always an array. See json.MarshalIndent for details.

func (ProxyList) JSONString

func (ss ProxyList) JSONString() string

JSONString returns the JSON encoded array as a string.

One important thing to note is that it will treat a nil slice as an empty slice to ensure that the JSON value return is always an array.

func (ProxyList) JSONStringIndent

func (ss ProxyList) JSONStringIndent(prefix, indent string) string

JSONStringIndent returns the JSON encoded array as a string with indent applied.

One important thing to note is that it will treat a nil slice as an empty slice to ensure that the JSON value return is always an array. See json.MarshalIndent for details.

func (ProxyList) Join

func (ss ProxyList) Join(glue string) (s string)

Join returns a string from joining each of the elements.

func (ProxyList) Last

func (ss ProxyList) Last() Proxy

Last returns the last element, or zero. Also see LastOr().

func (ProxyList) LastOr

func (ss ProxyList) LastOr(defaultValue Proxy) Proxy

LastOr returns the last element or a default value if there are no elements.

func (ProxyList) Len

func (ss ProxyList) Len() int

Len returns the number of elements.

func (ProxyList) Map

func (ss ProxyList) Map(fn func(Proxy) Proxy) (ss2 ProxyList)

Map will return a new slice where each element has been mapped (transformed). The number of elements returned will always be the same as the input.

Be careful when using this with slices of pointers. If you modify the input value it will affect the original slice. Be sure to return a new allocated object or deep copy the existing one.

func (ProxyList) Mode

func (ss ProxyList) Mode() ProxyList

Mode returns a new slice containing the most frequently occuring values.

The number of items returned may be the same as the input or less. It will never return zero items unless the input slice has zero items.

func (*ProxyList) Pop

func (ss *ProxyList) Pop() (popped *Proxy)

Pop the first element of the slice

Usage Example:

type knownGreetings []string
greetings := knownGreetings{"ciao", "hello", "hola"}
for greeting := greetings.Pop(); greeting != nil; greeting = greetings.Pop() {
    fmt.Println(*greeting)
}

func (ProxyList) Random

func (ss ProxyList) Random(source rand.Source) Proxy

Random returns a random element by your rand.Source, or zero

func (ProxyList) Reverse

func (ss ProxyList) Reverse() ProxyList

Reverse returns a new copy of the slice with the elements ordered in reverse. This is useful when combined with Sort to get a descending sort order:

ss.Sort().Reverse()

func (ProxyList) Send

func (ss ProxyList) Send(ctx context.Context, ch chan<- Proxy) ProxyList

Send sends elements to channel in normal act it sends all elements but if func canceled it can be less

it locks execution of gorutine it doesn't close channel after work returns sended elements if len(this) != len(old) considered func was canceled

func (ProxyList) SequenceUsing

func (ss ProxyList) SequenceUsing(creator func(int) Proxy, params ...int) ProxyList

SequenceUsing generates slice in range using creator function

There are 3 variations to generate:

  1. [0, n).
  2. [min, max).
  3. [min, max) with step.

if len(params) == 1 considered that will be returned slice between 0 and n, where n is the first param, [0, n). if len(params) == 2 considered that will be returned slice between min and max, where min is the first param, max is the second, [min, max). if len(params) > 2 considered that will be returned slice between min and max with step, where min is the first param, max is the second, step is the third one, [min, max) with step, others params will be ignored

func (ProxyList) Shift

func (ss ProxyList) Shift() (Proxy, ProxyList)

Shift will return two values: the shifted value and the rest slice.

func (ProxyList) Shuffle

func (ss ProxyList) Shuffle(source rand.Source) ProxyList

Shuffle returns shuffled slice by your rand.Source

func (ProxyList) SortStableUsing

func (ss ProxyList) SortStableUsing(less func(a, b Proxy) bool) ProxyList

SortStableUsing works similar to sort.SliceStable. However, unlike sort.SliceStable the slice returned will be reallocated as to not modify the input slice.

func (ProxyList) SortUsing

func (ss ProxyList) SortUsing(less func(a, b Proxy) bool) ProxyList

SortUsing works similar to sort.Slice. However, unlike sort.Slice the slice returned will be reallocated as to not modify the input slice.

func (ProxyList) Strings

func (ss ProxyList) Strings() pie.Strings

Strings transforms each element to a string.

If the element type implements fmt.Stringer it will be used. Otherwise it will fallback to the result of:

fmt.Sprintf("%v")

func (ProxyList) StringsUsing

func (ss ProxyList) StringsUsing(transform func(Proxy) string) pie.Strings

StringsUsing transforms each element to a string.

func (ProxyList) SubSlice

func (ss ProxyList) SubSlice(start int, end int) (subSlice ProxyList)

SubSlice will return the subSlice from start to end(excluded)

Condition 1: If start < 0 or end < 0, nil is returned. Condition 2: If start >= end, nil is returned. Condition 3: Return all elements that exist in the range provided, if start or end is out of bounds, zero items will be placed.

func (ProxyList) Top

func (ss ProxyList) Top(n int) (top ProxyList)

Top will return n elements from head of the slice if the slice has less elements then n that'll return all elements if n < 0 it'll return empty slice.

func (ProxyList) Unshift

func (ss ProxyList) Unshift(elements ...Proxy) (unshift ProxyList)

Unshift adds one or more elements to the beginning of the slice and returns the new slice.

type SSD

type SSD struct {
	Airport      string  `json:"airport"`
	Port         int     `json:"port"`
	Encryption   string  `json:"encryption"`
	Password     string  `json:"password"`
	TrafficUsed  float64 `json:"traffic_used"`
	TrafficTotal float64 `json:"traffic_total"`
	Expiry       string  `json:"expiry"`
	URL          string  `json:"url"`
	Servers      []struct {
		ID            int     `json:"id"`
		Server        string  `json:"server"`
		Ratio         float64 `json:"ratio"`
		Remarks       string  `json:"remarks"`
		Port          string  `json:"port"`
		Encryption    string  `json:"encryption"`
		Password      string  `json:"password"`
		Plugin        string  `json:"plugin"`
		PluginOptions string  `json:"plugin_options"`
	} `json:"servers"`
}

type Socket

type Socket struct {
	Base
	Username string `json:"username"`
	Password string `json:"password"`
}
func ParseSocketLink(link string) (*Socket, error)

func (Socket) Clone

func (s Socket) Clone() Proxy
func (s Socket) Link() string

func (Socket) String

func (s Socket) String() string

func (Socket) ToClash

func (s Socket) ToClash() string

func (Socket) ToSurge

func (s Socket) ToSurge() string

type Trojan

type Trojan struct {
	Base
	Password       string   `json:"password"`
	Sni            string   `json:"sni,omitempty"`
	ALPN           []string `yaml:"alpn,omitempty" json:"alpn,omitempty"`
	SkipCertVerify bool     `yaml:"skip-cert-verify,omitempty" json:"skip-cert-verify,omitempty"`
	Network        string   `yaml:"network,omitempty" json:"network,omitempty"`
	WsOpts         struct {
		Path    string                 `yaml:"path,omitempty" json:"path,omitempty"`
		Headers map[string]interface{} `yaml:"header,omitempty" json:"headers,omitempty"`
	} `yaml:"ws-opts,omitempty" json:"ws-opts,omitempty"`
	GrpcOpts struct {
		GrpcServiceName string `yaml:"grpc-service-name,omitempty" json:"grpc-service-name,omitempty"`
	} `yaml:"grpc-opts,omitempty" json:"grpc-opts,omitempty"`
}
func ParseTrojanLink(s string) (*Trojan, error)

func (Trojan) Clone

func (t Trojan) Clone() Proxy

func (Trojan) String

func (t Trojan) String() string

func (Trojan) ToClash

func (t Trojan) ToClash() string

func (Trojan) ToSurge

func (t Trojan) ToSurge() string

type Vless

type Vless struct {
	Base
	UUID           string            `json:"uuid,omitempty"`
	AlterId        int               `json:"alterId"`
	Cipher         string            `json:"cipher,omitempty"`
	Network        string            `json:"network,omitempty"`
	Tls            bool              `json:"tls"`
	Flow           string            `json:"flow,omitempty"`
	SkipCertVerify bool              `json:"skip-cert-verify"`
	Sni            string            `json:"sni,omitempty"`
	WSPath         string            `proxy:"ws-path,omitempty" json:"ws_path,omitempty" yaml:"ws_path,omitempty"`
	WSHeaders      map[string]string `proxy:"ws-headers,omitempty" json:"ws_headers,omitempty" yaml:"ws_headers,omitempty"`
}
func ParseVlessLink(link string) (*Vless, error)

func (Vless) Clone

func (s Vless) Clone() Proxy
func (s Vless) Link() string

func (Vless) String

func (s Vless) String() string

func (Vless) ToClash

func (s Vless) ToClash() string

func (Vless) ToSurge

func (s Vless) ToSurge() string

type Vmess

type Vmess struct {
	Add  string      `json:"add"`
	Aid  interface{} `json:"aid"`
	Host string      `json:"host"`
	ID   string      `json:"id"`
	Net  string      `json:"net"`
	Path string      `json:"path"`
	Port interface{} `json:"port"`
	Scy  string      `json:"scy"`
	Sni  string      `json:"sni"`
	PS   string      `json:"ps"`
	TLS  string      `json:"tls"`
	Type string      `json:"type"`
	V    interface{} `json:"v"`
}

Jump to

Keyboard shortcuts

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