config

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvConfigDir = "GO_CONFIG_DIR"  // Configuration file directory
	EnvService   = "GO_SERVICE_ENV" // Service environment (local/test/prod)
)

Environment variable constants

View Source
const (
	EnvLogDir = "GO_LOGS_DIR"
)

Variables

This section is empty.

Functions

func CloseRedisClient

func CloseRedisClient() error

CloseRedisClient closes Redis connection (call on program exit)

func DefaultDB

func DefaultDB() (*gorm.DB, error)

func Get

func Get(key string) any

func GetBool

func GetBool(key string) bool

func GetFloat64

func GetFloat64(key string) float64

func GetInt

func GetInt(key string) int

func GetLogsDir added in v0.0.3

func GetLogsDir() string

GetLogsDir gets the log directory path Priority: 1. Environment variable GO_LOG_DIR > 2. logger.path in config file > 3. logs in current directory

func GetString

func GetString(key string) string

func GetStringMap

func GetStringMap(key string) map[string]any

func GetStringMapString

func GetStringMapString(key string) map[string]string

func GetStringSlice

func GetStringSlice(key string) []string

func Init added in v0.0.5

func Init()

func IsDebugging

func IsDebugging() bool

func NewDB

func NewDB(name string) (*gorm.DB, error)

func NewRedisClient

func NewRedisClient() *redis.Client

Types

type Config

type Config struct {
	DebugMode bool                `mapstructure:"debug_mode"`
	Logger    LoggerConfig        `mapstructure:"logger"`
	Web       WebConfig           `mapstructure:"web"`
	DB        map[string]DBConfig `mapstructure:"db"`
	Redis     RedisConfig         `mapstructure:"redis"`
}

func GetConfig

func GetConfig() *Config

type DBConfig

type DBConfig struct {
	Driver   string `mapstructure:"driver"` // mysql, postgres
	Host     string `mapstructure:"host"`
	Port     string `mapstructure:"port"`
	User     string `mapstructure:"user"`
	Password string `mapstructure:"password"`
	Name     string `mapstructure:"name"`
	MaxIdle  int    `mapstructure:"max_idle"`
	MaxOpen  int    `mapstructure:"max_open"`
}

type LoggerConfig

type LoggerConfig struct {
	Path    string `mapstructure:"path"`
	Console bool   `mapstructure:"console"`
	Level   string `mapstructure:"level"`
}

type LoggerInstance

type LoggerInstance struct {
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger() *LoggerInstance

func (*LoggerInstance) Debug

func (l *LoggerInstance) Debug(msg string, fields ...zap.Field)

func (*LoggerInstance) Debugf

func (l *LoggerInstance) Debugf(template string, args ...interface{})

func (*LoggerInstance) Error

func (l *LoggerInstance) Error(msg string, fields ...zap.Field)

func (*LoggerInstance) Errorf

func (l *LoggerInstance) Errorf(template string, args ...interface{})

func (*LoggerInstance) Info

func (l *LoggerInstance) Info(msg string, fields ...zap.Field)

func (*LoggerInstance) Infof

func (l *LoggerInstance) Infof(template string, args ...interface{})

type RedisConfig

type RedisConfig struct {
	Host     string
	Port     string
	Password string
	DB       int
}

type WebConfig

type WebConfig struct {
	Host string
	Port int
}

Jump to

Keyboard shortcuts

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