Back to godoc.org

Package htp

v0.0.0-...-d73eb14
Latest Go to latest

The latest major version is .

Published: Oct 22, 2019 | License: GPL2 | Module: gitee.com/cloudapex/Ghost

Index

Constants

const (
	CodeSucessed    = 0     // http.StatusOK
	CodeNotLogin    = 401   // 未登录
	CodeNoRight     = 403   // 未授权访问
	CodeDBError     = 10001 // 数据库操作失败
	CodeEncrypt     = 10002 // 加密失败
	CodeParamErr    = 10003 // 各种奇奇怪怪的参数错误
	CodeExtendBegin = 20000 // 扩展起始Code
)

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

func MH_Cors

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

Cors 跨域配置

func MH_CurrentUser

func MH_CurrentUser() gin.HandlerFunc

MH_CurrentUser 获取登录用户

func MH_Session

func MH_Session(secret string) gin.HandlerFunc

Session 初始化session

func MH_UserAuthed

func MH_UserAuthed() gin.HandlerFunc

MH_AuthRequired 需要登录

func Service

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

func Sessions

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

func SetModeAndLogger

func SetModeAndLogger(value string, out io.Writer)

func SetUserGeter

func SetUserGeter(f TUserGeterFunc)

type GinLogger

type GinLogger struct{} //

func (GinLogger) Write

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

type IService

type IService interface {
	Handle(c *gin.Context) Response
}

type IUser

type IUser interface {
	Mutex() *sync.Mutex
	SetLastTime(time.Time)
	Reload()
}

func GetUser

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

GetUser 用id获取用户

type Response

type Response struct {
	Code  int         `json:"code"`
	Data  interface{} `json:"data,omitempty"`
	Msg   string      `json:"msg"`
	Error string      `json:"error,omitempty"`
}

Response 基础序列化器

func ErrorResponse

func ErrorResponse(err error) Response

校验器返回错误

func RespDBErr

func RespDBErr(msg string, err error) Response

数据库操作失败

func RespErr

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

通用错误处理

func RespNotLogin

func RespNotLogin() Response

检查登录

func RespOK

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

成功返回

func RespParamErr

func RespParamErr(msg string, err error) Response

各种参数错误

func RespUserDBErr

func RespUserDBErr(c *gin.Context, msg string, err error) Response

用户数据库操作失败

func (*Response) Err

func (r *Response) Err() error

type TUserGeterFunc

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

type TrackedErrorResponse

type TrackedErrorResponse struct {
	Response
	TrackID string `json:"track_id"`
}

TrackedErrorResponse 有追踪信息的错误响应

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier