proxy

package
v0.0.0-...-cf12e39 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProxyDirect = "DIRECT"
	ProxyReject = "REJECT"
	ProxyGlobal = "GLOBAL"
)

Variables

View Source
var (
	ErrorReject         = errors.New("connection reject")
	ErrorServerNotFound = errors.New("server or server group not found")

	MockServer   = &Server{Name: "MOCK"}
	FailedServer = &Server{Name: "FAILED"}
	RejectServer = &Server{Name: "REJECT"}
)
View Source
var ErrorUnknowType = errors.New("unknow select type")

Functions

func AddGroup

func AddGroup(name string, vs []string) (err error)

func AddProxy

func AddProxy(name string, vs []string) error

func ApplyConfig

func ApplyConfig(config IProxyConfig) (err error)

func CheckSelector

func CheckSelector(method string) bool

func DestroyServers

func DestroyServers()

func Duration2Str

func Duration2Str(d time.Duration) string

func EditGroup

func EditGroup(name string, vs []string) (err error)

func EditProxy

func EditProxy(name string, vs []string) error

func InitServers

func InitServers(gs []*ServerGroup, ss []*Server) error

func ParseServer

func ParseServer(v interface{}) (*ServerGroup, *Server, error)

func RegisterProxyProtocolCreator

func RegisterProxyProtocolCreator(name string, p NewProtocol)

func RegisterSelector

func RegisterSelector(method string, newSelector NewSelector)

func RemoveGroup

func RemoveGroup(name string) (effects, deletes []string, err error)

func RemoveProxy

func RemoveProxy(name string) (effects, deletes []string, err error)

func SelectRefresh

func SelectRefresh(groupName string) error

func SelectServer

func SelectServer(groupName, serverName string) error

func TestRTT

func TestRTT(s IServer, testURL string) (rtt time.Duration, err error)

Types

type GroupExternal

type GroupExternal struct {
	Name       string            `json:"name"`
	SelectType string            `json:"select_type"`
	Servers    []*ProxyExternal2 `json:"servers"`
	Selected   *ProxyExternal2   `json:"selected"`
	RttUrl     string            `json:"rtt_url"`
}

func GetGroupExternals

func GetGroupExternals(names ...string) []*GroupExternal

type IProtocol

type IProtocol interface {
	//获取服务器连接
	Conn(request IRequest) (conn.IConn, error)
}

type IProxyConfig

type IProxyConfig interface {
	GetProxy() map[string][]string
	SetProxy(map[string][]string)
	GetProxyGroup() map[string][]string
	SetProxyGroup(map[string][]string)
	GetRttUrl() string
	SetRttUrl(string)
}

type IRequest

type IRequest interface {
	Network() string
	Domain() string
	IP() string
	Port() string
	Host() string
}

type ISelector

type ISelector interface {
	Get() (*Server, error)
	Select(string) error
	Refresh() error
	Reset(group *ServerGroup) error
	Destroy()
	Current() IServer
}

func GetSelector

func GetSelector(method string, group *ServerGroup) (ISelector, error)

type IServer

type IServer interface {
	GetName() string
	GetServer() (*Server, error)
	GetRttRrl() string
}

type NewProtocol

type NewProtocol func([]string) (IProtocol, error)

type NewSelector

type NewSelector func(group *ServerGroup) (ISelector, error)

type ProxyExternal

type ProxyExternal struct {
	Name     string        `json:"name"`
	Rtt      time.Duration `json:"rtt"`
	RttText  string        `json:"rtt_text"`
	Protocol string        `json:"protocol"`
}

func GetServerExternals

func GetServerExternals() []*ProxyExternal

type ProxyExternal2

type ProxyExternal2 struct {
	ProxyExternal
	SubName    string `json:"sub_name"`
	IsSelected bool   `json:"is_selected"`
}

type Server

type Server struct {
	Name          string
	Rtt           time.Duration
	ProxyProtocol string
	RttUrl        string
	IProtocol     `json:"-"`
}

func GetServer

func GetServer(name string) (*Server, error)

func NewServer

func NewServer(name string, params []string) (*Server, error)

创建Server

func ProxyExist

func ProxyExist(name string) (*Server, bool)

func (*Server) Conn

func (s *Server) Conn(req IRequest) (conn.IConn, error)

func (*Server) GetName

func (s *Server) GetName() string

func (*Server) GetRttRrl

func (s *Server) GetRttRrl() string

func (*Server) GetServer

func (s *Server) GetServer() (*Server, error)

type ServerGroup

type ServerGroup struct {
	Servers    []interface{}
	Name       string
	SelectType string
	Selector   ISelector
	RttUrl     string
	sync.RWMutex
}

func GetGroups

func GetGroups() []*ServerGroup

func GroupExist

func GroupExist(name string) (*ServerGroup, bool)

func (*ServerGroup) GetName

func (s *ServerGroup) GetName() string

func (*ServerGroup) GetRttRrl

func (s *ServerGroup) GetRttRrl() string

func (*ServerGroup) GetServer

func (s *ServerGroup) GetServer() (*Server, error)

func (*ServerGroup) Remove

func (s *ServerGroup) Remove(name string) (isExist bool)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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