config

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

README

Config Package

Overview

The config package manages configurations in Go applications, ensuring compatibility between config.yaml and setup.env. setup.env is used to setup environment variables.

Note - When both environment variables and config.yaml settings are present, the package prioritizes environment variables, overriding equivalent settings in config.yaml.

Compatible configurations example

The below configurations are compatible in this project.

  • setup.env contains:

    export LOGFILE_PATH=log/damselfly.log
    
  • config.yaml has:

    logfile:
      path: log/damselfly.log
    

How to use it

  • Use a blank import in your package (e.g., main, logger, and so on)
  • Get a value using Viper

Note - It's just my preference. config.Init() can be used.

import (
    // other packages

    // Loads configurations from setup.env and config.yaml
    _ "github.com/cloud-barista/cm-damselfly/pkg/config"
)

func main() {
    logFilePath := viper.GetString("damselfly.logfile.path")
    // Application logic follows
}

Wrapping Up

This setup illustrates the package's ability to harmonize settings from both setup.env and config.yaml, showcasing its versatility and ease of use.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RuntimeConfig Config
	Damselfly     DamselflyConfig
)

Functions

func Init

func Init()

func NVL

func NVL(str string, def string) string

NVL is func for null value logic

Types

type AllowConfig

type AllowConfig struct {
	Origins string `mapstructure:"origins"`
}

type ApiConfig

type ApiConfig struct {
	Allow    AllowConfig `mapstructure:"allow"`
	Auth     AuthConfig  `mapstructure:"auth"`
	Username string      `mapstructure:"username"`
	Password string      `mapstructure:"password"`
}

type AuthConfig

type AuthConfig struct {
	Enabled bool `mapstructure:"enabled"`
}

type AutoControlConfig

type AutoControlConfig struct {
	DurationMilliSec int `mapstructure:"duration_ms"`
}

type Config

type Config struct {
	Damselfly DamselflyConfig `mapstructure:"damselfly"`
}

type DamselflyConfig

type DamselflyConfig struct {
	Root        string            `mapstructure:"root"`
	Self        SelfConfig        `mapstructure:"self"`
	API         ApiConfig         `mapstructure:"api"`
	LKVStore    LkvStoreConfig    `mapstructure:"lkvstore"`
	LogFile     LogfileConfig     `mapstructure:"logfile"`
	LogLevel    string            `mapstructure:"loglevel"`
	LogWriter   string            `mapstructure:"logwriter"`
	Node        NodeConfig        `mapstructure:"node"`
	AutoControl AutoControlConfig `mapstructure:"autocontrol"`
}

type LkvStoreConfig

type LkvStoreConfig struct {
	Path string `mapstructure:"path"`
}

type LogfileConfig

type LogfileConfig struct {
	Path       string `mapstructure:"path"`
	MaxSize    int    `mapstructure:"maxsize"`
	MaxBackups int    `mapstructure:"maxbackups"`
	MaxAge     int    `mapstructure:"maxage"`
	Compress   bool   `mapstructure:"compress"`
}

type NodeConfig

type NodeConfig struct {
	Env string `mapstructure:"env"`
}

type SelfConfig

type SelfConfig struct {
	Endpoint string `mapstructure:"endpoint"`
}

Jump to

Keyboard shortcuts

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