gwk

package
v0.0.0-...-276be26 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2019 License: MIT Imports: 23 Imported by: 2

Documentation

Index

Constants

View Source
const (
	TYPE_MS   = "ms"
	TYPE_HTTP = "http"
	TYPE_MOCK = "mock"

	AUTH_TYPE_NONE   = "none"
	AUTH_TYPE_BASIC  = "basic"
	AUTH_TYPE_HEADER = "header"
	AUTH_TYPE_JWT    = "jwt"
	AUTH_TYPE_OAUTH1 = "oauth1"
	AUTH_TYPE_OAUTH2 = "oauth2"

	DEFAULT_SERVICE_SUFFIX = ".service.consul."
	DEFAULT_DNS_SERVER     = "127.0.0.1:8600"
)

Variables

View Source
var (
	// DefaultGzipConfig is the default Gzip middleware config.
	DefaultForwardersConfig = Config{
		Forwarders: []*FwdItem{},
		Skipper:    middleware.DefaultSkipper,
	}

	HeaderXServer = false

	ThisConfig Config
)
View Source
var (
	DefaultGwBackend = &defaultBackend{}
)

Functions

func ContextReplacer

func ContextReplacer(h echo.HandlerFunc) echo.HandlerFunc

func Error

func Error(msg string)

func Errorf

func Errorf(fmt string, args ...interface{})

func Shutdown

func Shutdown()

Types

type Auth

type Auth struct {
	// basic auth, header(jwt), key-based: oauth1, oauth2, ...
	Type      string `json:"type,omitempty" yaml:"type,omitempty"`
	Username  string `json:"userid,omitempty" yaml:"userid,omitempty"`
	Password  string `json:"passwd,omitempty" yaml:"passwd,omitempty"`
	Header    string `json:"header,omitempty" yaml:"header,omitempty"`
	AppKey    string `json:"appkey,omitempty" yaml:"appkey,omitempty"`
	AppSecret string `json:"secret,omitempty" yaml:"secret,omitempty"`
}

Auth 提供目标服务的认证方案,注意通常不需要

type CircuitBreakAt

type CircuitBreakAt struct {
	Failed        int `json:"failed,omitempty" yaml:"failed,omitempty"`
	Timeout       int `json:"timeout,omitempty" yaml:"timeout,omitempty"`
	CannotResolve int `json:"cannotresolve,omitempty" yaml:"cannotresolve,omitempty"`
	HTTP5xx       int `json:"5xx,omitempty" yaml:"5xx,omitempty"`
	HTTP4xx       int `json:"4xx,omitempty" yaml:"4xx,omitempty"`
}

type Config

type Config struct {
	Forwarders     []*FwdItem         `json:"forwarders" yaml:"forwarders,flow"`
	Registrar      Registrar          `json:"registrar" yaml:"registrar,flow"`
	Skipper        middleware.Skipper `json:"_,omitempty" yaml:",omitempty"` // Skipper defines a function to skip middleware.
	UniqueFwdIDMap map[string]int     `json:"_,omitempty" yaml:",omitempty"`
	UniqueLbIDMap  map[string]int     `json:"_,omitempty" yaml:",omitempty"`
	UniqueLbIDInt  int                `json:"_,omitempty" yaml:",omitempty"`
	Echo           *echo.Echo         `json:"_,omitempty" yaml:",omitempty"`
}

Config a forwarders configurations inside main app config file (meta.yaml)

func GetAppConfig

func GetAppConfig() *Config

func (*Config) Init

func (s *Config) Init()

func (*Config) Shutdown

func (s *Config) Shutdown()

type Context

type Context struct {
	echo.Context
}

func (*Context) Bar

func (c *Context) Bar() string

func (*Context) Foo

func (c *Context) Foo() string

type FwdItem

