config

package
v0.0.0-...-3208bda Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: MIT Imports: 4 Imported by: 0

README

配置目录说明

  • 动态配置项基于yaml文件,编译后启动时可传入config目录启动;
  • 根据debug、release、test三种环境载入配置,配置文件于对应环境的目录中;
  • 可使用ginger-gen工具,根据yaml文件生成配置项解析代码;
  • 除yaml文件配置外,配置项也可用常数;

Documentation

Index

Constants

View Source
const (

	// 基本设置
	AppName    = "ginger"
	AppVersion = "v1.0.0"
	DefaultEnv = gin.DebugMode // 环境变量未设置时的默认值,默认使用开发环境配置

	// jwt编码时的私钥字符串
	TokenPrivateKey = "gingeradmin"

	// oauth2 Key and Secret
	// 微信
	WechatSignSwitch      = true
	WechatOAuth2AppKey    = ""
	WechatOAuth2AppSecret = ""
)

常量级参数配置项,编译前设置值

Variables

View Source
var (
	BaseConf  *Base
	LogConf   *Log
	MysqlConf *Mysql
	RedisConf *Redis
	MongoConf *Mongodb
	MqConf    *Mq
	CorsConf  *Cors
)

Functions

func Init

func Init(confPath string)

动态参数配置项,编译后可携yaml配置文件启动

Types

type Base

type Base struct {
	Env        string `yaml:"env"`
	ListenPort int64  `yaml:"listen"`
}

基础配置

type Cors

type Cors struct {
	AllowHeaders     []string `yaml:"AllowHeaders"`
	AllowCredentials bool     `yaml:"AllowCredentials"`
	ExposeHeaders    []string `yaml:"ExposeHeaders"`
	MaxAge           int      `yaml:"MaxAge"`
	AllowAllOrigins  bool     `yaml:"AllowAllOrigins"`
	AllowOrigins     []string `yaml:"AllowOrigins"`
	AllowMethods     []string `yaml:"AllowMethods"`
}

Cors配置

type Log

type Log struct {
	LogDir                     string `yaml:"logDir"`
	LogMaxDayCount             int    `yaml:"maxDayCount"`
	LogMongoHookSwitch         bool   `yaml:"logMongoHookSwitch"`
	LogMongoCollection         string `yaml:"logMongoCol"`
	LogMongoExpireAfterSeconds int    `yaml:"logMongoExpire"`
	WithRotationTime           int    `yaml:"withRotationTime"`
}

日志配置

type Mongodb

type Mongodb struct {
	DbHosts  []string `yaml:"dbHosts"`
	DbPorts  []int    `yaml:"dbPorts"`
	DbUser   string   `yaml:"dbUser"`
	DbPasswd string   `yaml:"dbPasswd"`
	DbName   string   `yaml:"dbName"`
}

MongoDB 配置

type Mq

type Mq struct {
	RedisMq `yaml:"redisMq"`
	NatsMq  `yaml:"natsMq"`
}

消息系统配置

type Mysql

type Mysql struct {
	DbHost                  string `yaml:"dbHost"`
	DbPort                  int64  `yaml:"dbPort"`
	DbUser                  string `yaml:"dbUser"`
	DbPasswd                string `yaml:"dbPasswd"`
	DbName                  string `yaml:"dbName"`
	ConnMaxLifetime         int64  `yaml:"connMaxLifetime"`
	MaxIdleConns            int64  `yaml:"maxIdleConns"`
	MaxOpenConns            int64  `yaml:"maxOpenConns"`
	ChartSet                string `yaml:"charset"`
	AllowCleartextPasswords bool   `yaml:"allowCleartextPasswords"`
	InterpolateParams       bool   `yaml:"interpolateParams"`
	Timeout                 int64  `yaml:"timeout"`
	ReadTimeout             int64  `yaml:"readTimeout"`
	ParseTime               bool   `yaml:"parseTime"`
	PING                    bool   `yaml:"ping"`
}

MysqlDB 配置

type NatsMq

type NatsMq struct {
	Switch      bool         `yaml:"switch"`
	NatsServers []NatsServer `yaml:"natsServer"`
}

Nats Mq 消息系统

type NatsServer

type NatsServer struct {
	Host       string `yaml:"host"`
	Port       int    `yaml:"port"`
	AuthSwitch bool   `yaml:"authSwitch"`
	UserName   string `yaml:"userName"`
	Password   string `yaml:"password"`
}

可配集群

type Redis

type Redis struct {
	DbHost      string `yaml:"dbHost"`
	DbPort      int64  `yaml:"dbPort"`
	DbAuth      bool   `yaml:"dbAuth"`
	DbPasswd    string `yaml:"dbPasswd"`
	MaxActive   int64  `yaml:"maxActive"`
	MaxIdle     int64  `yaml:"maxIdle"`
	IdleTimeout int64  `yaml:"idleTimeout"`
}

RedisDB配置

type RedisMq

type RedisMq struct {
	Switch      bool   `yaml:"switch"`
	MaxActive   int    `yaml:"maxActive"`
	MaxIdle     int    `yaml:"maxIdle"`
	IdleTimeout int    `yaml:"idleTimeout"`
	DbHost      string `yaml:"dbHost"`
	DbPort      int    `yaml:"dbPort"`
	DbAuth      bool   `yaml:"dbAuth"`
	DbPasswd    int    `yaml:"dbPasswd"`
}

Redis Pubsub 消息系统

Jump to

Keyboard shortcuts

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