config

package
v0.0.0-...-e8a8f99 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2020 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AppName app name.
	AppName = "Galaxy"
	// VERSION mark app version.
	VERSION = "0.0.1"
	// AppLogLevel log level.
	AppLogLevel = "GALAXY_LOGLEVEL"
)
View Source
const (
	// MySQLDSNFormat string format
	MySQLDSNFormat = "%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=true&loc=Local"
)

Variables

View Source
var (

	// NodeID mark for current node.
	NodeID string
	// ServerStartAt Cache server start unix time.
	ServerStartAt uint64
)
View Source
var (

	// Default writes to First-Level path while not found any config file.
	Default = Config{
		MySQLConfig: DBConfig{
			User:     "lance",
			Password: "Lancexu@1992",
			Host:     "localhost",
			Port:     3306,
			Database: "galaxy_test",
		},
		App: App{
			AppName: AppName,
			Version: VERSION,
		},
	}
)

Functions

func GetLogLevel

func GetLogLevel() string

GetLogLevel returns log level of current app.

func GetNodeID

func GetNodeID() string

GetNodeID reads NodeID safely.

func GetServerStartAt

func GetServerStartAt() uint64

GetServerStartAt reads ServerStartAt.

func InitialiseSystem

func InitialiseSystem() error

InitialiseSystem done all things about app runtime env configurationss.

func IsRunningTests

func IsRunningTests() bool

IsRunningTests returns true if current system is test mode.

func Load

func Load(paths []string, conf *Config) error

Load will load a configuration file, trying each of the paths given and using the first one that is a regular file and can be opened.

If none exists, a default config will be written to the first path in the list.

An error will be returned only if any of the paths existed but was not a valid config file.

func SetGlobal

func SetGlobal(conf Config)

SetGlobal store global config to atomic.Value

func SetNodeID

func SetNodeID(nodeID string)

SetNodeID writes NodeID safely.

func SetServerStartAt

func SetServerStartAt(st uint64)

SetServerStartAt writes ServerStartAt safely.

func SetTestMode

func SetTestMode(v bool)

SetTestMode for unitest case.

func WriteConf

func WriteConf(path string, conf *Config) error

WriteConf writes conf to specific file.

func WriteDefault

func WriteDefault(path string, conf *Config) error

WriteDefault will set conf to the default config and write it to disk in path, if the path is non-empty.

Types

type App

type App struct {
	AppName string `json:"appName"`
	Version string `json:"version"`
	StartAt uint64 `json:"startAt"`
	NodeID  string `json:"nodeID"`
}

App cache node info.

func GetApp

func GetApp() App

GetApp returns app info.

type Config

type Config struct {
	// OriginalPath is the path to the config file that was read. If
	// none was found, it's the path to the default config file that
	// was written.
	OriginalPath    string `json:"-"`
	TemplatePath    string `json:"template_path"`
	PIDFileLocation string `json:"pid_file_location"`

	LivenessCheck LivenessCheckConfig `json:"liveness_check"`

	MySQLConfig DBConfig `json:"mysql_config"`

	App App `json:"app"`
}

Config global configs.

func Global

func Global() Config

Global returns global config from atomic.Value

type DBConfig

type DBConfig struct {
	User     string `json:"user"`
	Password string `json:"password"`
	Host     string `json:"host"`
	Port     int    `json:"port"`
	Database string `json:"database"`
}

DBConfig defines for DB connection.

func (DBConfig) DSNFormat

func (c DBConfig) DSNFormat() string

DSNFormat returns builder dsn string.

type LivenessCheckConfig

type LivenessCheckConfig struct {
	CheckDuration time.Duration `json:"check_duration"`
}

LivenessCheckConfig liveness check duration.

Jump to

Keyboard shortcuts

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