rest

package
v1.0.12-0...-16f252f Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSignatureConfig = errors.New("bad config for Signature")

Functions

This section is empty.

Types

type Middleware

type Middleware func(next http.HandlerFunc) http.HandlerFunc

func ToMiddleware

func ToMiddleware(handler func(next http.Handler) http.Handler) Middleware

type PrivateKeyConf

type PrivateKeyConf struct {
	Fingerprint string
	KeyFile     string
}

type RestConf

type RestConf struct {
	service.ServiceConf
	Host     string `json:",default=0.0.0.0"`
	Port     int
	Verbose  bool  `json:",optional"`
	MaxConns int   `json:",default=10000"`
	MaxBytes int64 `json:",default=1048576,range=[0:8388608]"`
	// milliseconds
	Timeout      int64         `json:",default=3000"`
	CpuThreshold int64         `json:",default=900,range=[0:1000]"`
	Signature    SignatureConf `json:",optional"`
}

why not name it as Conf, because we need to consider usage like:

type Config struct {
    rpcx.RpcConf
    rest.RestConf
}

if with the name Conf, there will be two Conf inside Config.

type Route

type Route struct {
	Method  string
	Path    string
	Handler http.HandlerFunc
}

func WithMiddleware

func WithMiddleware(middleware Middleware, rs ...Route) []Route

type RouteOption

type RouteOption func(r *featuredRoutes)

func WithJwt

func WithJwt(secret string) RouteOption

func WithJwtTransition

func WithJwtTransition(secret, prevSecret string) RouteOption

func WithPriority

func WithPriority() RouteOption

func WithSignature

func WithSignature(signature SignatureConf) RouteOption

type RunOption

type RunOption func(*Server)

func WithRouter

func WithRouter(router httpx.Router) RunOption

func WithUnauthorizedCallback

func WithUnauthorizedCallback(callback handler.UnauthorizedCallback) RunOption

func WithUnsignedCallback

func WithUnsignedCallback(callback handler.UnsignedCallback) RunOption

type Server

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

func MustNewServer

func MustNewServer(c RestConf, opts ...RunOption) *Server

func NewServer

func NewServer(c RestConf, opts ...RunOption) (*Server, error)

func (*Server) AddRoute

func (e *Server) AddRoute(r Route, opts ...RouteOption)

func (*Server) AddRoutes

func (e *Server) AddRoutes(rs []Route, opts ...RouteOption)

func (*Server) Start

func (e *Server) Start()

func (*Server) Stop

func (e *Server) Stop()

func (*Server) Use

func (e *Server) Use(middleware Middleware)

type SignatureConf

type SignatureConf struct {
	Strict      bool          `json:",default=false"`
	Expiry      time.Duration `json:",default=1h"`
	PrivateKeys []PrivateKeyConf
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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