gins

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OK              = &Errno{Code: 0, Message: "success", Tips: "成功"}
	InternalError   = &Errno{Code: 10001, Message: "Internal server error", Tips: "服务器内部错误"}
	ErrTokenInvalid = &Errno{Code: 20001, Message: "The token was invalid", Tips: "Token无效"}
	ErrParam        = &Errno{Code: 30001, Message: "The parameter is error", Tips: "参数错误"}
	ErrPageParam    = &Errno{Code: 30002, Message: "The parameter of page_no or page_size is error", Tips: "分页参数错误"}
)
View Source
var JwtSecret = "ABCDEFabcdef123456"
View Source
var WhitelistAPI = map[string]bool{
	"/api/v1/account/login":    true,
	"/api/v1/account/vericode": true,
	"/ping":                    true,
	"/favicon.ico":             true,
}

Functions

func CheckPageParam

func CheckPageParam(c *Context) (bool, error)

func CheckToken

func CheckToken(token, apiPath string, c *Context) (string, error)

func GetAnyString

func GetAnyString(desc string, keys ...interface{}) string

func GetJoinString

func GetJoinString(ss ...interface{}) string

func GetKeyword

func GetKeyword(keys ...interface{}) string

func GetStatus

func GetStatus(s interface{}) string

func GetString

func GetString(s interface{}) string

func HandleFunc

func HandleFunc(handler func(c *Context)) func(ctx *gin.Context)

func InitLog

func InitLog(logDir, logfileName string)

func InitLogger

func InitLogger(l *Log) zapcore.Core

func LogDebug

func LogDebug(msg ...string)

func LogError

func LogError(msg ...string)

func LogFatal

func LogFatal(msg ...string)

func LogInfo

func LogInfo(msg ...string)

func LogPanic

func LogPanic(msg ...string)

func LogWarn

func LogWarn(msg ...string)

func SendResponse

func SendResponse(c *Context, err error, data interface{})

Types

type BodyLogWriter

type BodyLogWriter struct {
	gin.ResponseWriter
	// contains filtered or unexported fields
}

func (BodyLogWriter) Write

func (w BodyLogWriter) Write(b []byte) (int, error)

type Context

type Context struct {
	*gin.Context
}

func (*Context) ArgsBool

func (c *Context) ArgsBool(key string) bool

func (*Context) ArgsBoolDefault

func (c *Context) ArgsBoolDefault(key string, val bool) bool

func (*Context) ArgsFile

func (c *Context) ArgsFile(key string) (*multipart.FileHeader, error)

func (*Context) ArgsFileDefault

func (c *Context) ArgsFileDefault(key string, file *multipart.FileHeader) (*multipart.FileHeader, error)

func (*Context) ArgsFloat64

func (c *Context) ArgsFloat64(key string) float64

func (*Context) ArgsFloat64Array

func (c *Context) ArgsFloat64Array(key string) []float64

func (*Context) ArgsFloat64ArrayDefault

func (c *Context) ArgsFloat64ArrayDefault(key string, val []float64) []float64

func (*Context) ArgsFloat64Default

func (c *Context) ArgsFloat64Default(key string, val float64) float64

func (*Context) ArgsInt

func (c *Context) ArgsInt(key string) int

func (*Context) ArgsInt64

func (c *Context) ArgsInt64(key string) int64

func (*Context) ArgsInt64Array

func (c *Context) ArgsInt64Array(key string) []int64

func (*Context) ArgsInt64ArrayDefault

func (c *Context) ArgsInt64ArrayDefault(key string, val []int64) []int64

func (*Context) ArgsInt64Default

func (c *Context) ArgsInt64Default(key string, val int64) int64

func (*Context) ArgsIntArray

func (c *Context) ArgsIntArray(key string) []int

func (*Context) ArgsIntArrayDefault

func (c *Context) ArgsIntArrayDefault(key string, val []int) []int

func (*Context) ArgsIntDefault

func (c *Context) ArgsIntDefault(key string, val int) int

func (*Context) ArgsObject

func (c *Context) ArgsObject(key string) interface{}

func (*Context) ArgsObjectDefault

func (c *Context) ArgsObjectDefault(key string, val interface{}) interface{}

func (*Context) ArgsString

func (c *Context) ArgsString(key string) string

func (*Context) ArgsStringArray

func (c *Context) ArgsStringArray(key string) []string

func (*Context) ArgsStringArrayDefault

func (c *Context) ArgsStringArrayDefault(key string, val []string) []string

func (*Context) ArgsStringDefault

func (c *Context) ArgsStringDefault(key string, val string) string

func (*Context) ArgsUint

func (c *Context) ArgsUint(key string) uint

