bootstrap

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FileRotateLogs = new(fileRotateLogs)

Functions

func CorsMiddleware

func CorsMiddleware() gin.HandlerFunc

CorsMiddleware 跨域中间件

func LoggerMiddleware

func LoggerMiddleware(l *zap.Logger) gin.HandlerFunc

LoggerMiddleware 日志中间件

func LoginMiddleWare

func LoginMiddleWare() gin.HandlerFunc

LoginMiddleWare 登录中间件

func NewMiddlewares

func NewMiddlewares(l *zap.Logger) []gin.HandlerFunc

func NewMysql

func NewMysql(config *Config) *gorm.DB

NewMysql 创建数据库连接

func NewRedis

func NewRedis(config *Config) redis.Cmdable

func NewServer

func NewServer(middlewares []gin.HandlerFunc, uh *handler.UserHandler, wh *handler.WebSocketHandler) *gin.Engine

func NewViper

func NewViper() *viper.Viper

NewViper 创建viper实例

func NewWebSocketManager

func NewWebSocketManager(config *Config) map[string]*websocket.Manager

func NewZap

func NewZap(config *Config) *zap.Logger

NewZap 创建Zap实例

Types

type Config

type Config struct {
	ServerConfig    *ServerConfig    `mapstructure:"server" json:"server" yaml:"server"`
	MysqlConfig     *MysqlConfig     `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
	RedisConfig     *RedisConfig     `mapstructure:"redis" json:"redis" yaml:"redis"`
	ZapConfig       *ZapConfig       `mapstructure:"zap" json:"zap" yaml:"zap"`
	WebSocketConfig *WebSocketConfig `mapstructure:"websocket" json:"websocket" yaml:"websocket"`
}

Config 配置文件

func NewConfig

func NewConfig(v *viper.Viper) *Config

NewConfig 读取配置文件

type MysqlConfig

type MysqlConfig struct {
	Hostname string `mapstructure:"hostname" json:"hostname" yaml:"hostname"` // 服务器地址
	Port     int    `mapstructure:"port" json:"port" yaml:"port"`             // 端口
	Config   string `mapstructure:"config" json:"config" yaml:"config"`       // 高级配置
	Database string `mapstructure:"database" json:"database" yaml:"database"` // 数据库名
	Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库用户名
	Password string `mapstructure:"password" json:"password" yaml:"password"` // 数据库密码
}

MysqlConfig mysql配置

type RedisConfig

type RedisConfig struct {
	Host     string `mapstructure:"host" json:"host" yaml:"host"`
	Port     int    `mapstructure:"port" json:"port" yaml:"port"`
	Username string `mapstructure:"username" json:"username" yaml:"username"`
	Password string `mapstructure:"password" json:"password" yaml:"password"`
}

type ServerConfig

type ServerConfig struct {
	Host string `mapstructure:"host" json:"host" yaml:"host"`
	Port int    `mapstructure:"port" json:"port" yaml:"port"`
}

ServerConfig server配置

type WebSocketConfig

type WebSocketConfig struct {
	Biz []string `mapstructure:"biz" json:"biz" yaml:"biz"`
}

WebSocketConfig websocket配置

type ZapConfig

type ZapConfig struct {
	Level         string `mapstructure:"level" json:"level" yaml:"level"`                            // 级别
	Prefix        string `mapstructure:"prefix" json:"prefix" yaml:"prefix"`                         // 日志前缀
	Format        string `mapstructure:"format" json:"format" yaml:"format"`                         // 输出
	Director      string `mapstructure:"director" json:"director"  yaml:"director"`                  // 日志文件夹
	EncodeLevel   string `mapstructure:"encode-level" json:"encode-level" yaml:"encode-level"`       // 编码级
	StacktraceKey string `mapstructure:"stacktrace-key" json:"stacktrace-key" yaml:"stacktrace-key"` // 栈名
	MaxAge        int    `mapstructure:"max-age" json:"max-age" yaml:"max-age"`                      // 日志留存时间
	ShowLine      bool   `mapstructure:"show-line" json:"show-line" yaml:"show-line"`                // 显示行
	LogInConsole  bool   `mapstructure:"log-in-console" json:"log-in-console" yaml:"log-in-console"` // 输出控制台
}

ZapConfig 配置

Jump to

Keyboard shortcuts

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