xconfig

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 15 Imported by: 0

README

config

Load config into go struct from shell environment and docker/k8s secrets.

Quick Start

package main

type Settings struct {
	AppName string `default:"default_app"` // testing snake env APP_NAME
	DB      struct {
		Name     string `default:"default_name"`             // testing default
		User     string `default:"default_user"`             // testing env
		Password string `default:"default_pwd"`              // testing secret
		Port     int    `default:"3306" env:"MYSQL_DB_PORT"` // testing int and custom env name
	}
}

func main() {
    var settings = new(Settings)
    xconfig.MustLoad(settings)
    fmt.Printf("%+v",settings)
}

Documentation

Overview

Package xconfig can load config from shell env variables, aws ssm and docker/k8s secrets.

Index

Constants

View Source
const (
	EnvLocal       = "local"
	EnvProduction  = "production" // this env only use in metric-related projects
	EnvTestnetDev  = "testnet-dev"
	EnvTestnetProd = "testnet-prod"
)
View Source
const AwsSsmParamStorePath = "AWS_SSM_PARAM_STORE_PATH"

AwsSsmParamStorePath the environment variable name for AWS SSM Param Store

Variables

This section is empty.

Functions

func Load

func Load(dst interface{}) error

Load config to `dst` struct pointer from shell env variables and docker secrets.

func LoadEnv

func LoadEnv(dst interface{}) error

LoadEnv load config to `dst` struct pointer from shell env variables only

func LoadEnvAndAwsSsm

func LoadEnvAndAwsSsm(dst interface{}, path string) error

LoadEnvAndAwsSsm load config to `dst` struct pointer from shell env variables and aws ssm param store.

func LoadEnvAndDockerSecret

func LoadEnvAndDockerSecret(dst interface{}) error

LoadEnvAndDockerSecret load config to `dst` struct pointer from shell env variables and docker secrets.

func LoadEnvAndSecret

func LoadEnvAndSecret(dst interface{}, secretPath string) error

LoadEnvAndSecret load config to `dst` struct pointer from shell env variables and container secrets.

func MustLoad

func MustLoad(dst interface{})

MustLoad just same as Load(), but it panics when an error occurs.

func SetAwsConfig

func SetAwsConfig(config *aws.Config)

SetAwsConfig if you want load config from aws ssm parameter store, you can set aws config manually. If it is not set, it will try to use default aws config, only when AWS_SSM_PARAM_STORE_PATH is set .

Types

type AwsSsmParamStore

type AwsSsmParamStore struct {
	Path string
}

AwsSsmParamStore is used in config struct, it will load AWS_SSM_PARAM_STORE_PATH from ENV

type Basic

type Basic struct {
	Env     string `default:"local"`
	Debug   bool   `default:"false"`
	Release string `default:"local-debug"` // github build number, injected in image by github action
	// slack config is optional, if exists, it will send all warn/error log to slack
	SlackToken   string
	SlackChannel string `default:"C076H0HBZLZ"` // default is channel testnet-dev
}

Basic is the shared basic configuration for all projects

func (Basic) GenLogger

func (b Basic) GenLogger() *slog.Logger

GenLogger generates a logger based on the environment and configuration

Jump to

Keyboard shortcuts

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