kconfig

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: MIT Imports: 9 Imported by: 0

README

Kconfig

Yaml file my-file.yaml:

addr: ":8080"
database:
  use: true
  dialect: "postgres"
  timeout: 12
  secret: env[SECRET_PASS|super-secret]
list: 
  - "first"
  - "second"
  - "third"
gtm: "env[GTM_ENV]"

Usage:

import "github.com/krstak/kconfig"

c, err := kconfig.Load("./my-file.yaml")

// returns string ":8080"
c.Get("addr")

// returns bool true
c.GetBool("database.use")

// returns string "postgres"
c.Get("database.dialect")

// returns int 12
c.GetInt("database.timeout")

// returns slice []string{"first", "second", "third"}
c.GetSlice("list")

// returns a value of environment variable GTM_ENV as a string
c.Get("gtm")

// returns a value of environment variable SECRET_PASS as a string. If not exists, it returns a default value super-secret
c.Get("database.secret")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

func Load

func Load(path string) (Config, error)

func LoadContent added in v0.3.0

func LoadContent(content []byte) (Config, error)

func (Config) Get

func (c Config) Get(key string) string

func (Config) GetBool added in v0.1.2

func (c Config) GetBool(key string) bool

func (Config) GetInt

func (c Config) GetInt(key string) int

func (Config) GetSlice

func (c Config) GetSlice(key string) []string

func (Config) GetX added in v0.2.0

func (c Config) GetX(key string, v interface{}) error

Jump to

Keyboard shortcuts

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