type FwdItem struct {
	ID               string   `json:"id" yaml:"id"`
	Type             string   `json:"type" yaml:"type"`
	Match            string   `json:"match" yaml:"match"`
	To               To       `json:"to,omitempty" yaml:"to,omitempty"`
	Targets          []string `json:"targets,flow,omitempty" yaml:"targets,flow,omitempty"`
	Mocks            []*Mock  `json:"mocks,omitempty" yaml:"mocks,omitempty"`
	Lb               *LoadBal `json:"lb,omitempty" yaml:"lb,omitempty"`
	DowngradeToHttp1 bool     `json:"downgrade-to-http1,omitempty" yaml:"downgrade-to-http1,omitempty"`
	ReverseRewrite   bool     `json:"reverse-rewrite,omitempty" yaml:"reverse-rewrite,omitempty"`
	Insecure         bool     `json:"insecure,omitempty" yaml:"insecure,omitempty"`
	NoTrailingSlash  bool     `json:"no-trailing-slash,omitempty" yaml:"no-trailing-slash,omitempty"`
	Description      string   `json:"desc,omitempty" yaml:"desc,omitempty"`
	WhiteLists       []string `json:"white-lists,omitempty" yaml:"white-lists,omitempty"`
	BlackLists       []string `json:"black-lists,omitempty" yaml:"black-lists,omitempty"`
	Disabled         bool     `json:"disabled,omitempty" yaml:"disabled,omitempty"`
	BreakAtFailured  int      `json:"break-at-failure,omitempty" yaml:"break-at-failure,omitempty"`
	Auth             Auth     `json:"auth,omitempty" yaml:"auth,omitempty"`
	ForceUpdate      bool     `json:"force-update,omitempty" yaml:"force-update,omitempty"`
	// contains filtered or unexported fields
}

Forwarder to define a forwarder/proxy/reverse-proxy to micro-service/external-service/...

func (*FwdItem) Balancer

func (s *FwdItem) Balancer() (bal middleware.ProxyBalancer)

func (*FwdItem) BalancerIsEmpty

func (s *FwdItem) BalancerIsEmpty() bool

func (*FwdItem) BuildUrl

func (s *FwdItem) BuildUrl(ip net.IP, port uint16, req *http.Request) *url.URL

func (*FwdItem) Init

func (s *FwdItem) Init()

func (*FwdItem) MiddlewareFunc

func (s *FwdItem) MiddlewareFunc() (fn echo.MiddlewareFunc)

func (*FwdItem) Proxy

func (s *FwdItem) Proxy() (p *proxy.TinyProxy)

func (*FwdItem) PutVersion

func (s *FwdItem) PutVersion(res *http.Response, target *url.URL)

PutVersion 专用于放置从后端响应头中提取到的版本号相关信息

func (*FwdItem) SetBalancer

func (s *FwdItem) SetBalancer(bal middleware.ProxyBalancer)

func (*FwdItem) SetMiddlewareFunc

func (s *FwdItem) SetMiddlewareFunc(fn echo.MiddlewareFunc)

func (*FwdItem) SetProxy

func (s *FwdItem) SetProxy(p *proxy.TinyProxy)

兼容旧版本算法,旧版本使用 TinyProxy

func (*FwdItem) Shutdown

func (s *FwdItem) Shutdown()

func (*FwdItem) StatsIncreaseHit

func (s *FwdItem) StatsIncreaseHit(target *middleware.ProxyTarget, ctx echo.Context, res *http.Request)

func (*FwdItem) StatsIncreaseReq

func (s *FwdItem) StatsIncreaseReq(target *middleware.ProxyTarget, ctx echo.Context, req *http.Request, url *url.URL, realIP string)

func (*FwdItem) StatsIncreaseResp

func (s *FwdItem) StatsIncreaseResp(target *middleware.ProxyTarget, ctx echo.Context, res *http.Response, url *url.URL, realIP string)

type GwBackend

type GwBackend interface {
	GetID() string
	GetURLString() string
	GetTag() string
	GetWeight() string
}

type GwBalancer

