route

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() services.RouteService

Types

type Service

type Service struct {
	*gin.Engine
	// contains filtered or unexported fields
}

Service 路由服务主结构体

func (*Service) Any

func (s *Service) Any(relativePath string, handlers ...services.Handler) services.IRoutes

Any 注册一个匹配所有HTTP方法的路由。 GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE.

func (*Service) DELETE

func (s *Service) DELETE(relativePath string, handlers ...services.Handler) services.IRoutes

DELETE 是 route.Handle("DELETE", path, handlers) 的短语形式.

func (*Service) Delims

func (s *Service) Delims(left, right string) services.RouteService

Delims 设置模板的左右界限, 并返回一个引擎实例.

func (*Service) GET

func (s *Service) GET(relativePath string, handlers ...services.Handler) services.IRoutes

GET 是 route.Handle("GET", path, handlers) 的短语形式.

func (*Service) Group

func (s *Service) Group(relativePath string, handlers ...services.Handler) services.IRouter

Group 创建一个新的路由器组, 您应该添加所有具有公共中间件或相同路径前缀的路由. 例如, 所有使用公共中间件进行授权的路由都可以分组.

func (*Service) HEAD

func (s *Service) HEAD(relativePath string, handlers ...services.Handler) services.IRoutes

HEAD 是 route.Handle("HEAD", path, handlers) 的短语形式.

func (*Service) Handle

func (s *Service) Handle(httpMethod, relativePath string, handlers ...services.Handler) services.IRoutes

Handle 用给定的路径和方法注册一个新的请求句柄和中间件. 最后一个处理程序应该是真正的处理程序, 其他的应该是中间件, 可以并且应该在不同的路由之间共享. 参见GitHub中的示例代码.

对于 GET, POST, PUT, PATCH 和 DELETE 请求各自的快捷方式可以使用函数.

此功能用于批量加载, 并允许使用不常用的、非标准化的或自定义的方法(例如, 用于内部与代理的通信).

func (*Service) Init

func (s *Service) Init(args ...services.Service) services.Service

Init 初始化

func (*Service) LoadHTMLFS

func (s *Service) LoadHTMLFS(fs fs.FS, patterns ...string)

LoadHTMLFS 从嵌入文件加载模板

func (*Service) LoadHTMLGlobs

func (s *Service) LoadHTMLGlobs(patterns ...string) error

LoadHTMLGlobs 加载多层目录结构的模板

func (*Service) Match

func (s *Service) Match(methods []string, relativePath string, handlers ...services.Handler) services.IRoutes

Match 注册与您声明的指定方法匹配的路由.

func (*Service) NoMethod

func (s *Service) NoMethod(handlers ...services.Handler)

NoMethod 不允许方法

func (*Service) NoRoute

func (s *Service) NoRoute(handlers ...services.Handler)

NoRoute 找不到路由

func (*Service) OPTIONS

func (s *Service) OPTIONS(relativePath string, handlers ...services.Handler) services.IRoutes

OPTIONS 是 route.Handle("OPTIONS", path, handlers) 的短语形式.

func (*Service) PATCH

func (s *Service) PATCH(relativePath string, handlers ...services.Handler) services.IRoutes

PATCH 是 route.Handle("PATCH", path, handlers) 的短语形式.

func (*Service) POST

func (s *Service) POST(relativePath string, handlers ...services.Handler) services.IRoutes

POST 是 route.Handle("POST", path, handlers) 的短语形式.

func (*Service) PUT

func (s *Service) PUT(relativePath string, handlers ...services.Handler) services.IRoutes

PUT 是 route.Handle("PUT", path, handlers) 的短语形式.

func (*Service) SecureJsonPrefix

func (s *Service) SecureJsonPrefix(prefix string) services.RouteService

SecureJsonPrefix 设置Context.SecureJSON中使用的SecureJsonPrefix.

func (*Service) Static

func (s *Service) Static(relativePath, root string) services.IRoutes

Static 方法从给定的文件系统根目录中提供文件服务. 它内部使用了 http.FileServer, 因此使用了 http.NotFound 而不是路由器的 NotFound 处理程序. 如果要使用操作系统的文件系统实现,请使用以下方法 router.Static("/static", "/var/www")

其中, 第一个参数是 URL 的前缀,第二个参数是文件系统根目录的路径. 这将把以 /static 开头的 URL 映射到 /var/www 目录下的文件系统.

func (*Service) StaticFS

func (s *Service) StaticFS(relativePath string, fs http.FileSystem) services.IRoutes

StaticFS 方法与 Static() 类似, 但是可以使用自定义的 http.FileSystem. 默认情况下, Gin 使用 gin.Dir().

func (*Service) StaticFile

func (s *Service) StaticFile(relativePath, filepath string) services.IRoutes

StaticFile 注册一个路由, 以便为本地文件系统的一个文件服务. router.StaticFile("favicon.ico", "./resources/favicon.ico")

func (*Service) StaticFileFS

func (s *Service) StaticFileFS(relativePath, filepath string, fs http.FileSystem) services.IRoutes

StaticFileFS 与 StaticFile 类似, 但可以使用自定义的 http.FileSystem. router.StaticFileFS("favicon.ico", "./resources/favicon.ico", Dir{".", false}) Gin 默认使用: gin.Dir()

func (*Service) Use

func (s *Service) Use(middleware ...services.Handler) services.RouteService

Use 将中间件添加到组中, 参见GitHub中的示例代码.

func (*Service) UseBefore

func (s *Service) UseBefore(middleware ...services.Handler) services.RouteService

UseBefore 将中间件前插进组中

Jump to

Keyboard shortcuts

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