router

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 10 Imported by: 46

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_pb_router_entry_proto protoreflect.FileDescriptor

Functions

func GetHandlerFuncName

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

GetHandlerFuncName 通过反射获取函数名称

Types

type Auther

type Auther interface {
	Auth(req *http.Request, entry 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 Entry

type Entry struct {
	Path             string            `protobuf:"bytes,1,opt,name=path,proto3" json:"path" bson:"path"`
	Method           string            `protobuf:"bytes,2,opt,name=method,proto3" json:"method" bson:"method"`
	GrpcPath         string            `protobuf:"bytes,3,opt,name=grpc_path,json=grpcPath,proto3" json:"grpc_path" bson:"grpc_path"`
	FunctionName     string            `protobuf:"bytes,4,opt,name=function_name,json=functionName,proto3" json:"function_name" bson:"function_name"`
	Resource         string            `protobuf:"bytes,5,opt,name=resource,proto3" json:"resource" bson:"resource"`
	AuthEnable       bool              `protobuf:"varint,6,opt,name=auth_enable,json=authEnable,proto3" json:"auth_enable" bson:"auth_enable"`
	PermissionEnable bool              `protobuf:"varint,7,opt,name=permission_enable,json=permissionEnable,proto3" json:"permission_enable" bson:"permission_enable"`
	Labels           map[string]string `` /* 157-byte string literal not displayed */
	// contains filtered or unexported fields
}

Entry 路由条目

func NewEntry added in v0.3.7

func NewEntry(path, method, resource string) *Entry

NewEntry 行健条目

func (*Entry) AddLabel added in v0.1.4

func (e *Entry) AddLabel(labels ...*Label) EntryDecorator

AddLabel 添加Label

func (*Entry) Descriptor deprecated added in v0.6.8

func (*Entry) Descriptor() ([]byte, []int)

Deprecated: Use Entry.ProtoReflect.Descriptor instead.

func (*Entry) DisableAuth added in v0.2.1

func (e *Entry) DisableAuth() EntryDecorator

DisableAuth 不启用身份验证

func (*Entry) DisablePermission added in v0.2.1

func (e *Entry) DisablePermission() EntryDecorator

DisablePermission 禁用授权验证

func (*Entry) EnableAuth added in v0.2.1

func (e *Entry) EnableAuth() EntryDecorator

EnableAuth 启动身份验证

func (*Entry) EnablePermission added in v0.2.1

func (e *Entry) EnablePermission() EntryDecorator

EnablePermission 启用授权验证

func (*Entry) GetAuthEnable added in v0.6.8

func (x *Entry) GetAuthEnable() bool

func (*Entry) GetFunctionName added in v0.6.8

func (x *Entry) GetFunctionName() string

func (*Entry) GetGrpcPath added in v0.7.1

func (x *Entry) GetGrpcPath() string

func (*Entry) GetLabels added in v0.6.8

func (x *Entry) GetLabels() map[string]string

func (*Entry) GetLableValue added in v0.4.0

func (e *Entry) GetLableValue(key string) string

GetLableValue 获取Lable的值

func (*Entry) GetMethod added in v0.6.8

func (x *Entry) GetMethod() string

func (*Entry) GetPath added in v0.6.8

func (x *Entry) GetPath() string

func (*Entry) GetPermissionEnable added in v0.6.8

func (x *Entry) GetPermissionEnable() bool

func (*Entry) GetResource added in v0.6.8

func (x *Entry) GetResource() string

func (*Entry) ProtoMessage added in v0.6.8

func (*Entry) ProtoMessage()

func (*Entry) ProtoReflect added in v0.6.8

func (x *Entry) ProtoReflect() protoreflect.Message

func (*Entry) Reset added in v0.6.8

func (x *Entry) Reset()

func (*Entry) String added in v0.3.7

func (x *Entry) String() string

func (*Entry) WithGrpcPath added in v0.7.1

func (e *Entry) WithGrpcPath(path string) EntryDecorator

WithGrpcPath todo

type EntryDecorator added in v0.1.4

type EntryDecorator interface {
	// SetLabel 设置子路由标签, 作用于Entry上
	AddLabel(...*Label) EntryDecorator
	EnableAuth() EntryDecorator
	DisableAuth() EntryDecorator
	EnablePermission() EntryDecorator
	DisablePermission() EntryDecorator
}

EntryDecorator 装饰

type EntrySet added in v0.1.2

type EntrySet struct {
	Items []*Entry `json:"items"`
}

EntrySet 路由条目集

func NewEntrySet added in v0.1.2

func NewEntrySet() *EntrySet

NewEntrySet 实例

func (*EntrySet) AddEntry added in v0.1.2

func (s *EntrySet) AddEntry(es ...Entry)

AddEntry 添加Entry

func (*EntrySet) GetEntry added in v0.1.2

func (s *EntrySet) GetEntry(path, mothod string) *Entry

GetEntry 获取条目

func (*EntrySet) String added in v0.3.7

func (s *EntrySet) String() string

type Label

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

Label 路由标签

func NewLable

func NewLable(k, v string) *Label

NewLable label实例

func (*Label) Key

func (l *Label) Key() string

Key 健

func (*Label) Value

func (l *Label) Value() string

Value 值

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)

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

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

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

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

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

	// 设置路由的Logger, 用于Debug
	SetLogger(logger.Logger)
	// SetLabel 设置路由标签, 作用于Entry上
	SetLabel(...*Label)

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

Router 路由

type SubRouter

type SubRouter interface {
	// 是否启用用户身份验证
	Auth(isEnable bool)
	// 是否启用用户权限验证
	Permission(isEnable bool)
	// 添加中间件
	Use(m Middleware)
	// SetLabel 设置路由标签, 作用于Entry上
	SetLabel(...*Label)
	// With独立作用于某一个Handler
	With(m ...Middleware) SubRouter
	// 添加受认证保护的路由
	Handle(method, path string, h http.HandlerFunc) EntryDecorator
	// ResourceRouter 资源路由器, 主要用于设置路由标签和资源名称,方便配置灵活的权限策略
	ResourceRouter(resourceName string, labels ...*Label) ResourceRouter
}

SubRouter 子路由或者分组路由

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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