type GwBalancer interface {
	GetID() string
	// GetBackend returns the real backend object from the balancer
	GetBackend(target *middleware.ProxyTarget) GwBackend
}

type LoadBal

type LoadBal struct {
	ID             string            `json:"id,omitempty" yaml:"id,omitempty"`
	Algorithm      string            `json:"alg" yaml:"alg"`
	CircuitBreakAt *CircuitBreakAt   `json:"break" yaml:"break"`
	Smart          *LoadBalanceSmart `json:"smart,omitempty" yaml:"smart,omitempty"`
}

type LoadBalanceSmart

type LoadBalanceSmart struct {
	URLHash  []string `json:"url-hash,omitempty" yaml:"url-hash,omitempty"`
	IPHash   []string `json:"ip-hash,omitempty" yaml:"ip-hash,omitempty"`
	Versions []string `json:"ver,omitempty" yaml:"ver,omitempty"`
	Weight   []int    `json:"weight,omitempty" yaml:"weight,omitempty"`
}

type Mock

type Mock struct {
	Methods []string    `json:"methods,flow,omitempty" yaml:"methods,flow,omitempty"`
	Object  interface{} `json:"object,omitempty" yaml:"object,flow,omitempty"`
	Text    string      `json:"text,omitempty" yaml:"text,omitempty"`
}

type Registrar

type Registrar struct {
	Enabled    bool                           `json:"enabled" yaml:"enabled"`
	Source     string                         `json:"source" yaml:"source"`
	Env        string                         `json:"env" yaml:"env"`
	TTL        int64                          `json:"ttl,omitempty" yaml:"ttl,omitempty"`
	Consul     map[string]*store.ConsulConfig `json:"consul,omitempty" yaml:"consul,omitempty"`
	Etcd       map[string]*store.Etcdtool     `json:"etcd,omitempty" yaml:"etcd,omitempty"`
	DNSAtFirst bool                           `json:"dns-at-first,omitempty" yaml:"dns-at-first,omitempty"`
	// contains filtered or unexported fields
}

func (*Registrar) Close

func (s *Registrar) Close()

func (*Registrar) GetStore

func (s *Registrar) GetStore() store.KVStore

func (*Registrar) IsOpen

func (s *Registrar) IsOpen() bool

func (*Registrar) Open

func (s *Registrar) Open()

func (*Registrar) SvrRecordDeregister

func (s *Registrar) SvrRecordDeregister(serviceName string, all bool) (err error)

func (*Registrar) SvrRecordRegister

func (s *Registrar) SvrRecordRegister(serviceName, version string) (err error)

SvrRecordRegister 注册服务到登记库中

func (*Registrar) SvrRecordResolver

func (s *Registrar) SvrRecordResolver(serviceName, ver, what string) (net.IP, uint16, string)

SvrRecordResolver 返回单一一条可用服务记录(总是返回首条) return net.IPv4zero, 0 means there are no more targets to be found

func (*Registrar) SvrRecordResolverAll

func (s *Registrar) SvrRecordResolverAll(serviceName string, what string) []*store.ServiceRecord

SvrRecordResolverAll 返回全部可用的服务记录

return all addresses if the service

for ETCD, `what` can be "addr", "grpc" for CONSUL, `what` should be empty string now

type Stub

type Stub struct {
	Forwarders []FwdItem `json:"forwarders" yaml:"forwarders,flow"`
}

Stud is just a structure stub used for yaml converter

type Targets

type Targets struct {
	Value []string `json:"target,omitempty" yaml:"target,omitempty"`
}

Targets present a set of endpoints about that external/internal RESTful service

type To

type To struct {
	MS      string `json:"ms,omitempty" yaml:"ms,omitempty"`
	Context string `json:"context,omitempty" yaml:"context,omitempty"` // ContextUrl前缀
}

To presents where to go to a micro-service, includes its well-known service name in registry

type VersionSetter

type VersionSetter interface {
	PutVersion(res *http.Response, target *url.URL, name string, version string)
}

Jump to

Keyboard shortcuts

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