config

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Watcher

func Watcher(filename string, handler func(cfg *Config))

Auto reload config. copy from https://github.com/spf13/viper/blob/v1.12.0/viper.go#L431

Types

type App

type App struct {
	Name      string `env-required:"true" yaml:"name"    env:"APP_NAME"`
	Debug     bool   `yaml:"debug" env:"APP_DEBUG"`
	SuperUser string `env-required:"true" yaml:"superUser" env:"APP_SUPER_USER"`
	// Please changed when app first started.
	SuperPassword string `env-required:"true" yaml:"superPassword" env:"APP_SUPER_PASSWORD"`
}

App -.

type Config

type Config struct {
	App   `yaml:"app"`
	HTTP  `yaml:"http"`
	Log   `yaml:"log"`
	MySQL `yaml:"mysql"` //nolint: tagliatelle
	Redis `yaml:"redis"`
}

Config -.

func GetConfig

func GetConfig() *Config

func LoadConfig

func LoadConfig(cfgFile string) (*Config, error)

default cfg file: "./config/config.yml".

type HTTP

type HTTP struct {
	Port string `env-required:"true" yaml:"port" env:"HTTP_PORT"`
}

HTTP -.

type Log

type Log struct {
	// debug, info, warn, error
	Level string `env-required:"true" yaml:"level"   env:"LOG_LEVEL"`
	// output format, json/text
	Format string `env-required:"true" yaml:"format"  env:"LOG_FORMAT"`
	// nocolor, default false
	NoColor bool `yaml:"noColor" env:"LOG_NOCOLOR"`
}

Log -.

type MySQL

type MySQL struct {
	// https://github.com/go-sql-driver/mysql#dsn-data-source-name
	DSN string `env-required:"true"                 env:"MYSQL_DSN"`
	// https://github.com/go-sql-driver/mysql#important-settings
	ConnMaxLifetime int `env-required:"true" yaml:"connMaxLifetime" env:"MYSQL_CONN_MAX_LIFETIME"`
	MaxOpenConns    int `env-required:"true" yaml:"maxOpenConns"     env:"MYSQL_MAX_OPEN_CONNS"`
	MaxIdleConns    int `env-required:"true" yaml:"maxIdleConns"     env:"MYSQL_MAX_IDLE_CONNS"`
}

MySQL -.

type Redis

type Redis struct {
	// "redis://<user>:<pass>@localhost:6379/<db>"
	URL string `env-required:"true"                            env:"REDIS_URL"`
}

Redis -.

Jump to

Keyboard shortcuts

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