leego

package module
v0.0.0-...-4d7864a Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DynamicRouteKey = ":*"

动态路由的节点的key

View Source
const Version = "0.0.1.0"

Variables

View Source
var (
	GowayTracer = http.CanonicalHeaderKey("Goway-Tracer")
	GowayServer = http.CanonicalHeaderKey("Goway-Server")
)

Functions

func GetLittleFileSize

func GetLittleFileSize() int64

func GetMaxRequestBodySize

func GetMaxRequestBodySize() int64

func SetLittleFileSize

func SetLittleFileSize(size int64)

func SetMaxRequestBodySize

func SetMaxRequestBodySize(size int64)

Types

type Accounts

type Accounts map[string]string

type Context

type Context struct {
	// 请求信息
	Path    string            // 请求路由
	Method  string            // 请求方法
	Headers http.Header       // 请求头
	Params  map[string]string // 路由参数

	// 响应信息
	StatusCode int // 响应状态码
	// contains filtered or unexported fields
}

Context 定义请求响应上下文

func (*Context) GetBasicAuth

func (own *Context) GetBasicAuth() (username, password string)

GetBasicAuth 获取基本认证的账号密码

func (*Context) GetBytesBody

func (own *Context) GetBytesBody() ([]byte, error)

GetBytesBody 获取bytes格式请求体

func (*Context) GetFormValue

func (own *Context) GetFormValue(key string) string

GetFormParam 获取表单参数

func (*Context) GetGowayServer

func (own *Context) GetGowayServer() (env, appId, appVer, instanceId string)

GetGowayServer 尝试获取 Goway 网关的代理数据:env, app id, app ver, instance id

func (*Context) GetGowayTracer

func (own *Context) GetGowayTracer() (tid, sid string)

GetGowayTracer 尝试获取 Goway 网关中的的链路 ID:trace id 和 span id

func (*Context) GetJsonBody

func (own *Context) GetJsonBody(model any) error

GetJsonBody 获取json格式请求体

func (*Context) GetRequest

func (own *Context) GetRequest() *http.Request

func (*Context) GetResponse

func (own *Context) GetResponse() http.ResponseWriter

func (*Context) GetStringBody

func (own *Context) GetStringBody() (string, error)

GetJsonBody 获取string格式请求体

func (*Context) GetUrlParam

func (own *Context) GetUrlParam(key string) string

GetUrlParam 获取动态路由参数

func (*Context) RequestByGoway

func (own *Context) RequestByGoway(method, url string, headers map[string]string, optGoway OptionGoway, body io.Reader) (*http.Response, error)

RequestByGoway 尝试通过 Goway 网关发起请求

func (*Context) ResponseBytes

func (own *Context) ResponseBytes(code int, data []byte)

ResponseBytes 响应字节数组

func (*Context) ResponseError

func (own *Context) ResponseError(code int, error string)

ResponseFail 响应错误信息

func (*Context) ResponseError400

func (own *Context) ResponseError400(error any)

ResponseError401 响应400

func (*Context) ResponseError401

func (own *Context) ResponseError401()

ResponseError401 响应401

func (*Context) ResponseError404

func (own *Context) ResponseError404()

ResponseError404 响应404

func (*Context) ResponseError500

func (own *Context) ResponseError500(error any)

ResponseError500 响应500

func (*Context) ResponseFile

func (own *Context) ResponseFile(code int, filepath, filename string)

ResponseFile 响应单个文件

func (*Context) ResponseHtml

func (own *Context) ResponseHtml(code int, filename string, data any)

ResponseHtml 响应单个HTML文件

func (*Context) ResponseHtmlString

func (own *Context) ResponseHtmlString(code int, text string, data any)

ResponseHtmlString 响应HTML字符串

func (*Context) ResponseJson

func (own *Context) ResponseJson(code int, data any)

ResponseJson 响应Json格式数据

func (*Context) ResponseString

func (own *Context) ResponseString(code int, data string)

ResponseString 响应字符串

func (*Context) RunNext

func (own *Context) RunNext()

RunNext 执行下一个中间件

