magicengine

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 19 Imported by: 2

README

magicEngine

http framework

Documentation

Index

Constants

View Source
const (
	Dev  string = "development"
	Prod string = "production"
	Test string = "test"
)

Envs

View Source
const (
	GET     = "GET"
	POST    = "POST"
	PUT     = "PUT"
	DELETE  = "DELETE"
	OPTIONS = "OPTIONS"
)

基本HTTP行为定义

View Source
const (
	DynamicTag   = "X-ENGINE-DYNAMIC-TAG"
	DynamicValue = "X-ENGINE-DYNAMIC-VALUE"
)

Variables

View Source
var Env = Dev
View Source
var Root string

Functions

func EnableTrace added in v1.3.2

func EnableTrace() bool

func GetElapseThreshold added in v1.3.2

func GetElapseThreshold() time.Duration

func InvokeMiddleWareHandler

func InvokeMiddleWareHandler(handler interface{}, ctx RequestContext, res http.ResponseWriter, req *http.Request)

InvokeMiddleWareHandler 执行MiddleWareHandle

func InvokeRouteHandler

func InvokeRouteHandler(handler interface{}, ctx context.Context, res http.ResponseWriter, req *http.Request)

InvokeRouteHandler 执行RouteHandle

func ValidateMiddleWareHandler

func ValidateMiddleWareHandler(handler interface{})

ValidateMiddleWareHandler 校验MiddleWareHandler

func ValidateRouteHandler

func ValidateRouteHandler(handler interface{})

ValidateRouteHandler 校验RouteHandler

Types

type HTTPServer

type HTTPServer interface {
	Use(handler MiddleWareHandler)
	Bind(router Router)
	Run()
}

HTTPServer HTTPServer

func NewHTTPServer

func NewHTTPServer(bindPort string) HTTPServer

NewHTTPServer 新建HTTPServer

type MiddleWareChains

type MiddleWareChains interface {
	Append(handler MiddleWareHandler)

	GetHandlers() []MiddleWareHandler
}

MiddleWareChains 处理器链

func NewMiddleWareChains

func NewMiddleWareChains() MiddleWareChains

NewMiddleWareChains 新建MiddleWareChains

type MiddleWareHandler

type MiddleWareHandler interface {
	Handle(ctx RequestContext, res http.ResponseWriter, req *http.Request)
}

MiddleWareHandler 中间件处理器

type PatternFilter

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

PatternFilter route filter

func NewPatternFilter

func NewPatternFilter(routePattern string) *PatternFilter

NewPatternFilter new route filter

func (*PatternFilter) Match

func (s *PatternFilter) Match(path string) bool

Match match path

type RequestContext

type RequestContext interface {
	Update(ctx context.Context)
	Context() context.Context
	Next()
	Written() bool
	Run()
}

func NewRequestContext

func NewRequestContext(filters []MiddleWareHandler, router Router, ctx context.Context, res http.ResponseWriter, req *http.Request) RequestContext

NewRequestContext 新建Context

func NewRouteContext

func NewRouteContext(reqCtx context.Context, filters []MiddleWareHandler, route Route, res http.ResponseWriter, req *http.Request) RequestContext

NewRouteContext 新建Context

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	Status() int
	Written() bool
	Size() int
}

func NewResponseWriter

func NewResponseWriter(rw http.ResponseWriter) ResponseWriter

type Route

type Route interface {
	// Method 路由行为GET/PUT/POST/DELETE
	Method() string
	// Pattern 路由规则, 以'/'开始
	Pattern() string
	// Handler 路由处理器
	Handler() func(context.Context, http.ResponseWriter, *http.Request)
}

Route 路由接口

func CreateProxyRoute

func CreateProxyRoute(pattern, method, reallyURL string, rewriteURL bool) Route

CreateProxyRoute create proxy route

func CreateRedirectRoute

func CreateRedirectRoute(pattern, method, redirectPattern string) Route

func CreateRoute

func CreateRoute(pattern, method string, handler func(context.Context, http.ResponseWriter, *http.Request)) Route

CreateRoute create Route

type Router

type Router interface {
	// SetApiVersion 设置ApiVersion
	SetApiVersion(version string)
	// GetApiVersion 查询ApiVersion
	GetApiVersion() string
	// AddRoute 增加路由
	AddRoute(rt Route, filters ...MiddleWareHandler)
	// RemoveRoute 清除路由
	RemoveRoute(rt Route)
	// Handle 分发一条请求
	Handle(ctx context.Context, res http.ResponseWriter, req *http.Request)
}

Router 路由器对象

func NewRouter

func NewRouter() Router

NewRouter 新建Router

type StaticOptions

type StaticOptions struct {
	Path string
	// Prefix is the optional prefix used to serve the static directory content
	Prefix string
	// SkipLogging will disable [Static] log messages when a static file is served.
	SkipLogging bool
	// IndexFile defines which file to serve as index if it exists.
	IndexFile string
	// Expires defines which user-defined function to use for producing a HTTP Expires Header
	// https://developers.google.com/speed/docs/insights/LeverageBrowserCaching
	Expires func() string
	// Fallback defines a default URL to serve when the requested resource was
	// not found.
	Fallback string
	// Exclude defines a pattern for URLs this handler should never process.
	Exclude string
}

StaticOptions is a struct for specifying configuration options for the martini.Static middleware.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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