gins

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 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: "OK"}
	InternalError   = &Errno{Code: 10001, Message: "Internal server error"}
	ErrTokenInvalid = &Errno{Code: 20001, Message: "The token was invalid."}
	ErrParam        = &Errno{Code: 30001, Message: "The parameter is error."}
	ErrPageParam    = &Errno{Code: 30002, Message: "The parameter of page_no or page_size is error"}
)
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 DecodeErr

func DecodeErr(err error) (int, string)

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
}

Err represents an error

func NewErr

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

func (*Err) Add

func (err *Err) Add(message string) error

func (*Err) AddAny

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

func (*Err) Error

func (err *Err) Error() string

type Errno

type Errno struct {
	Code    int
	Message string
}

func (Errno) Error

func (err Errno) Error() string

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 Message

type Message struct {
	Style int         `json:"style"`
	Data  interface{} `json:"data"`
}

type Response

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	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(relativePath string, 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 {
	Code    int                    `json:"code"`
	Message string                 `json:"message"`
	Data    map[string]interface{} `json:"data"`
}

Jump to

Keyboard shortcuts

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