Documentation
¶
Index ¶
- Constants
- Variables
- func MinusClusters(c map[string]*Cluster, c1 map[string]*Cluster, filter func(*Cluster) bool) map[string]*Cluster
- func MinusServers(c map[string]*Server, c1 map[string]*Server, filter func(*Server) bool) map[string]*Server
- type API
- type AccessControl
- type AddAnalysisPointReq
- type AddAnalysisPointRsp
- type Analysis
- func (a *Analysis) AddRecentCount(key string, secs int)
- func (a *Analysis) Failure(key string)
- func (a *Analysis) GetContinuousFailureCount(server string) int
- func (a *Analysis) GetQPS(server string, secs int) int
- func (a *Analysis) GetRecentlyAvg(server string, secs int) int
- func (a *Analysis) GetRecentlyMax(server string, secs int) int
- func (a *Analysis) GetRecentlyMin(server string, secs int) int
- func (a *Analysis) GetRecentlyRejectCount(server string, secs int) int
- func (a *Analysis) GetRecentlyRequestCount(server string, secs int) int
- func (a *Analysis) GetRecentlyRequestFailureCount(server string, secs int) int
- func (a *Analysis) GetRecentlyRequestSuccessedCount(server string, secs int) int
- func (a *Analysis) Reject(key string)
- func (a *Analysis) Request(key string)
- func (a *Analysis) Response(key string, cost int64)
- type Bind
- type Circuit
- type Cluster
- type Clusters
- type EtcdStore
- func (e EtcdStore) AddAnalysisPoint(proxyAddr, serverAddr string, secs int) error
- func (e EtcdStore) ChangeLogLevel(addr string, level string) error
- func (e EtcdStore) Clean() error
- func (e EtcdStore) DeleteAPI(apiURL, method string) error
- func (e EtcdStore) DeleteCluster(name string) error
- func (e EtcdStore) DeleteServer(addr string) error
- func (e EtcdStore) GC() error
- func (e EtcdStore) GetAPI(apiURL, method string) (*API, error)
- func (e EtcdStore) GetAPIs() ([]*API, error)
- func (e EtcdStore) GetAnalysisPoint(proxyAddr, serverAddr string, secs int) (*GetAnalysisPointRsp, error)
- func (e EtcdStore) GetBinds() ([]*Bind, error)
- func (e EtcdStore) GetCluster(clusterName string) (*Cluster, error)
- func (e EtcdStore) GetClusters() ([]*Cluster, error)
- func (e EtcdStore) GetProxies() ([]*ProxyInfo, error)
- func (e EtcdStore) GetRoutings() ([]*Routing, error)
- func (e EtcdStore) GetServer(serverAddr string) (*Server, error)
- func (e EtcdStore) GetServers() ([]*Server, error)
- func (e EtcdStore) Registry(proxyInfo *ProxyInfo) error
- func (e EtcdStore) SaveAPI(api *API) error
- func (e EtcdStore) SaveBind(bind *Bind) error
- func (e EtcdStore) SaveCluster(cluster *Cluster) error
- func (e EtcdStore) SaveRouting(routing *Routing) error
- func (e EtcdStore) SaveServer(svr *Server) error
- func (e EtcdStore) UnBind(bind *Bind) error
- func (e EtcdStore) UpdateAPI(api *API) error
- func (e EtcdStore) UpdateCluster(cluster *Cluster) error
- func (e EtcdStore) UpdateServer(svr *Server) error
- func (e EtcdStore) Watch(evtCh chan *Evt, stopCh chan bool) error
- type Evt
- type EvtSrc
- type EvtType
- type GetAnalysisPointReq
- type GetAnalysisPointRsp
- type Mock
- type MockHeader
- type Node
- type ProxyInfo
- type Recently
- type Register
- type RouteResult
- type RouteTable
- func (r *RouteTable) AddNewAPI(api *API) error
- func (r *RouteTable) AddNewCluster(cluster *Cluster) error
- func (r *RouteTable) AddNewRouting(routing *Routing) error
- func (r *RouteTable) AddNewServer(svr *Server) error
- func (r *RouteTable) Bind(svrAddr string, clusterName string) error
- func (r *RouteTable) DeleteAPI(url, method string) error
- func (r *RouteTable) DeleteCluster(clusterName string) error
- func (r *RouteTable) DeleteRouting(id string) error
- func (r *RouteTable) DeleteServer(serverAddr string) error
- func (r *RouteTable) GetAnalysis() *Analysis
- func (r *RouteTable) GetServer(addr string) *Server
- func (r *RouteTable) GetTimeWheel() *goetty.HashedTimeWheel
- func (r *RouteTable) Load()
- func (r *RouteTable) Select(req *fasthttp.Request) []*RouteResult
- func (r *RouteTable) UnBind(svrAddr string, clusterName string) error
- func (r *RouteTable) UpdateAPI(api *API) error
- func (r *RouteTable) UpdateCluster(cluster *Cluster) error
- func (r *RouteTable) UpdateServer(svr *Server) error
- type Routing
- type RoutingItem
- type Server
- func (s *Server) AddBind(bind *Bind)
- func (s *Server) CloseCircuit()
- func (s *Server) GetCircuit() Circuit
- func (s *Server) HalfCircuit()
- func (s *Server) HasBind() bool
- func (s *Server) Lock()
- func (s *Server) Marshal() []byte
- func (s *Server) OpenCircuit()
- func (s *Server) RemoveBind(clusterName string)
- func (s *Server) UnLock()
- type Servers
- type ServiceDiscoveryDriver
- type SetLogReq
- type SetLogRsp
- type SetReqHeadStaticMappingReq
- type SetReqHeadStaticMappingRsp
- type Status
- type Store
- type Validation
- type ValidationRule
Constants ¶
const ( // APIStatusDown down status APIStatusDown = iota //APIStatusUp up status APIStatusUp )
const ( // FromQueryString query string FromQueryString = iota // FromForm form data FromForm )
const ( // Down backend server down status Down = Status(0) // Up backend server up status Up = Status(1) )
const ( // CircuitOpen Circuit open status CircuitOpen = Circuit(0) // CircuitHalf Circuit half status CircuitHalf = Circuit(1) // CircuitClose Circuit close status CircuitClose = Circuit(2) )
const ( // DefaultCheckDurationInSeconds Default duration to check server DefaultCheckDurationInSeconds = 5 // DefaultCheckTimeoutInSeconds Default timeout to check server DefaultCheckTimeoutInSeconds = 3 )
const ( // ActionClusters query cluster ActionClusters = "/clusters" // ActionServers query servers ActionServers = "/clusters/" )
const ( // EventTypeNew event type new EventTypeNew = EvtType(0) // EventTypeUpdate event type update EventTypeUpdate = EvtType(1) // EventTypeDelete event type delete EventTypeDelete = EvtType(2) )
const ( // EventSrcCluster cluster event EventSrcCluster = EvtSrc(0) // EventSrcServer server event EventSrcServer = EvtSrc(1) // EventSrcBind bind event EventSrcBind = EvtSrc(2) // EventSrcAPI api event EventSrcAPI = EvtSrc(3) // EventSrcRouting routing event EventSrcRouting = EvtSrc(4) )
const ( // Regexp reg type Regexp = iota )
Variables ¶
var ( // TICKER ticket TICKER = time.Second * 3 // TTL timeout TTL = uint64(5) )
var ( // GlobalCfgDesc global desc cfg GlobalCfgDesc = "desc" // GlobalCfgOrder global order cfg GlobalCfgOrder = "order" // GlobalCfgDeadline global deadline cfg GlobalCfgDeadline = "deadline" // GlobalCfgRule global rule cfg GlobalCfgRule = "rule" // GlobalCfgOr global or cfg GlobalCfgOr = "or" )
var ( // ValueHeader value of header prefix ValueHeader = "$HEADER" // ValueCookie value of cookie prefix ValueCookie = "$COOKIE" // ValueQuery value of query string prefix ValueQuery = "$QUERY" )
rule: left [==,>,<=,>=,in,~] right can use var: $header_, $cookie_, $query_
var ( // EQ == EQ = "==" // LT < LT = "<" // LE <= LE = "<=" // GT > GT = ">" // GE >= GE = ">=" // IN in IN = "in" // MATCH reg matches MATCH = "~" // PATTERN reg pattern for expression PATTERN = regexp.MustCompile(fmt.Sprintf("^(?U)(.+)(%s|%s|%s|%s|%s|%s|%s)(.+)$", EQ, LE, LT, GE, GT, IN, MATCH)) )
var ( // ErrServerExists Server already exist ErrServerExists = errors.New("Server already exist") // ErrClusterExists Cluster already exist ErrClusterExists = errors.New("Cluster already exist") // ErrBindExists Bind already exist ErrBindExists = errors.New("Bind already exist") // ErrAPIExists API already exist ErrAPIExists = errors.New("API already exist") // ErrRoutingExists Routing already exist ErrRoutingExists = errors.New("Routing already exist") // ErrServerNotFound Server not found ErrServerNotFound = errors.New("Server not found") // ErrClusterNotFound Cluster not found ErrClusterNotFound = errors.New("Cluster not found") // ErrBindNotFound Bind not found ErrBindNotFound = errors.New("Bind not found") // ErrAPINotFound API not found ErrAPINotFound = errors.New("API not found") // ErrRoutingNotFound Routing not found ErrRoutingNotFound = errors.New("Routing not found") )
var ( // ErrHasBind error has bind into, can not delete ErrHasBind = errors.New("Has bind info, can not delete") )
var ( // ErrSyntax Syntax error ErrSyntax = errors.New("Syntax error") )
Functions ¶
Types ¶
type API ¶
type API struct {
Name string `json:"name, omitempty"`
URL string `json:"url"`
Method string `json:"method"`
Domain string `json:"domain, omitempty"`
Status int `json:"status, omitempty"`
AccessControl *AccessControl `json:"accessControl, omitempty"`
Mock *Mock `json:"mock, omitempty"`
Nodes []*Node `json:"nodes"`
Desc string `json:"desc, omitempty"`
Pattern *regexp.Regexp `json:"-"`
}
API a api define
func UnMarshalAPIFromReader ¶
UnMarshalAPIFromReader unmarshal from reader
func (*API) AccessCheckBlacklist ¶
AccessCheckBlacklist check blacklist
func (*API) AccessCheckWhitelist ¶
AccessCheckWhitelist check whitelist
func (*API) RenderMock ¶
func (a *API) RenderMock(ctx *fasthttp.RequestCtx)
RenderMock dender mock response
type AccessControl ¶
type AccessControl struct {
Whitelist []string `json:"whitelist, omitempty"`
Blacklist []string `json:"blacklist, omitempty"`
// contains filtered or unexported fields
}
AccessControl access control
type AddAnalysisPointReq ¶
AddAnalysisPointReq AddAnalysisPointReq
type AddAnalysisPointRsp ¶
type AddAnalysisPointRsp struct {
Code int
}
AddAnalysisPointRsp AddAnalysisPointRsp
type Analysis ¶
type Analysis struct {
// contains filtered or unexported fields
}
Analysis analysis struct
func (*Analysis) AddRecentCount ¶
AddRecentCount add analysis point on a key
func (*Analysis) GetContinuousFailureCount ¶
GetContinuousFailureCount return Continuous failure request count in spec secs
func (*Analysis) GetRecentlyAvg ¶
GetRecentlyAvg return avg latency in spec secs
func (*Analysis) GetRecentlyMax ¶
GetRecentlyMax return max latency in spec secs
func (*Analysis) GetRecentlyMin ¶
GetRecentlyMin return min latency in spec secs
func (*Analysis) GetRecentlyRejectCount ¶
GetRecentlyRejectCount return reject count in spec secs
func (*Analysis) GetRecentlyRequestCount ¶
GetRecentlyRequestCount return the server request count in spec seconds
func (*Analysis) GetRecentlyRequestFailureCount ¶
GetRecentlyRequestFailureCount return failure request count in spec secs
func (*Analysis) GetRecentlyRequestSuccessedCount ¶
GetRecentlyRequestSuccessedCount return successed request count in spec secs
type Bind ¶
type Bind struct {
ClusterName string `json:"clusterName,omitempty"`
ServerAddr string `json:"serverAddr,omitempty"`
}
Bind a bind server and cluster
func UnMarshalBindFromReader ¶
UnMarshalBindFromReader unmarshal
type Cluster ¶
type Cluster struct {
Name string `json:"name,omitempty"`
LbName string `json:"lbName,omitempty"`
// External external, e.g. create from external service discovery
External bool `json:"external,omitempty"`
BindServers []string `json:"bindServers,omitempty"`
// contains filtered or unexported fields
}
Cluster cluster
func NewCluster ¶
NewCluster create a cluster
func UnMarshalClusterFromReader ¶
UnMarshalClusterFromReader unmarshal from reader
type EtcdStore ¶
type EtcdStore struct {
// contains filtered or unexported fields
}
EtcdStore etcd store impl
func (EtcdStore) AddAnalysisPoint ¶
AddAnalysisPoint add a analysis point
func (EtcdStore) ChangeLogLevel ¶
ChangeLogLevel change proxy log level
func (EtcdStore) DeleteCluster ¶
DeleteCluster delete a cluster from store
func (EtcdStore) DeleteServer ¶
DeleteServer delete a server from store
func (EtcdStore) GetAnalysisPoint ¶
func (e EtcdStore) GetAnalysisPoint(proxyAddr, serverAddr string, secs int) (*GetAnalysisPointRsp, error)
GetAnalysisPoint return analysis point data
func (EtcdStore) GetCluster ¶
GetCluster return cluster info
func (EtcdStore) GetClusters ¶
GetClusters return clusters in store
func (EtcdStore) GetProxies ¶
GetProxies return runable proxies
func (EtcdStore) GetRoutings ¶
GetRoutings return routes in store
func (EtcdStore) GetServers ¶
GetServers return server from store
func (EtcdStore) SaveCluster ¶
SaveCluster save a cluster to store
func (EtcdStore) SaveRouting ¶
SaveRouting save route to store
func (EtcdStore) SaveServer ¶
SaveServer save a server to store
func (EtcdStore) UpdateCluster ¶
UpdateCluster update a cluster to store
func (EtcdStore) UpdateServer ¶
UpdateServer update a server to store
type GetAnalysisPointReq ¶
GetAnalysisPointReq GetAnalysisPointReq
type GetAnalysisPointRsp ¶
type GetAnalysisPointRsp struct {
Code int `json:"schema,omitempty"`
RequestCount int `json:"requestCount"`
RejectCount int `json:"rejectCount"`
RequestSuccessedCount int `json:"requestSuccessedCount"`
RequestFailureCount int `json:"requestFailureCount"`
ContinuousFailureCount int `json:"continuousFailureCount"`
QPS int `json:"qps"`
Max int `json:"max"`
Min int `json:"min"`
Avg int `json:"avg"`
}
GetAnalysisPointRsp GetAnalysisPointRsp
type Mock ¶
type Mock struct {
Value string `json:"value"`
ContentType string `json:"contentType, omitempty"`
Headers []*MockHeader `json:"headers, omitempty"`
Cookies []string `json:"cookies, omitempty"`
ParsedCookies []*fasthttp.Cookie `json:"-"`
}
Mock mock
type MockHeader ¶
MockHeader header
type Node ¶
type Node struct {
ClusterName string `json:"clusterName, omitempty"`
Rewrite string `json:"rewrite, omitempty"`
AttrName string `json:"attrName, omitempty"`
Validations []*Validation `json:"validations, omitempty"`
}
Node api dispatch node
type Recently ¶
type Recently struct {
// contains filtered or unexported fields
}
Recently recently point data
type Register ¶
type Register interface {
Registry(proxyInfo *ProxyInfo) error
GetProxies() ([]*ProxyInfo, error)
ChangeLogLevel(proxyAddr string, level string) error
AddAnalysisPoint(proxyAddr, serverAddr string, secs int) error
GetAnalysisPoint(proxyAddr, serverAddr string, secs int) (*GetAnalysisPointRsp, error)
}
Register register
type RouteResult ¶
type RouteResult struct {
API *API
Node *Node
Svr *Server
Err error
Code int
Res *fasthttp.Response
Merge bool
}
RouteResult RouteResult
func (*RouteResult) GetRewritePath ¶
func (result *RouteResult) GetRewritePath(req *fasthttp.Request) string
GetRewritePath get rewrite path
func (*RouteResult) NeedRewrite ¶
func (result *RouteResult) NeedRewrite() bool
NeedRewrite need rewrite
type RouteTable ¶
type RouteTable struct {
// contains filtered or unexported fields
}
RouteTable route table
func NewRouteTable ¶
func NewRouteTable(cnf *conf.Conf, store Store, serviceDiscoveryDriver *ServiceDiscoveryDriver) *RouteTable
NewRouteTable create a new RouteTable
func (*RouteTable) AddNewAPI ¶
func (r *RouteTable) AddNewAPI(api *API) error
AddNewAPI add a new API
func (*RouteTable) AddNewCluster ¶
func (r *RouteTable) AddNewCluster(cluster *Cluster) error
AddNewCluster add new cluster
func (*RouteTable) AddNewRouting ¶
func (r *RouteTable) AddNewRouting(routing *Routing) error
AddNewRouting add a new route
func (*RouteTable) AddNewServer ¶
func (r *RouteTable) AddNewServer(svr *Server) error
AddNewServer add a new server
func (*RouteTable) Bind ¶
func (r *RouteTable) Bind(svrAddr string, clusterName string) error
Bind bind server and cluster
func (*RouteTable) DeleteAPI ¶
func (r *RouteTable) DeleteAPI(url, method string) error
DeleteAPI delete a api using url
func (*RouteTable) DeleteCluster ¶
func (r *RouteTable) DeleteCluster(clusterName string) error
DeleteCluster delete a cluster
func (*RouteTable) DeleteRouting ¶
func (r *RouteTable) DeleteRouting(id string) error
DeleteRouting delete a route
func (*RouteTable) DeleteServer ¶
func (r *RouteTable) DeleteServer(serverAddr string) error
DeleteServer delete a server
func (*RouteTable) GetAnalysis ¶
func (r *RouteTable) GetAnalysis() *Analysis
GetAnalysis return analysis
func (*RouteTable) GetServer ¶
func (r *RouteTable) GetServer(addr string) *Server
GetServer return server
func (*RouteTable) GetTimeWheel ¶
func (r *RouteTable) GetTimeWheel() *goetty.HashedTimeWheel
GetTimeWheel return time wheel
func (*RouteTable) Select ¶
func (r *RouteTable) Select(req *fasthttp.Request) []*RouteResult
Select return route result
func (*RouteTable) UnBind ¶
func (r *RouteTable) UnBind(svrAddr string, clusterName string) error
UnBind unbind cluster and server
func (*RouteTable) UpdateCluster ¶
func (r *RouteTable) UpdateCluster(cluster *Cluster) error
UpdateCluster update cluster
func (*RouteTable) UpdateServer ¶
func (r *RouteTable) UpdateServer(svr *Server) error
UpdateServer update server
type Routing ¶
type Routing struct {
ClusterName string `json:"clusterName, omitempty"`
ID string `json:"id,omitempty"`
Cfg string `json:"cfg,omitempty"`
URL string `json:"url,omitempty"`
// contains filtered or unexported fields
}
Routing routing
func NewRouting ¶
NewRouting create a new Routing
func UnMarshalRoutingFromReader ¶
UnMarshalRoutingFromReader unmarshal
type RoutingItem ¶
type RoutingItem struct {
// contains filtered or unexported fields
}
RoutingItem routing item
type Server ¶
type Server struct {
Schema string `json:"schema,omitempty"`
Addr string `json:"addr,omitempty"`
// External external, e.g. create from external service discovery
External bool `json:"external,omitempty"`
// CheckPath begin with / checkpath, expect return CheckResponsedBody.
CheckPath string `json:"checkPath,omitempty"`
// CheckResponsedBody check url responsed http body, if not set, not check body
CheckResponsedBody string `json:"checkResponsedBody"`
// CheckDuration check interval, unit second
CheckDuration int `json:"checkDuration,omitempty"`
// CheckTimeout timeout to check server
CheckTimeout int `json:"checkTimeout,omitempty"`
// Status Server status
Status Status `json:"status,omitempty"`
// MaxQPS the backend server max qps support
MaxQPS int `json:"maxQPS,omitempty"`
HalfToOpen int `json:"halfToOpen,omitempty"`
HalfTrafficRate int `json:"halfTrafficRate,omitempty"`
CloseCount int `json:"closeCount,omitempty"`
BindClusters []string `json:"bindClusters,omitempty"`
// contains filtered or unexported fields
}
Server server
func UnMarshalServerFromReader ¶
UnMarshalServerFromReader unmarshal
type ServiceDiscoveryDriver ¶
type ServiceDiscoveryDriver struct {
// contains filtered or unexported fields
}
ServiceDiscoveryDriver service discovery driver service discovery is used for auto discovery domains, servers and binds.
func NewServiceDiscoveryDriver ¶
func NewServiceDiscoveryDriver(registryCenter *plugin.RegistryCenter) *ServiceDiscoveryDriver
NewServiceDiscoveryDriver new ServiceDiscoveryDriver
func (*ServiceDiscoveryDriver) GetAllClusters ¶
func (d *ServiceDiscoveryDriver) GetAllClusters() (*Clusters, error)
GetAllClusters get all clusters
func (*ServiceDiscoveryDriver) GetServersByClusterName ¶
func (d *ServiceDiscoveryDriver) GetServersByClusterName(clusterName string) (*Servers, error)
GetServersByClusterName get all servers in domains
type SetReqHeadStaticMappingReq ¶
SetReqHeadStaticMappingReq SetReqHeadStaticMappingReq
type SetReqHeadStaticMappingRsp ¶
type SetReqHeadStaticMappingRsp struct {
Code int
}
SetReqHeadStaticMappingRsp SetReqHeadStaticMappingRsp
type Store ¶
type Store interface {
SaveBind(bind *Bind) error
UnBind(bind *Bind) error
GetBinds() ([]*Bind, error)
SaveCluster(cluster *Cluster) error
UpdateCluster(cluster *Cluster) error
DeleteCluster(name string) error
GetClusters() ([]*Cluster, error)
GetCluster(clusterName string) (*Cluster, error)
SaveServer(svr *Server) error
UpdateServer(svr *Server) error
DeleteServer(addr string) error
GetServers() ([]*Server, error)
GetServer(serverAddr string) (*Server, error)
SaveAPI(api *API) error
UpdateAPI(api *API) error
DeleteAPI(url string, method string) error
GetAPIs() ([]*API, error)
GetAPI(url string, method string) (*API, error)
SaveRouting(routing *Routing) error
GetRoutings() ([]*Routing, error)
Watch(evtCh chan *Evt, stopCh chan bool) error
Clean() error
GC() error
}
Store store interface
type Validation ¶
type Validation struct {
Attr string `json:"attr, omitempty"`
GetFrom int `json:"getFrom, omitempty"`
Required bool `json:"required, omitempty"`
Rules []*ValidationRule `json:"rules, omitempty"`
}
Validation validate rule
func (Validation) ParseValidation ¶
func (v Validation) ParseValidation()
ParseValidation parse validation
type ValidationRule ¶
type ValidationRule struct {
Type int `json:"type, omitempty"`
Expression string `json:"expression, omitempty"`
// contains filtered or unexported fields
}
ValidationRule validation rule