func (*Context) SetHeader

func (own *Context) SetHeader(key string, value string)

func (*Context) SetHeaders

func (own *Context) SetHeaders(headers map[string]string)

func (*Context) SetStatusCode

func (own *Context) SetStatusCode(code int)

SetStatusCode 设置响应状态码

type Engine

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

Engine 定义 HTTP/HTTPS 服务引擎的结构

func NewDefaultEngine

func NewDefaultEngine(addr string) *Engine

NewDefaultEngine 创建一个默认 HTTP/HTTPS 服务引擎,自带异常恢复和日志记录

func NewEngine

func NewEngine(addr string) *Engine

NewEngine 新建一个 HTTP/HTTPS 服务引擎

func (Engine) AddMiddlewares

func (own Engine) AddMiddlewares(middlewares ...Handler)

AddMiddlewares 添加中间件到当前路由组

func (Engine) CONNECT

func (own Engine) CONNECT(route string, handler Handler)

CONNECT 添加 CONNECT 请求路由到当前路由组

func (Engine) DELETE

func (own Engine) DELETE(route string, handler Handler)

DELETE 添加 DELETE 请求路由到当前路由组

func (Engine) GET

func (own Engine) GET(route string, handler Handler)

GET 添加 GET 请求路由到当前路由组

func (Engine) HEAD

func (own Engine) HEAD(route string, handler Handler)

HEAD 添加 HEAD 请求路由到当前路由组

func (*Engine) ListenAndServe

func (own *Engine) ListenAndServe()

ListenAndServe 运行 HTTP 服务器引擎

func (*Engine) ListenAndServeTLS

func (own *Engine) ListenAndServeTLS(cert, key string)

ListenAndServe 运行 HTTPS 服务器引擎

func (*Engine) LoadHTMLTemplates

func (engine *Engine) LoadHTMLTemplates(path string)

func (Engine) NewGroup

func (own Engine) NewGroup(prefix string) *group

NewGroup 在某个路由组下新建一个路由组

func (Engine) OPTIONS

func (own Engine) OPTIONS(route string, handler Handler)

OPTIONS 添加 OPTIONS 请求路由到当前路由组

func (Engine) PATCH

func (own Engine) PATCH(route string, handler Handler)

PATCH 添加 PATCH 请求路由到当前路由组

func (Engine) POST

func (own Engine) POST(route string, handler Handler)

POST 添加 POST 请求路由到当前路由组

func (Engine) PUT

func (own Engine) PUT(route string, handler Handler)

PUT 添加 PUT 请求路由到当前路由组

func (*Engine) ServeHTTP

func (own *Engine) ServeHTTP(resp http.ResponseWriter, req *http.Request)

ServeHTTP 实现 http.Hanlder 接口,处理所有的路由请求

func (*Engine) SetHTMLFuncs

func (engine *Engine) SetHTMLFuncs(funcs template.FuncMap)

func (Engine) SetStatic

func (own Engine) SetStatic(route string, root string)

SetStatic 设置静态文件服务

func (Engine) TRACE

func (own Engine) TRACE(route string, handler Handler)

TRACE 添加 TRACE 请求路由到当前路由组

type Handler

type Handler func(*Context)

func AllowCors

func AllowCors(c cors.CORS) Handler

AllowCors 返回一个跨域配置中间件

func BasicAuth

func BasicAuth(accounts Accounts) Handler

BasicAuth 返回一个 BasicAuth 鉴权中间件

func Log

func Log() Handler

Log 返回一个日志记录中间件

func Recovery

func Recovery() Handler

Recovery 返回一个异常恢复中间件

func Restrict

func Restrict(limt int) Handler

Restrict 返回一个简单限流中间件

type Json

type Json map[string]any

Json 定义简单的JSON数据格式

type OptionGoway

type OptionGoway struct {
	// 环境 (必选)
	Env string
	// 应用 ID (必选)
	AppId string
	// 应用版本 (可选)
	AppVer string
	// 实例 ID (可选)
	InstanceId string
}

Directories

Path Synopsis
global

Jump to

Keyboard shortcuts

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