Documentation ¶
Index ¶
- Constants
- func CodecForRequest(ctx context.Context, headerName string) (xbinding.Codec, bool)
- func DefaultErrorEncoder(ctx context.Context, err error)
- func DefaultRequestDecoder(ctx context.Context, v interface{}) (err error)
- func DefaultResponseEncoder(ctx context.Context, v interface{}) (err error)
- func Deregister(name string)
- func Register(resolver Resolver)
- func RegistryEngineRoute(engine AdapterEngine, router *RouterGroup)
- type AdapterEngine
- type DataEncoder
- type DecodeRequestFunc
- type EncodeErrorFunc
- type EncodeResponseFunc
- type HandlerFunc
- type Header
- type Hook
- type HttpEngine
- type IChecker
- type LogContext
- type Method
- type NormalRouterOption
- type Option
- func WithConfig(cfg config.Config) Option
- func WithErrorEncoder(errorEncoder EncodeErrorFunc) Option
- func WithLogOptions(opt *log.Options) Option
- func WithRequestDecoder(requestDecoder DecodeRequestFunc) Option
- func WithResponseEncoder(responseEncoder EncodeResponseFunc) Option
- func WithSrvName(name string) Option
- func WithSrvType(srvType string) Option
- type Options
- type Request
- type Resolver
- type ResponseEntity
- type ResponseWriter
- type RouterGroup
- func (group *RouterGroup) BasePath() string
- func (group *RouterGroup) GetTreePathList() []string
- func (group *RouterGroup) Group(relativePath string, middlewares ...middleware.Middleware) *RouterGroup
- func (group *RouterGroup) Handle(relativePath string, handler interface{}, opts ...RouterOption)
- func (group *RouterGroup) Use(middlewares ...middleware.Middleware) *RouterGroup
- type RouterList
- type RouterOption
- type RouterOptions
- type RouterWrapper
- type RunStatus
- type Status
Constants ¶
const ( StatusStart = "start" StatusStop = "stop" )
const (
ContentTypeName = constants.ContentTypeName
)
const SupportPackageIsVersion1 = true
SupportPackageIsVersion1 These constants should not be referenced from any other code.
Variables ¶
This section is empty.
Functions ¶
func CodecForRequest ¶
CodecForRequest get encoding.Codec via http.Request
func DefaultErrorEncoder ¶
DefaultErrorEncoder encodes the error to the HTTP response.
func DefaultRequestDecoder ¶
DefaultRequestDecoder decodes the request body to object.
func DefaultResponseEncoder ¶
DefaultResponseEncoder encodes the object to the HTTP response.
func RegistryEngineRoute ¶
func RegistryEngineRoute(engine AdapterEngine, router *RouterGroup)
Types ¶
type AdapterEngine ¶
type DataEncoder ¶
type DecodeRequestFunc ¶
DecodeRequestFunc is decode request func.
type EncodeErrorFunc ¶
EncodeErrorFunc is encode error func.
type EncodeResponseFunc ¶
EncodeResponseFunc is encode response func.
type HandlerFunc ¶
type HttpEngine ¶
type LogContext ¶
type Method ¶
type Method string
func (Method) Apply ¶ added in v0.5.8
func (m Method) Apply(opts *RouterOptions)
type NormalRouterOption ¶ added in v0.5.8
type NormalRouterOption struct {
// contains filtered or unexported fields
}
func (*NormalRouterOption) Apply ¶ added in v0.5.8
func (o *NormalRouterOption) Apply(opts *RouterOptions)
type Option ¶
type Option func(*Options)
func WithConfig ¶
func WithErrorEncoder ¶
func WithErrorEncoder(errorEncoder EncodeErrorFunc) Option
func WithLogOptions ¶
func WithRequestDecoder ¶
func WithRequestDecoder(requestDecoder DecodeRequestFunc) Option
func WithResponseEncoder ¶
func WithResponseEncoder(responseEncoder EncodeResponseFunc) Option
func WithSrvName ¶
func WithSrvType ¶
type Options ¶
type Options struct { SrvType string SrvName string RequestDecoder DecodeRequestFunc ResponseEncoder EncodeResponseFunc ErrorEncoder EncodeErrorFunc LogOpts *log.Options Config config.Config }
func DefaultOptions ¶
func DefaultOptions() *Options
type ResponseEntity ¶ added in v0.4.10
type ResponseWriter ¶
type ResponseWriter interface { Status() int Size() int Written() bool WriteHeader(code int) Header() xtypes.SMap Write(p []byte) (n int, err error) WriteString(string) (int, error) Flush() error }
ResponseWriter ...
type RouterGroup ¶
type RouterGroup struct { ServiceGroups map[string]*RouterWrapper Children map[string]*RouterGroup // contains filtered or unexported fields }
func NewRouterGroup ¶
func NewRouterGroup(basePath string) *RouterGroup
func (*RouterGroup) BasePath ¶
func (group *RouterGroup) BasePath() string
BasePath returns the base path of router group. For example, if v := router.Group("/rest/n/v1/api"), v.BasePath() is "/rest/n/v1/api".
func (*RouterGroup) GetTreePathList ¶ added in v0.5.11
func (group *RouterGroup) GetTreePathList() []string
func (*RouterGroup) Group ¶
func (group *RouterGroup) Group(relativePath string, middlewares ...middleware.Middleware) *RouterGroup
Group creates a new router group. You should add all the routes that have common middlewares or the same path prefix. For example, all the routes that use a common middleware for authorization could be grouped.
func (*RouterGroup) Handle ¶
func (group *RouterGroup) Handle(relativePath string, handler interface{}, opts ...RouterOption)
Handle registers a new request handle and middleware with the given path and method. The last handler should be the real handler, the other ones should be middleware that can and should be shared among different routes. See the example code in GitHub.
For GET, POST requests the respective shortcut functions can be used.
This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for internal communication with a proxy).
func (*RouterGroup) Use ¶
func (group *RouterGroup) Use(middlewares ...middleware.Middleware) *RouterGroup
Use adds middleware to the group, see example code in GitHub.
type RouterList ¶ added in v0.5.14
type RouterList struct { ServerType string `json:"server_type" yaml:"server_type"` PathList []string `json:"path_list" yaml:"path_list"` }
func (RouterList) GetPathList ¶ added in v0.5.14
func (r RouterList) GetPathList() []string
func (RouterList) GetType ¶ added in v0.5.14
func (r RouterList) GetType() string
type RouterOption ¶ added in v0.5.7
type RouterOption interface {
Apply(*RouterOptions)
}
func WithExcludeLogReq ¶ added in v0.5.8
func WithExcludeLogReq() RouterOption
func WithExcludeLogResp ¶ added in v0.5.8
func WithExcludeLogResp() RouterOption
func WithMethod ¶ added in v0.5.7
func WithMethod(method ...string) RouterOption
func WithPrintHeaders ¶ added in v0.5.22
func WithPrintHeaders(keys ...constants.HeaderGetter) RouterOption
func WithPrintSource ¶ added in v0.5.22
func WithPrintSource(include bool) RouterOption