initial

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	O_SERVER_CONFIG *ServerConfig

	O_DB_PG *gorm.DB
	O_REDIS *redis.Client
)

singleton

Functions

func InitBaseRouter

func InitBaseRouter(router *gin.Engine) *gin.Engine

func InitGormPg

func InitGormPg() *gorm.DB

GormPgSql 初始化 Postgresql 数据库 Author [piexlmax](https://github.com/piexlmax) Author [SliverHorn](https://github.com/SliverHorn)

func InitRedis

func InitRedis() *redis.Client

func InitServer

func InitServer(address string, router *gin.Engine) server

func InitServerConfig

func InitServerConfig()

func InitSwagger

func InitSwagger(router *gin.Engine, staticPath string) *gin.Engine

Types

type PgConn

type PgConn struct {
	DSN           string `mapstructure:"dsn" json:"dsn" yaml:"dsn"`                                  // 是否开启Gorm全局日志
	MaxIdleConns  int    `mapstructure:"max-idle-conns" json:"max-idle-conns" yaml:"max-idle-conns"` // 空闲中的最大连接数
	MaxOpenConns  int    `mapstructure:"max-open-conns" json:"max-open-conns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
	SlowThreshold int    `mapstructure:"slow-threshold" json:"slow-threshold" yaml:"slow-threshold"` // slow sql threshold
}

func (PgConn) GormPgSqlByConfig

func (p PgConn) GormPgSqlByConfig() *gorm.DB

GormPgSqlByConfig 初始化 Postgresql 数据库 通过参数

type Redis

type Redis struct {
	Addr     string `mapstructure:"addr" json:"addr" yaml:"addr"`             // 服务器地址:端口
	Username string `mapstructure:"username" json:"username" yaml:"username"` // 密码
	Password string `mapstructure:"password" json:"password" yaml:"password"` // 密码
	DB       int    `mapstructure:"db" json:"db" yaml:"db"`                   // redis的哪个数据库
}

func (Redis) InitRedisByConfig

func (redisCfg Redis) InitRedisByConfig() *redis.Client

type ServerConfig

type ServerConfig struct {
	Redis  Redis  `mapstructure:"redis" json:"redis" yaml:"redis"`
	PgConn PgConn `mapstructure:"pg-conn" json:"pg-conn" yaml:"pg-conn"`

	ServerName string `mapstructure:"server-name" json:"server-name" yaml:"server-name"`
	LogPath    string `mapstructure:"log-path" json:"log-path" yaml:"log-path"`
	TimeOut    int    `mapstructure:"time-out" json:"time-out" yaml:"time-out"`

	SecurityKey   string `mapstructure:"security-key" json:"security-key" yaml:"security-key"`
	SecurityValue string `mapstructure:"security-value" json:"security-value" yaml:"security-value"`
}

func LoadServerConfig

func LoadServerConfig(serverConfig *ServerConfig) *ServerConfig

Jump to

Keyboard shortcuts

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