config

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Set         = viper.Set
	Get         = viper.Get
	GetString   = viper.GetString
	GetInt      = viper.GetInt
	GetBool     = viper.GetBool
	GetFloat64  = viper.GetFloat64
	GetDuration = viper.GetDuration
)

Functions

func GetIP

func GetIP() string

GetIP returns the listen IP of the HTTP server.

func GetIPWithDefault

func GetIPWithDefault(defaultIP string) string

GetIPWithDefault returns the listen IP of the HTTP server. If the IP is not set, it returns the default IP.

func GetPort

func GetPort() int

GetPort returns the listen port of the HTTP server.

func GetPortWithDefault

func GetPortWithDefault(defaultPort int) int

GetPortWithDefault returns the port of the HTTP server. If the port is not set, it returns the default port.

func GetTokenAccessDuration

func GetTokenAccessDuration() time.Duration

GetTokenAccessDuration returns the duration of the access token.

func GetTokenRefreshDuration

func GetTokenRefreshDuration() time.Duration

GetTokenRefreshDuration returns the duration of the refresh token.

func GetTokenSymmetricKey

func GetTokenSymmetricKey() string

GetTokenSymmetricKey returns the symmetric key of the token.

func GetVersion

func GetVersion() string

GetVersion returns the version of the application.

func Init

func Init()

Init reads configuration from file or environment variables.

func InitWithPathAndType

func InitWithPathAndType(configPath, configType string)

func IsDebugMode

func IsDebugMode() bool

IsDebugMode returns whether the application is in debug mode.

func SetEnv

func SetEnv(e TypeEnv)

Types

type Config

type Config struct {
	Version    string `mapstructure:"version"`
	DebugMode  bool   `mapstructure:"debug_mode"`
	HTTPServer struct {
		IP   string `mapstructure:"ip"`
		Port int    `mapstructure:"port"`
	} `mapstructure:"http_server"`
	Token struct {
		SymmetricKey    string        `mapstructure:"symmetric_key"`
		AccessDuration  time.Duration `mapstructure:"access_duration"`
		RefreshDuration time.Duration `mapstructure:"refresh_duration"`
	} `mapstructure:"token"`
	MySQL struct {
		Log                 bool          `mapstructure:"log"`
		MaxOpenConnections  int           `mapstructure:"max_open_connections"`
		MaxIdleConnections  int           `mapstructure:"max_idle_connections"`
		MaxLifetimeDuration time.Duration `mapstructure:"max_lifetime_duration"`
		Read                struct {
			Addr     string `mapstructure:"addr"`
			User     string `mapstructure:"user"`
			Password string `mapstructure:"password"`
			Name     string `mapstructure:"name"`
		} `mapstructure:"read"`
		Write struct {
			Addr     string `mapstructure:"addr"`
			User     string `mapstructure:"user"`
			Password string `mapstructure:"password"`
			Name     string `mapstructure:"name"`
		} `mapstructure:"write"`
	} `mapstructure:"mysql"`
}

Config stores configuration of the application. The values are read by viper from a config file or environment variables.

func GetConfig

func GetConfig() *Config

GetConfig returns the configuration of the application.

type TypeEnv

type TypeEnv int
const (
	TypeEnvDev TypeEnv = iota
	TypeEnvTest
	TypeEnvProd
	TypeEnvUnknown
)

func GetEnv

func GetEnv() TypeEnv

func (TypeEnv) String

func (te TypeEnv) String() string

Jump to

Keyboard shortcuts

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