engine

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodPost   = "POST"
	MethodGet    = "GET"
	MethodPut    = "PUT"
	MethodDelete = "DELETE"
)
View Source
const (
	StatusStart = "start"
	StatusStop  = "stop"
)
View Source
const SupportPackageIsVersion1 = true

SupportPackageIsVersion1 These constants should not be referenced from any other code.

Variables

This section is empty.

Functions

func CodecForRequest

func CodecForRequest(ctx context.Context, name string) (encoding.Codec, bool)

CodecForRequest get encoding.Codec via http.Request

func DefaultErrorEncoder

func DefaultErrorEncoder(ctx context.Context, err error)

DefaultErrorEncoder encodes the error to the HTTP response.

func DefaultRequestDecoder

func DefaultRequestDecoder(ctx context.Context, v interface{}) error

DefaultRequestDecoder decodes the request body to object.

func DefaultResponseEncoder

func DefaultResponseEncoder(ctx context.Context, v interface{}) error

DefaultResponseEncoder encodes the object to the HTTP response.

func Deregister

func Deregister(name string)

Deregister 清理配置适配器

func Register

func Register(resolver Resover)

Register 注册配置文件适配器

func RegistryEngineRoute

func RegistryEngineRoute(engine AdapterEngine, router *RouterGroup)

Types

type AdapterEngine

type AdapterEngine interface {
	NoMethod()
	NoRoute()
	Handle(method string, path string, callfunc HandlerFunc)
	Write(ctx context.Context, resp interface{})
	GetImpl() any
}

func NewEngine

func NewEngine(proto string, setting config.Config, opts ...Option) (AdapterEngine, error)

NewEngine 根据适配器名称及参数返回配置处理器

type DataEncoder

type DataEncoder interface {
	Render(ctx context.Context) error
}

type DecodeRequestFunc

type DecodeRequestFunc func(context.Context, interface{}) error

DecodeRequestFunc is decode request func.

type EncodeErrorFunc

type EncodeErrorFunc func(context.Context, error)

EncodeErrorFunc is encode error func.

type EncodeResponseFunc

type EncodeResponseFunc func(context.Context, interface{}) error

EncodeResponseFunc is encode response func.

type HandlerFunc

type HandlerFunc func(context.Context)
type Header xtypes.SMap

type Hook

type Hook func(ctx context.Context) error

type HttpEngine

type HttpEngine interface {
	ServeHTTP(http.ResponseWriter, *http.Request)
	StaticFile(string, string)
	Static(string, string)
}

type IChecker

type IChecker interface {
	Check() error
}

type LogContext

type LogContext interface {
	LogOptions() *log.Options
}

type Method

type Method string

type Option

type Option func(*Options)

func WithConfig

func WithConfig(cfg config.Config) Option

func WithErrorEncoder

func WithErrorEncoder(errorEncoder EncodeErrorFunc) Option

func WithLogOptions

func WithLogOptions(opt *log.Options) Option

func WithRequestDecoder

func WithRequestDecoder(requestDecoder DecodeRequestFunc) Option

func WithResponseEncoder

func WithResponseEncoder(responseEncoder EncodeResponseFunc) Option

func WithSrvName

func WithSrvName(name string) Option

func WithSrvType

func WithSrvType(srvType string) Option

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 Request

type Request interface {
	Context() context.Context
	WithContext(context.Context)
	GetName() string
	GetService() string
	GetMethod() string
	Params() map[string]string
	GetHeader() map[string]string
	Body() []byte
	GetRemoteAddr() string
}

type Resover

type Resover interface {
	Name() string
	Resolve(name string, config config.Config, opts ...Option) (AdapterEngine, error)
}

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]*router.Group
	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) 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{}, methods ...Method)

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 RunStatus

type RunStatus uint
const (
	Unstarted RunStatus = 1
	Pause     RunStatus = 2
	Running   RunStatus = 4
	Pending   RunStatus = 8
	Stoped    RunStatus = 16
)

type Status

type Status string

Jump to

Keyboard shortcuts

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