ddhttp

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: MIT Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuth added in v0.4.9

func BasicAuth(inner http.Handler) http.Handler

BasicAuth adds http basic auth validation

func BulkHead added in v0.9.0

func BulkHead(workers int, maxWaitTime time.Duration) func(inner http.Handler) http.Handler

BulkHead add bulk head pattern middleware based on https://github.com/slok/goresilience workers is the number of workers in the execution pool. maxWaitTime is the max time an incoming request will wait to execute before being dropped its execution and return 429 response.

func Logger added in v0.2.4

func Logger(inner http.Handler) http.Handler

Logger logs http request body and response body for debugging

func Metrics added in v0.2.4

func Metrics(inner http.Handler) http.Handler

Metrics logs some metrics for http request

func NewClient added in v0.2.3

func NewClient() *resty.Client

NewClient creates new resty Client instance

func Recover added in v0.7.3

func Recover(inner http.Handler) http.Handler

Recover handles panic from processing incoming http request

func Rest added in v0.2.4

func Rest(inner http.Handler) http.Handler

Rest set Content-Type to application/json

func Seed added in v0.7.9

func Seed()

Seed starts a seed node

func Tracing added in v0.8.7

func Tracing(inner http.Handler) http.Handler

Tracing add jaeger tracing middleware

Types

type BizError added in v0.9.8

type BizError struct {
	StatusCode int
	ErrCode    int
	ErrMsg     string
}

BizError is used for business error implemented error interface StatusCode will be set to http response status code ErrCode is used for business error code ErrMsg is custom error message

func NewBizError added in v0.9.8

func NewBizError(err error, opts ...BizErrorOption) *BizError

NewBizError is factory function for creating an instance of BizError struct

func (BizError) Error added in v0.9.8

func (b BizError) Error() string

Error is used for implementing error interface

func (BizError) String added in v0.9.8

func (b BizError) String() string

String function is used for printing string representation of a BizError instance

type BizErrorOption added in v0.9.8

type BizErrorOption func(bizError *BizError)

func WithErrCode added in v0.9.8

func WithErrCode(errCode int) BizErrorOption

func WithStatusCode added in v0.9.8

func WithStatusCode(statusCode int) BizErrorOption

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

type DefaultHttpSrv struct {
	*mux.Router
	// contains filtered or unexported fields
}

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

func (*DefaultHttpSrv) Run

func (srv *DefaultHttpSrv) Run()

Run runs http server

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)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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