configs

package
v0.0.0-...-66cf1cd Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package configs @program: gin-template @author: [lliuhuan](https://github.com/lliuhuan) @create: 2024-07-23 22:36

Package configs @program: gin-template @author: [lliuhuan](https://github.com/lliuhuan) @create: 2024-07-02 21:31

Package configs

@program:		gin-template
@author:		[lliuhuan](https://github.com/lliuhuan)
@create:		2024-07-02 21:32
@description:	常量配置

Package configs

@program:		gin-template
@author:		[lliuhuan](https://github.com/lliuhuan)
@create:		2024-07-02 21:32
@description:	数据库配置

Package configs @program: gin-template @author: [lliuhuan](https://github.com/lliuhuan) @create: 2024-07-02 21:32

Package configs

@program:		gin-template
@author:		[lliuhuan](https://github.com/lliuhuan)
@create:		2024-07-02 21:33
@description:	报警配置

Package configs @program: gin-template @author: [lliuhuan](https://github.com/lliuhuan) @create: 2024-07-02 21:33

Package configs

@program:		gin-template
@author:		[lliuhuan](https://github.com/lliuhuan)
@create:		2024-07-02 21:33
@description:	redis配置

Index

Constants

View Source
const (
	// MinGoVersion 支持的最小Go版本
	MinGoVersion = 1.16
	// ProjectVersion 项目版本
	ProjectVersion = "v0.0.1"
	// ProjectName 项目名称
	ProjectName = "gin-template"

	// ProjectLogFile 项目访问日志存放文件
	ProjectLogFile = "./logs/" + ProjectName + ".log"

	// ProjectCronLogFile 项目后台任务日志存放文件
	ProjectCronLogFile = "./logs/" + ProjectName + "-cron.log"

	// ZhCN 简体中文 - 中国
	ZhCN = "zh-cn"

	// EnUS 英文 - 美国
	EnUS = "en-us"

	// HeaderLoginToken 登录验证 Token,Header 中传递的参数
	HeaderLoginToken = "Token"

	// HeaderSignToken 签名验证 Authorization,Header 中传递的参数
	HeaderSignToken = "Authorization"

	// HeaderSignTokenDate 签名验证 Date,Header 中传递的参数
	HeaderSignTokenDate = "Authorization-Date"

	// MaxRequestsPerSecond 每秒最大请求量
	MaxRequestsPerSecond = 10000

	ProjectNotifyMail   = "mail"
	ProjectNotifyWeChat = "wechat"

	ProjectDBMySQL     = "mysql"
	ProjectDBSQLServer = "sqlserver"
	ProjectDBPGSQL     = "postgresql"

	ConfigKeyPrefix = "Config_" //  配置文件键值缓存时,键的前缀

	// RedisKeyPrefixLoginUser Redis Key 前缀 - 登录用户信息
	RedisKeyPrefixLoginUser = ProjectName + ":login-user:"

	// RedisKeyPrefixSignature Redis Key 前缀 - 签名验证信息
	RedisKeyPrefixSignature = ProjectName + ":signature:"

	// LoginSessionTTL 登录有效期为 24 小时
	LoginSessionTTL = time.Hour * 24

	// ProjectInstallMark 项目安装完成标识
	ProjectInstallMark = "INSTALL.lock"

	// HeaderSignTokenTimeout 签名有效期为 2 分钟
	HeaderSignTokenTimeout = time.Minute * 2
)

Variables

This section is empty.

Functions

func CreateContainersFactory

func CreateContainersFactory() *containers

CreateContainersFactory 创建一个容器工厂

Types

type Captcha

type Captcha struct {
	KeyLong            int `toml:"keyLong"`            // KeyLong 验证码长度
	ImgWidth           int `toml:"imgWidth"`           // ImgWidth 图片宽度
	ImgHeight          int `toml:"imgHeight"`          // ImgHeight 图片高度
	OpenCaptcha        int `toml:"openCaptcha"`        // OpenCaptcha 防爆破验证码开启此数,0代表每次登录都需要验证码,其他数字代表错误密码此数,如3代表错误三次后出现验证码
	OpenCaptchaTimeOut int `toml:"openCaptchaTimeout"` // OpenCaptchaTimeOut 防爆破验证码超时时间,单位:s(秒)
}

type Config

type Config struct {
	Project  Project  `mapstructure:"project" json:"project" yaml:"project" toml:"project"`     // 项目信息
	Notify   Notify   `mapstructure:"notify" json:"notify" yaml:"notify" toml:"notify"`         // 通知配置
	Redis    Redis    `mapstructure:"redis" json:"redis" yaml:"redis" toml:"redis"`             // redis配置
	DataBase DataBase `mapstructure:"database" json:"database" yaml:"database" toml:"database"` // 数据库配置
	HashIds  HashIds  `mapstructure:"hash-ids" json:"hashIds" yaml:"hash-ids" toml:"hash-ids"`  // hashIds配置
	Captcha  Captcha  `mapstructure:"captcha" json:"captcha" yaml:"captcha" toml:"captcha"`     // 验证码配置
}

func Get

func Get() *Config

type DataBase

type DataBase struct {
	Mode string `toml:"mode"` // Mode 数据库模式 database|sqlite3|postgres|sqlserver
	// MySql
	MySql DataBaseConf `toml:"mysql"`
	// SqlServer
	SqlServer DataBaseConf `toml:"sqlserver"`
	// PostgreSql
	PostgreSql DataBaseConf `toml:"postgresql"`
}

func (*DataBase) GetDataBaseConfig

func (d *DataBase) GetDataBaseConfig() DataBaseConf

type DataBaseConf

type DataBaseConf struct {
	IsOpenReadDB int                `toml:"isOpenReadDB"` // 是否开启读写分离,如果不开启的话就默认忽略Read库的配置
	Read         DataBaseConfDetail `toml:"read"`
	Write        DataBaseConfDetail `toml:"write"`
	Base         DataBaseConfBase   `toml:"base"`
}

type DataBaseConfBase

type DataBaseConfBase struct {
	MaxIdleConn     int `toml:"maxIdleConn"`
	MaxOpenConn     int `toml:"maxOpenConn"`
	ConnMaxLifeTime int `toml:"connMaxLifeTime"`
}

type DataBaseConfDetail

type DataBaseConfDetail struct {
	Host     string `toml:"host"`
	Port     int    `toml:"port"`
	User     string `toml:"user"`
	Pass     string `toml:"pass"`
	DataBase string `toml:"dataBase"`
	Charset  string `toml:"charset"`
	Prefix   string `toml:"prefix"` // 表前缀
	// 下面是PGSql的
	SSLMode     string `toml:"sslMode"`     // SSLMode 是否开启SSL
	SSLRootCert string `toml:"sslRootCert"` // SSLRootCert 根证书路径
	SSLCert     string `toml:"sslCert"`     // SSLCert 证书路径
	TimeZone    string `toml:"timeZone"`    // TimeZone 时区
	//下面是sqlite3的
	Path string `toml:"path"` // Path 数据库路径
}

type HashIds

type HashIds struct {
	Alphabet  string   `toml:"alphabet"`
	MinLength uint8    `toml:"min-length"`
	BlockList []string `toml:"block-list"`
}

type Mail

type Mail struct {
	Host string `toml:"host"` // 邮箱服务器地址
	Port int    `toml:"port"` // 邮箱服务器端口
	User string `toml:"user"` // 邮箱账号
	Pass string `toml:"pass"` // 邮箱密码
	To   string `toml:"to"`   // 接收人
}

type Notify

type Notify struct {
	Way    string `mapstructure:"way" json:"way" toml:"way"`          // 告警方式
	Mail   Mail   `mapstructure:"mail" json:"mail" toml:"mail"`       // 告警邮箱配置
	WeChat WeChat `mapstructure:"wechat" json:"wechat" toml:"wechat"` // 告警微信配置
}

type Project

type Project struct {
	Domain  string `mapstructure:"domain" json:"domain" toml:"domain"`    // 项目ip/域名
	Port    int    `mapstructure:"port" json:"port" toml:"port"`          // 项目端口
	Local   string `mapstructure:"local" json:"local" toml:"local"`       // 中英文 zh-cn/en-us
	PidFile string `mapstructure:"pidfile" json:"pidfile" toml:"pidfile"` // pid文件

}

type Redis

type Redis struct {
	Mode         string   `toml:"mode"`         // Mode Redis模式 cluster|simple|failover
	MasterName   string   `toml:"masterName"`   // MasterName 哨兵主节点名称,sentinel模式下需要配置此项
	Addr         string   `toml:"addr"`         // Addr Simple 实例配置地址
	Addrs        []string `toml:"addrs"`        // Addrs Cluster,Failover实例配置地址
	Pass         string   `toml:"pass"`         // Pass 密码
	DB           int      `toml:"db"`           // DB,默认为0, 一般应用不推荐使用DB分片
	MaxRetries   int      `toml:"maxRetries"`   // MaxRetries 网络相关的错误最大重试次数 默认8次
	PoolSize     int      `toml:"poolSize"`     // PoolSize 集群内每个节点的最大连接池限制 默认每个CPU10个连接
	MinIdleConns int      `toml:"minIdleConns"` // MinIdleConns 最小空闲连接数
	DialTimeout  int      `toml:"dialTimeout"`  // DialTimeout 拨超时时间
	ReadTimeout  int      `toml:"readTimeout"`  // ReadTimeout 读超时 默认3s
	WriteTimeout int      `toml:"writeTimeout"` // WriteTimeout 读超时 默认3s

}

type TomlConfigInterf

type TomlConfigInterf interface {
	ConfigFileChangeListen()
	Clone(fileName string) TomlConfigInterf
	Get(keyName string) interface{}
	GetString(keyName string) string
	GetBool(keyName string) bool
	GetInt(keyName string) int
	GetInt32(keyName string) int32
	GetInt64(keyName string) int64
	GetFloat64(keyName string) float64
	GetDuration(keyName string) time.Duration
	GetStringSlice(keyName string) []string
	Set(keyName string, value any)
	WriteConfig() error
	// contains filtered or unexported methods
}

func CreateTomlFactory

func CreateTomlFactory() TomlConfigInterf

CreateTomlFactory 创建一个yaml配置文件工厂 两种方式存储配置文件,一种是解析到结构体,一种是使用KV

func GetContainer

func GetContainer() TomlConfigInterf

type WeChat

type WeChat struct {
	Key string `mapstructure:"key" json:"key" toml:"key"` // 企业微信机器人key
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