mgateway

package
v0.0.0-...-57fd995 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir(root string, listDirectory bool) http.FileSystem

Dir returns a http.Filesystem that can be used by http.FileServer(). It is used internally in router.Static(). if listDirectory == true, then it works the same as http.Dir() otherwise it returns a filesystem that prevents http.FileServer() to list the directory files.

Types

type Context

type Context struct {
	Writer  responseWriter
	Request *http.Request

	PathParams map[string]string

	Path   string
	Method string

	StatusCode int
	// contains filtered or unexported fields
}

Context gateway 自定义路由上下文解析

func (*Context) Abort

func (c *Context) Abort()

func (*Context) AbortWithStatus

func (c *Context) AbortWithStatus(code int)

AbortWithStatus 调用 Abort 并返回指定状态码

func (*Context) Deadline

func (c *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Done

func (c *Context) Done() <-chan struct{}

func (*Context) Err

func (c *Context) Err() error

func (*Context) File

func (c *Context) File(filepath string)

File 启动一个文件服务

func (*Context) FileFromFS

func (c *Context) FileFromFS(filepath string, fs http.FileSystem)

FileFromFS 通过 http.FileSystem 启动一个文件流服务 filepath: 路径参数名, 从请求路径中获取到filepath的地址信息,将信息当作路由

func (*Context) Header

func (c *Context) Header(key, value string)

Header 设置返回的请求头信息, 如果value == "" 将删除对应的key值

func (*Context) IsAborted

func (c *Context) IsAborted() bool

func (*Context) JSON

func (c *Context) JSON(code int, obj any)

JSON 返回json格式数据信息

func (*Context) Next

func (c *Context) Next()

Next 中间件信息修复

func (*Context) Render

func (c *Context) Render(code int, r render.Render)

func (*Context) Status

func (c *Context) Status(code int)

Status 设置 http 返回的状态值

func (*Context) Value

func (c *Context) Value(key any) any

type Error

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

func (*Error) Code

func (e *Error) Code() int

func (*Error) Error

func (e *Error) Error() string

func (*Error) Msg

func (e *Error) Msg() string

type Gateway

type Gateway struct {
	RouterGroup
	// contains filtered or unexported fields
}

func New

func New(config GatewayConf, log logger.ILogger) *Gateway

New 启动gateway服务

func (*Gateway) Close

func (g *Gateway) Close(ctx context.Context) error

func (*Gateway) GetServerMux

func (g *Gateway) GetServerMux() *runtime.ServeMux

func (*Gateway) Run

func (g *Gateway) Run()

type GatewayConf

type GatewayConf struct {
	Port string
}

type H

type H map[string]interface{}

type HandlerFunc

type HandlerFunc func(ctx *Context)

type IRoutes

IRoutes 定义所有路由器句柄接口

type Response

type Response struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

type RouterGroup

type RouterGroup struct {

	// 路由中间件
	Handlers []HandlerFunc
	// contains filtered or unexported fields
}

RouterGroup 内部路由器配置

func (*RouterGroup) DELETE

func (r *RouterGroup) DELETE(path string, handler HandlerFunc) IRoutes

func (*RouterGroup) GET

func (r *RouterGroup) GET(path string, handler HandlerFunc) IRoutes

func (*RouterGroup) Group

func (r *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup

Group 路由分组

func (*RouterGroup) HEAD

func (r *RouterGroup) HEAD(path string, handler HandlerFunc) IRoutes

func (*RouterGroup) OPTIONS

func (r *RouterGroup) OPTIONS(path string, handler HandlerFunc) IRoutes

func (*RouterGroup) PATCH

func (r *RouterGroup) PATCH(path string, handler HandlerFunc) IRoutes

func (*RouterGroup) POST

func (r *RouterGroup) POST(path string, handler HandlerFunc) IRoutes

func (*RouterGroup) PUT

func (r *RouterGroup) PUT(path string, handler HandlerFunc) IRoutes

func (*RouterGroup) StaticFile

func (r *RouterGroup) StaticFile(relativePath, filepath string) IRoutes

func (*RouterGroup) StaticFileFS

func (r *RouterGroup) StaticFileFS(relativePath, filepath string, fs http.FileSystem) IRoutes

func (*RouterGroup) Use

func (r *RouterGroup) Use(middleware ...HandlerFunc) IRoutes

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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