v0.0.0-...-0cb7091 Latest Latest

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

Go to latest
Published: Mar 6, 2021 License: BSD-3-Clause-Clear Imports: 23 Imported by: 1




View Source
const (
	DEF_UNIT_MSIZE       = 10
	DEF_CLAIMS_HEAD_KEY  = "claims"         // request head 中 jwt_claims 字段
	DEF_REQUEST_TIMEOVER = time.Second * 10 // 等待回应的请求超时时间


View Source
var (
	TokenExpired      error   = errors.New("Token is expired")
	TokenNotValidYet  error   = errors.New("Token not active yet")
	TokenMalformed    error   = errors.New("That's not even a token")
	TokenInvalid      error   = errors.New("Token is invalid")
	AuthNameExisted   error   = errors.New("Jwt auth unit already exists")
	RequestExpireTime float64 = 3000



func CurrGHead

func CurrGHead(ctx context.Context, key string) string

for grpc head

func CurrentUId

func CurrentUId(c *gin.Context) int64

------------------------------------------------------------------------------ ===================================User Auth==================================== ------------------------------------------------------------------------------ CurrentUser 获取用户Id

func Init

func Init(mode string, transJwtTokenForGrpc ...bool)


func InitJwtAuth

func InitJwtAuth(name string, cust ICustClaimer, signKey string) error

-------- JWT认证中间件

func InstallExt

func InstallExt(ctrlName string, mc IMCGeter, conf *Config)


func JWT

func JWT(key []byte) *_jwt

------------------------------------------------------------------------------ ==================================JWT签名工具结构================================= ------------------------------------------------------------------------------

func MH_Cors

func MH_Cors(allowOrigins ...string) gin.HandlerFunc

Cors 跨域配置1

func MH_Corss

func MH_Corss() gin.HandlerFunc

Cors 跨域配置2 by gin-contrib.cors

func MH_CurrentUser

func MH_CurrentUser() gin.HandlerFunc

MH_CurrentUser 获取登录用户

func MH_Heavier

func MH_Heavier(level time.Duration) gin.HandlerFunc

MH_Heavier 代码耗时错误记录

func MH_JWTAuthed

func MH_JWTAuthed(name string) gin.HandlerFunc

func MH_SESAuthed

func MH_SESAuthed() gin.HandlerFunc

-------- Session认证中间件

func MH_Session

func MH_Session(secret string) gin.HandlerFunc

Session 初始化session

func PreUnregist

func PreUnregist(name string) error

Preregist 卸载API

func Service

func Service(c *gin.Context, s IService)

func ServiceHtml

func ServiceHtml(c *gin.Context, name string, s IService)

func ServiceStr

func ServiceStr(c *gin.Context, s IService)

func ServiceXml

func ServiceXml(c *gin.Context, s IService)

func Sessions

func Sessions(c *gin.Context) sessions.Session

func TranGHead

func TranGHead(ctx context.Context, c *gin.Context, keys ...string) context.Context

func WithGHead

func WithGHead(ctx context.Context, key string, valStringer interface{}) context.Context


type CliResp

type CliResp struct {
	Header http.Header
	Body   []byte

http response

func HttpCliRequest

func HttpCliRequest(cli *http.Client, method, url, sbody string, transHeader func(http.Header)) (CliResp, error)

func HttpRequest

func HttpRequest(method, url, sbody string, transHeader func(http.Header)) (CliResp, error)

type Config

type Config struct {
	RunMode    string `json:"runMode"` //
	ListenAddr string `json:"listenAddr"`

	ListnTls ListenTLS `json:"listnTls"`

=> 启动配置

type ECode

type ECode = int

=> 错误码定义[3位数:复用http原本语义]

const (
	CodeSucessed         ECode = 0   // http.StatusOK
	CodeTokenNil         ECode = -1  // Head中没有携带token
	CodeTokenErr         ECode = -2  // token错误
	CodeTokenExpired     ECode = -3  // token过期
	CodeTokenMake        ECode = -4  // token生成失败
	CodeNotLogin         ECode = -5  // 未登录
	CodeNoRight          ECode = -6  // 未授权访问
	CodeAuthFaild        ECode = -7  // 认证错误
	CodeSysError         ECode = -9  // 系统错误
	CodeDBError          ECode = -10 // 数据库错误
	CodeParamErr         ECode = -11 // 参数错误
	CodeEncrypt          ECode = -15 // 加密解密错误
	CodeAuthStamp        ECode = -16 // 时间戳错误
	CodeAuthHash         ECode = -17 // Hash错误
	CodeTargetNotFound   ECode = -18 // 找不到目标
	CodeModelError       ECode = -19 // 模型层逻辑错误
	CodePermitDenied     ECode = -20 // 不允许访问
	CodePermitRdsRole    ECode = -21 // 许可错误[role]
	CodePermitRdsRoute   ECode = -22 // 许可错误[Route]
	CodePermitLoginClash ECode = -23 // 账号登陆冲突
	CodePermitChanged    ECode = -24 // 权限发生改变
	CodeConvertError     ECode = -25 // 结构转换错误
	CodeSortField        ECode = -26 // 不支持的排序字段

	CodeGrpcBase ECode = 100 // GRPC返回的状态码额外加100

type EStatus

type EStatus = interface{} // GRPC的状态码类型(uint32)

type GinLogger

type GinLogger struct{} //

-------- GinLogger

func (GinLogger) Write

func (this GinLogger) Write(p []byte) (n int, err error)

type GinRecover

type GinRecover struct{} //

-------- GinRecover

func (GinRecover) Write

func (this GinRecover) Write(p []byte) (n int, err error)

type Htp

type Htp struct {
	// contains filtered or unexported fields

 => etcd client control

func Install

func Install(ctrlName string, conf *Config) *Htp


func (*Htp) HandleInit

func (this *Htp) HandleInit()

func (*Htp) HandleTerm

func (this *Htp) HandleTerm()

func (*Htp) HasUnit

func (this *Htp) HasUnit(name string) int

Htp.HasUnit 查找 api

func (*Htp) Mount

func (this *Htp) Mount(source TUnits)

Htp.Mount 挂在初始化源,在控制器启动的时候一起创建

type IApier

type IApier interface {

	// 配置加载
	HandleInit(r *gin.Engine)

 => 配置数据接口

func Preregist

func Preregist(name string, handle IApier) IApier

Preregist 预加载API

type ICustClaimer

type ICustClaimer interface {
	TheUID() int64
	TheStandardClaims() *jwt.StandardClaims

type IMCGeter

type IMCGeter interface {

	// 获取基类配置
	HandleHtp() *Htp

 => Htp 对象接口

type IService

type IService interface {
	Handle(c *gin.Context, ctx context.Context) Response

type IUser

type IUser interface {
	Mutex() *sync.Mutex
	GetLast() time.Time
	Isload() bool

func GetUser

func GetUser(uId interface{}) (IUser, error)

GetUser 用id获取用户

type ListenTLS

type ListenTLS struct {
	Enable  bool   `json:"enable"` // "debug" or  "release"
	CrtFile string `json:"crtFile"`
	KeyFile string `json:"keyFile"`

type MUser

type MUser struct {
	Mutx sync.Mutex
	Last time.Time
	Load bool // 是否需要重新加载

} //

IUser 提供默认模型

func (*MUser) GetLast

func (u *MUser) GetLast() time.Time

func (*MUser) Isload

func (u *MUser) Isload() bool

func (*MUser) Mutex

func (u *MUser) Mutex() *sync.Mutex

func (*MUser) Ready

func (u *MUser) Ready() error

func (*MUser) Reload

func (u *MUser) Reload()

func (*MUser) SetLast

func (u *MUser) SetLast(t time.Time)

type Response

type Response struct {
	Code  ECode       `json:"code"`
	Data  interface{} `json:"data"`
	Msg   string      `json:"msg"`
	Error string      `json:"err,omitempty"`
	// contains filtered or unexported fields

Response 基础序列化器

func RespConvertErr

func RespConvertErr(msg string, err error) Response


func RespDBErr

func RespDBErr(msg string, err error) Response


func RespErr

func RespErr(errCode ECode, msg string, err error) Response


func RespErrData

func RespErrData(errCode ECode, msg string, err error, data interface{}) Response


func RespFile

func RespFile(c *gin.Context, filePath string) Response


func RespFileData

func RespFileData(c *gin.Context, contentType, fileName string, data []byte) Response


func RespModelErr

func RespModelErr(msg string, err error) Response


func RespOK

func RespOK(msg string, data interface{}) Response


func RespParamErr

func RespParamErr(msg string, err error) Response


func RespValidErr

func RespValidErr(err error) Response


func (*Response) Err

func (r *Response) Err() error

func (*Response) Track

func (r *Response) Track(s string) Response

type TUnits

type TUnits []Unit // 支持排序

func (TUnits) Len

func (l TUnits) Len() int

func (TUnits) Less

func (l TUnits) Less(i, j int) bool

func (TUnits) Swap

func (l TUnits) Swap(i, j int)

type TUserGeterFunc

type TUserGeterFunc func(uId interface{}) (IUser, error)

type Unit

type Unit struct {
	// contains filtered or unexported fields

func NewUnit

func NewUnit(name string, api IApier) Unit


Jump to

Keyboard shortcuts

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