groot

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 33 Imported by: 0

README

groot

gin api template

  • gin
  • viper
  • zap
  • go-redis
  • swaggo
  • gorm

Documentation

Index

Constants

View Source
const (
	TRACE_CTX = "TRACE_CTX"
	TRACE_ID  = "TRACE_ID"
)
View Source
const (
	DRIVER_MYSQL      = "mysql"
	DRIVER_POSTGRESQL = "pgsql"
	DRIVER_SQLITE     = "sqlite"
)
View Source
const DEFAULT_CONFIG_FILENAME = "config"
View Source
const DEFAULT_CONFIG_FILETYPE = "toml"
View Source
const KEY_DEPLOY_ENV = "DEPLOY_ENV"

Variables

View Source
var SwaggerInfo = &SwaggerInfoData{
	Enable:      false,
	Version:     "",
	Host:        "",
	BasePath:    "",
	Schemes:     []string{},
	Title:       "",
	Description: "",
}

SwaggerInfo holds exported Swagger Info so clients can modify it

Functions

func Debug

func Debug(msg string, fields ...zap.Field)

func Error

func Error(msg string, fields ...zap.Field)

func GetDb

func GetDb() *gorm.DB

func GetRedisClient

func GetRedisClient() *goredislib.Client

func GetRedisSync

func GetRedisSync() *redsync.Redsync

func GetTraceId

func GetTraceId(c *gin.Context) (string, bool)

func GinLogger

func GinLogger() gin.HandlerFunc

func GinRecovery

func GinRecovery(stack bool) gin.HandlerFunc

func InitDb

func InitDb()

func InitLogger

func InitLogger(cfg *LogConfig) (err error)

InitLogger 初始化Logger

func InitRedis

func InitRedis() error

func InitSwagger

func InitSwagger(cfg *SwaggerInfoData, r *gin.Engine)

func LoadConfig

func LoadConfig(files ...string) error

func Log

func Log() *zap.Logger

func SetSwagDoc

func SetSwagDoc(docstr string)

func TDebug

func TDebug(c *gin.Context, msg string, fields ...zap.Field)

func TError

func TError(c *gin.Context, msg string, fields ...zap.Field)

func TInfo

func TInfo(c *gin.Context, msg string, fields ...zap.Field)

func TraceIdMiddleware

func TraceIdMiddleware() gin.HandlerFunc

Types

type ApiResult

type ApiResult struct {
	Code    int         `json:"code"`
	Msg     string      `json:"msg"`
	ErrCode string      `json:"errCode"`
	Data    interface{} `json:"data"`
}

func Fail

func Fail(msg string, errCode string) ApiResult

func OK

func OK(data interface{}) ApiResult

type LogConfig

type LogConfig struct {
	Level      string `json:"level"`
	Filename   string `json:"filename"`
	MaxSize    int    `json:"maxsize"`
	MaxAge     int    `json:"max_age"`
	MaxBackups int    `json:"max_backups"`
}

func GetLogConfig

func GetLogConfig() LogConfig

type OrmConfig

type OrmConfig struct {
	Driver          string `json:"driver"`
	Url             string `json:"url"`
	Debug           bool   `json:"debug"`
	MaxIdleConns    int    `json:"maxIdleConns"`    // SetMaxIdleConns 用于设置连接池中空闲连接的最大数量。
	MaxOpenConns    int    `json:"maxOpenConns"`    // SetMaxOpenConns 设置打开数据库连接的最大数量。
	ConnMaxLifetime int    `json:"connMaxLifetime"` // SetConnMaxLifetime 设置了连接可复用的最大时间, 秒
}

func GetOrmConfig

func GetOrmConfig() OrmConfig

type RedisConfig

type RedisConfig struct {
	Addr     string `json:"addr"`
	Password string `json:"password"`
	Db       int    `json:"db"`
}

func GetRedisConfig

func GetRedisConfig() RedisConfig

type Server

type Server struct {
	Engine *gin.Engine
	Cfg    *ServerConfig
}

func NewDefaultServer

func NewDefaultServer() *Server

func (*Server) Run

func (s *Server) Run() error

type ServerConfig

type ServerConfig struct {
	Host string `json:"host"`
	Port int    `json:"port"`
	Cors bool   `json:"cors"`
}

func GetServerConfig

func GetServerConfig() ServerConfig

type SwaggerInfoData

type SwaggerInfoData struct {
	Enable      bool
	Version     string
	Host        string
	BasePath    string
	Schemes     []string
	Title       string
	Description string
	JsonFile    string // json file path
}

func GetSwaggerConfig

func GetSwaggerConfig() SwaggerInfoData

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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