Documentation ¶
Index ¶
- func BasicAuth(inner http.Handler) http.Handler
- func Logger(inner http.Handler) http.Handler
- func Metrics(inner http.Handler) http.Handler
- func NewClient() *resty.Client
- func Recover(inner http.Handler) http.Handler
- func Rest(inner http.Handler) http.Handler
- func Seed()
- type DdClient
- type DdClientOption
- type DefaultHttpSrv
- type HttpLog
- type MemberlistServiceProvider
- type ServiceProvider
- type SmoothWeightedRoundRobinProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewClient ¶ added in v0.2.3
func NewClient() *resty.Client
NewClient creates new resty Client instance
Types ¶
type DdClient ¶ added in v0.3.7
type DdClient interface { SetProvider(provider registry.IServiceProvider) SetClient(client *resty.Client) }
DdClient defines service client interface
type DdClientOption ¶ added in v0.3.7
type DdClientOption func(DdClient)
DdClientOption defines configure function type
func WithClient ¶ added in v0.3.7
func WithClient(client *resty.Client) DdClientOption
WithClient sets http client
func WithProvider ¶ added in v0.3.7
func WithProvider(provider registry.IServiceProvider) DdClientOption
WithProvider sets service provider
type DefaultHttpSrv ¶
DefaultHttpSrv wraps gorilla mux router
func NewDefaultHttpSrv ¶
func NewDefaultHttpSrv() *DefaultHttpSrv
NewDefaultHttpSrv create a DefaultHttpSrv instance
func (*DefaultHttpSrv) AddMiddleware ¶
func (srv *DefaultHttpSrv) AddMiddleware(mwf ...func(http.Handler) http.Handler)
AddMiddleware adds middlewares to router
func (*DefaultHttpSrv) AddRoute ¶
func (srv *DefaultHttpSrv) AddRoute(route ...model.Route)
AddRoute adds routes to router
type HttpLog ¶ added in v0.2.4
type HttpLog struct { ClientIp string `json:"clientIp,omitempty"` HttpMethod string `json:"httpMethod,omitempty"` Uri string `json:"uri,omitempty"` Proto string `json:"proto,omitempty"` Host string `json:"host,omitempty"` ReqContentLength int64 `json:"reqContentLength,omitempty"` ReqHeader http.Header `json:"reqHeader,omitempty"` RequestId string `json:"requestId,omitempty"` RawReq string `json:"rawReq,omitempty"` RespBody string `json:"respBody,omitempty"` StatusCode int `json:"statusCode,omitempty"` RespHeader http.Header `json:"respHeader,omitempty"` RespContentLength int `json:"respContentLength,omitempty"` ElapsedTime string `json:"elapsedTime,omitempty"` // in ms Elapsed int64 `json:"elapsed,omitempty"` }
HttpLog wraps properties for logging http request and body Example:
POST /usersvc/pageusers HTTP/1.1 Host: localhost:6060 Content-Length: 80 Content-Type: application/json User-Agent: go-resty/2.6.0 (https://github.com/go-resty/resty) X-Request-Id: d1e4dc83-18be-493e-be5b-2e0faaca90ec {"filter":{"dept":99,"name":"Jack"},"page":{"orders":null,"pageNo":2,"size":10}}
type MemberlistServiceProvider ¶ added in v0.2.4
type MemberlistServiceProvider struct {
// contains filtered or unexported fields
}
MemberlistServiceProvider defines an implementation for IServiceProvider
func NewMemberlistServiceProvider ¶ added in v0.2.4
func NewMemberlistServiceProvider(name string) *MemberlistServiceProvider
NewMemberlistServiceProvider create an NewMemberlistServiceProvider instance
func (*MemberlistServiceProvider) AddNode ¶ added in v0.8.0
func (m *MemberlistServiceProvider) AddNode(node *memberlist.Node)
AddNode add or update node providing the service
func (*MemberlistServiceProvider) RemoveNode ¶ added in v0.8.0
func (m *MemberlistServiceProvider) RemoveNode(node *memberlist.Node)
func (*MemberlistServiceProvider) SelectServer ¶ added in v0.2.4
func (m *MemberlistServiceProvider) SelectServer() string
SelectServer selects a node which is supplying service specified by name property from cluster
func (*MemberlistServiceProvider) UpdateWeight ¶ added in v0.8.0
func (m *MemberlistServiceProvider) UpdateWeight(node *memberlist.Node)
type ServiceProvider ¶ added in v0.2.3
type ServiceProvider struct {
// contains filtered or unexported fields
}
ServiceProvider defines an implementation for IServiceProvider
func NewServiceProvider ¶ added in v0.2.3
func NewServiceProvider(env string) *ServiceProvider
NewServiceProvider creates new ServiceProvider instance
func (*ServiceProvider) AddNode ¶ added in v0.8.0
func (s *ServiceProvider) AddNode(node *memberlist.Node)
func (*ServiceProvider) RemoveNode ¶ added in v0.8.0
func (s *ServiceProvider) RemoveNode(node *memberlist.Node)
func (*ServiceProvider) SelectServer ¶ added in v0.2.3
func (s *ServiceProvider) SelectServer() string
SelectServer return service address from environment variable
func (*ServiceProvider) UpdateWeight ¶ added in v0.8.0
func (s *ServiceProvider) UpdateWeight(node *memberlist.Node)
type SmoothWeightedRoundRobinProvider ¶ added in v0.8.0
type SmoothWeightedRoundRobinProvider struct {
// contains filtered or unexported fields
}
SmoothWeightedRoundRobinProvider is a smooth weighted round-robin algo implementation for IServiceProvider https://github.com/nginx/nginx/commit/52327e0627f49dbda1e8db695e63a4b0af4448b1
func NewSmoothWeightedRoundRobinProvider ¶ added in v0.8.0
func NewSmoothWeightedRoundRobinProvider(name string) *SmoothWeightedRoundRobinProvider
NewSmoothWeightedRoundRobinProvider create an SmoothWeightedRoundRobinProvider instance
func (*SmoothWeightedRoundRobinProvider) AddNode ¶ added in v0.8.0
func (m *SmoothWeightedRoundRobinProvider) AddNode(node *memberlist.Node)
AddNode add or update node providing the service
func (*SmoothWeightedRoundRobinProvider) RemoveNode ¶ added in v0.8.0
func (m *SmoothWeightedRoundRobinProvider) RemoveNode(node *memberlist.Node)
func (*SmoothWeightedRoundRobinProvider) SelectServer ¶ added in v0.8.0
func (m *SmoothWeightedRoundRobinProvider) SelectServer() string
SelectServer selects a node which is supplying service specified by name property from cluster
func (*SmoothWeightedRoundRobinProvider) UpdateWeight ¶ added in v0.8.0
func (m *SmoothWeightedRoundRobinProvider) UpdateWeight(node *memberlist.Node)