router

package
v1.9.15 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: MIT Imports: 7 Imported by: 46

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHandlerFuncName

func GetHandlerFuncName(h http.HandlerFunc, seps ...rune) string

GetHandlerFuncName 通过反射获取函数名称

Types

type Auditer added in v1.6.7

type Auditer interface {
	ResponseHook(http.ResponseWriter, *http.Request, httppb.Entry)
}

Auditer 用于审计

type Auther

type Auther interface {
	Auth(req *http.Request, entry httppb.Entry) (authInfo interface{}, err error)
}

Auther 设置受保护路由使用的认证器 Header 用于鉴定身份 Entry 用于鉴定权限

type AutherFunc

type AutherFunc func(http.Header) (authInfo interface{}, err error)

The AutherFunc type is an adapter to allow the use of ordinary functions as Auther handlers. If f is a function with the appropriate signature, AutherFunc(f) is a Handler that calls f.

func (AutherFunc) Auth

func (f AutherFunc) Auth(h http.Header) (authInfo interface{}, err error)

Auth calls auth.

type Middleware

type Middleware interface {
	Handler(http.Handler) http.Handler
}

Middleware 中间件的函数签名

type MiddlewareFunc

type MiddlewareFunc func(http.Handler) http.Handler

MiddlewareFunc is an adapter to allow the use of ordinary functions as Negroni handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f.

func (MiddlewareFunc) Handler

func (h MiddlewareFunc) Handler(next http.Handler) http.Handler

Handler wrappe for function

type ResourceRouter added in v0.1.2

type ResourceRouter interface {
	SubRouter
	// BasePath 设置资源路由的基础路径
	BasePath(path string)
}

ResourceRouter 资源路由

type Router

type Router interface {
	// 添加中间件
	Use(m Middleware)

	// 是否启用用户身份验证
	Auth(isEnable bool)

	// 是否启用用户权限验证
	Permission(isEnable bool)

	// 允许target标识
	Allow(targets ...fmt.Stringer)

	// 是否开启审计日志
	AuditLog(isEnable bool)

	// 是否需要NameSpace
	RequiredNamespace(isEnable bool)

	// 添加受认证保护的路由
	Handle(method, path string, h http.HandlerFunc) httppb.EntryDecorator

	// 开始认证时 使用的认证器
	SetAuther(Auther)

	// 开始审计器, 记录用户操作
	SetAuditer(Auditer)

	// 实现标准库路由
	ServeHTTP(http.ResponseWriter, *http.Request)

	// 获取当前的路由条目信息
	GetEndpoints() *httppb.EntrySet

	// EnableAPIRoot 将服务路由表通过路径/暴露出去
	EnableAPIRoot()

	// 设置路由的Logger, 用于Debug
	SetLogger(logger.Logger)

	// SetLabel 设置路由标签, 作用于Entry上
	SetLabel(...*httppb.Label)

	// 子路由
	SubRouter(basePath string) SubRouter
}

Router 路由

type SubRouter

type SubRouter interface {
	// 是否启用用户身份验证
	Auth(isEnable bool)

	// 是否启用用户权限验证
	Permission(isEnable bool)

	// 允许target标识
	Allow(targets ...fmt.Stringer)

	// 是否开启审计日志
	AuditLog(isEnable bool)

	// 是否需要NameSpace
	RequiredNamespace(isEnable bool)

	// 添加中间件
	Use(m Middleware)

	// SetLabel 设置路由标签, 作用于Entry上
	SetLabel(...*httppb.Label)

	// With独立作用于某一个Handler
	With(m ...Middleware) SubRouter

	// 添加受认证保护的路由
	Handle(method, path string, h http.HandlerFunc) httppb.EntryDecorator

	// ResourceRouter 资源路由器, 主要用于设置路由标签和资源名称,方便配置灵活的权限策略
	ResourceRouter(resourceName string, labels ...*httppb.Label) ResourceRouter
}

SubRouter 子路由或者分组路由

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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