ddhttp

package
v0.7.7 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2021 License: MIT Imports: 34 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 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

Types

type DdClient added in v0.3.7

type DdClient interface {
	SetProvider(provider 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 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 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 IServiceProvider added in v0.2.3

type IServiceProvider interface {
	SelectServer() (string, error)
}

IServiceProvider defines service provider interface for server discovery

func NewMemberlistServiceProvider added in v0.2.4

func NewMemberlistServiceProvider(name string, registry registry.IRegistry, opts ...MemberlistProviderOption) IServiceProvider

NewMemberlistServiceProvider create an NewMemberlistServiceProvider instance

func NewServiceProvider added in v0.2.3

func NewServiceProvider(env string, opts ...ServiceProviderOption) IServiceProvider

NewServiceProvider creates new ServiceProvider instance

type MemberlistProviderOption added in v0.2.4

type MemberlistProviderOption func(IServiceProvider)

MemberlistProviderOption defines a function for setting properties of MemberlistServiceProvider

type MemberlistServiceProvider added in v0.2.4

type MemberlistServiceProvider struct {
	// contains filtered or unexported fields
}

MemberlistServiceProvider defines an implementation for IServiceProvider. Recommend to use.

func (*MemberlistServiceProvider) SelectServer added in v0.2.4

func (m *MemberlistServiceProvider) SelectServer() (string, error)

SelectServer selects a node which is supplying service specified by name property from cluster

type ServiceProvider added in v0.2.3

type ServiceProvider struct {
	Env string
}

ServiceProvider defines an implementation for IServiceProvider

func (*ServiceProvider) SelectServer added in v0.2.3

func (s *ServiceProvider) SelectServer() (string, error)

SelectServer return service address from environment variable

type ServiceProviderOption added in v0.2.3

type ServiceProviderOption func(IServiceProvider)

ServiceProviderOption sets properties of ServiceProvider

type Srv

type Srv interface {
	// Run the service
	Run()
	// Register routes
	AddRoute(route ...model.Route)
	// Use middleware
	AddMiddleware(mwf ...func(http.Handler) http.Handler)
}

Srv represents a go-doudou service

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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