func (*Context) ArgsUint64

func (c *Context) ArgsUint64(key string) uint64

func (*Context) ArgsUint64Array

func (c *Context) ArgsUint64Array(key string) []uint64

func (*Context) ArgsUint64ArrayDefault

func (c *Context) ArgsUint64ArrayDefault(key string, val []uint64) []uint64

func (*Context) ArgsUint64Default

func (c *Context) ArgsUint64Default(key string, val uint64) uint64

func (*Context) ArgsUintArray

func (c *Context) ArgsUintArray(key string) []uint

func (*Context) ArgsUintArrayDefault

func (c *Context) ArgsUintArrayDefault(key string, val []uint) []uint

func (*Context) ArgsUintDefault

func (c *Context) ArgsUintDefault(key string, val uint) uint

func (*Context) SaveFile

func (c *Context) SaveFile(key, savePath string) error

type Err

type Err struct {
	Code    int
	Message string
	Err     error
}

type Errno

type Errno struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Tips    string `json:"tips"`
	Err     error  `json:"err"`
}

func DecodeErr

func DecodeErr(err error) *Errno

func NewErr

func NewErr(errno *Errno, err error) *Errno

func (*Errno) Add added in v0.1.8

func (err *Errno) Add(message string)

func (*Errno) AddAny added in v0.1.8

func (err *Errno) AddAny(format string, args ...interface{})

func (*Errno) Error

func (err *Errno) Error() string

type H added in v0.1.7

type H gin.H

type HandlerFunc

type HandlerFunc func(*Context)

func Args

func Args(checkParamMethods ...func(c *Context) (bool, error)) HandlerFunc

func Cors

func Cors() HandlerFunc

func LogAop

func LogAop(dealLogInfo func(data LogData)) HandlerFunc

func Validate

func Validate(checkToken func(token, apiPath string, c *Context) (string, error)) HandlerFunc

type Log

type Log struct {
	LogDir      string
	LogFileName string
	Stdout      bool
	LogMaxSize  int
	LogMaxAge   int
	MaxBackups  int
	LogCompress bool
	LocalTime   bool
	EnableColor bool
	JsonFormat  bool
	LogMinLevel zapcore.Level
}

type LogData

type LogData struct {
	LogInfo       map[string]interface{} `json:"log_info"`
	RequestParams map[string]interface{} `json:"request_params"`
	RequestToken  string                 `json:"request_token"`
	ResponseData  string                 `json:"response_data"`
}

type Response

type Response struct {
	*Errno
	Data interface{} `json:"data"`
}

type RouterGroup

type RouterGroup struct {
	*gin.RouterGroup
}

func (*RouterGroup) ANY

func (r *RouterGroup) ANY(relativePath string, handlers ...func(c *Context)) gin.IRoutes

func (*RouterGroup) DELETE

func (r *RouterGroup) DELETE(relativePath string, handlers ...func(c *Context)) gin.IRoutes

func (*RouterGroup) GET

func (r *RouterGroup) GET(relativePath string, handlers ...func(c *Context)) gin.IRoutes

func (*RouterGroup) POST

func (r *RouterGroup) POST(relativePath string, handlers ...func(c *Context)) gin.IRoutes

func (*RouterGroup) PUT

func (r *RouterGroup) PUT(relativePath string, handlers ...func(c *Context)) gin.IRoutes

func (*RouterGroup) Use

func (r *RouterGroup) Use(middlewares ...func(c *Context)) gin.IRoutes

type Server

type Server struct {
	*gin.Engine
}

func DefaultServer

func DefaultServer(mode string) *Server

func NewServer

func NewServer(mode string) *Server

func (*Server) ANY

func (s *Server) ANY(relativePath string, handlers ...func(c *Context)) gin.IRoutes

func (*Server) DELETE

func (s *Server) DELETE(relativePath string, handlers ...func(c *Context)) gin.IRoutes

func (*Server) GET

func (s *Server) GET(relativePath string, handlers ...func(c *Context)) gin.IRoutes

func (*Server) Group

func (s *Server) Group(relativePath string, handlers ...func(c *Context)) *RouterGroup

func (*Server) NoRoute

func (s *Server) NoRoute(handlers ...func(c *Context))

func (*Server) POST

func (s *Server) POST(relativePath string, handlers ...func(c *Context)) gin.IRoutes

func (*Server) PUT

func (s *Server) PUT(relativePath string, handlers ...func(c *Context)) gin.IRoutes

func (*Server) Use

func (s *Server) Use(middlewares ...HandlerFunc)

type ThirdResponse

type ThirdResponse struct {
	*Errno
	Data map[string]interface{} `json:"data"`
}

Jump to

Keyboard shortcuts

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