middleware

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package middleware 自定义 api 中间键包,提供常用业务场景中会使用到的一些中间键封装 某些自定义功能可能会需要几个中间键组合在一起才能生效

Index

Constants

View Source
const WrapperDefaultKey = "default"

WrapperDefaultKey 默认的wrapper 名称

Variables

This section is empty.

Functions

func CORS

func CORS() gin.HandlerFunc

CORS 赋予接口能被浏览器跨域调用的中间键

func HTTPBasicAuth

func HTTPBasicAuth(verifyFunc HTTPBasicAuthVerifyFunc) gin.HandlerFunc

HTTPBasicAuth 参考 rfc7235和rfc2617 实现接口http Basic 认证的中间键 需要传入一个认证函数来实现函数的认证 这个中间键应该放在渲染中间键之后

func Logger added in v0.5.3

func Logger() gin.HandlerFunc

func OptionsOK

func OptionsOK() gin.HandlerFunc

OptionsOK 将options 请求返回为成功

func PermissionCheck

func PermissionCheck(permission interface{}, checkpoints ...CheckPermitFunc) gin.HandlerFunc

PermissionCheck 检查权限的中间键,可以提供多个checkpoints 函数进行权限检查,任意一个检查点未通过都会直接返回403,checkpoint 中的Context是独立的,不会影响实际的request context ,checkpoints 间的context 是共享的

func Session

func Session(name string, handler xsession.Handler) gin.HandlerFunc

Session middleware handle session issue

func SessionUserAuth

func SessionUserAuth(userKey string) gin.HandlerFunc

SessionUserAuth Get a Session User auth middleware , this should after Session middleware userKey is the key save user data

func SimpleJSONWrapper

func SimpleJSONWrapper() gin.HandlerFunc

SimpleJSONWrapper get a simple json wrapper middware

func SimpleJWTAuth

func SimpleJWTAuth(configFunc JWTAuthConfigFunc) gin.HandlerFunc

SimpleJWTAuth 实现接口基于JWT 的 http Bearer 认证的中间键,参考 rfc6750 和rfc7519 如果认证成功 会在context Set token 为后续操作服务

func WrapAPI

func WrapAPI(wrappers Wrappers) gin.HandlerFunc

WrapAPI api及中间键逻辑完成之后进行统一的header 和content 设定的中间键 使用这个中间键的时候要注意它的执行位置,最好放在所有接口逻辑之前

func XinRESTfulWrap

func XinRESTfulWrap(env xin.Envirment) gin.HandlerFunc

XinRESTfulWrap create a WrapAPI middleware with XinRESTfulWrapper as default wrapper

func XinRESTfulWrapper

func XinRESTfulWrapper(env xin.Envirment) gin.HandlerFunc

XinRESTfulWrapper get a xin restful wrapper middware httpstatus = apiStatus%1000 For example if api status is set to 1404 then api http status will be set to 404

Types

type CheckPermitFunc

type CheckPermitFunc func(c *gin.Context, permission interface{}) (pass bool, user interface{}, err error)

CheckPermitFunc 给定一个 context 和一个api 名称,获取request 来源是否有权限访问api 注意,不应该在这个函数中修改 c 的内容, 不会影响主逻辑后和其他中间键的context

type HTTPBasicAuthVerifyFunc

type HTTPBasicAuthVerifyFunc func(string, string) (pass bool, user interface{})

HTTPBasicAuthVerifyFunc 传入函数的第一个参数是用户名,第二个参数名是密码, 第二个返回参数是用户,会被设置在全局变量中

type JWTAuthConfig

type JWTAuthConfig struct {
	Keyfunc jwt.Keyfunc
	Options []jwt_request.ParseFromRequestOption
}

JWTAuthConfig JWT授权验证的配置结构体

type JWTAuthConfigFunc

type JWTAuthConfigFunc func() *JWTAuthConfig

JWTAuthConfigFunc 提供JWT 验证配置的函数,这个主要为了保证验证的线程安全

type Wrappers

type Wrappers map[string]gin.HandlerFunc

Wrappers api 包装的逻辑map

func NewWrappers

func NewWrappers() Wrappers

NewWrappers 创建一个带有default 的wrappers

func (Wrappers) SetDefault

func (w Wrappers) SetDefault(wrapper gin.HandlerFunc) Wrappers

SetDefault 设置默认的包装逻辑

type XinRESTfulResponse

type XinRESTfulResponse struct {
	Status int    `json:"status"`
	ErrMsg string `json:"err_msg,omitempty"`
}

XinRESTfulResponse restful response struct

Jump to

Keyboard shortcuts

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