bootstrap

package
v0.0.0-...-2cadb06 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: Apache-2.0 Imports: 21 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 NewMongo

func NewMongo(c *Config, l *zap.Logger) *mongo.Database

func NewMysql

func NewMysql(c *Config, l *zap.Logger) *gorm.DB

NewMysql 创建Mysql数据库连接

func NewRedis

func NewRedis(c *Config) redis.Cmdable

func NewServer

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

NewServer 创建server

func NewViper

func NewViper() *viper.Viper

NewViper 创建viper实例

func NewZap

func NewZap(c *Config) *zap.Logger

NewZap NewZap

Types

type CacheConfig

type CacheConfig struct {
	UserExpiration int64 `mapstructure:"user-expiration" json:"user-expiration" yaml:"user-expiration"`
}

type Config

type Config struct {
	ServerConfig *ServerConfig `mapstructure:"server" json:"server" yaml:"server"`
	ZapConfig    *ZapConfig    `mapstructure:"zap" json:"zap" yaml:"zap"`
	MysqlConfig  *MysqlConfig  `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
	MongoConfig  *MongoConfig  `mapstructure:"mongo" json:"mongo" yaml:"mongo"`
	RedisConfig  *RedisConfig  `mapstructure:"redis" json:"redis" yaml:"redis"`
	TokenConfig  *TokenConfig  `mapstructure:"token" json:"token" yaml:"token"`
	CacheConfig  *CacheConfig  `mapstructure:"cache" json:"cache" yaml:"cache"`
	LimitConfig  *LimitConfig  `mapstructure:"limit" json:"limit" yaml:"limit"`
}

Config 配置文件

func NewConfig

func NewConfig(v *viper.Viper) *Config

NewConfig 读取配置文件

type LimitConfig

type LimitConfig struct {
	SmsLimitConfig *SmsLimitConfig `mapstructure:"sms" json:"sms" yaml:"sms"`
}

type MongoConfig

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

MongoConfig mongodb配置

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 {
	Address  string `mapstructure:"address" json:"address" yaml:"address"`
	User     string `mapstructure:"user" json:"user" yaml:"user"`
	Password string `mapstructure:"password" json:"password" yaml:"password"`
}

type Server

type Server gin.Engine

type ServerConfig

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

ServerConfig server配置

type SmsLimitConfig

type SmsLimitConfig struct {
	Interval int `mapstructure:"interval" json:"interval" yaml:"interval"`
	Rate     int `mapstructure:"rate" json:"rate" yaml:"rate"`
}

type TokenConfig

type TokenConfig struct {
	Expiration int `mapstructure:"expiration" json:"expiration" yaml:"expiration"`
}

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