config

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: BSD-3-Clause Imports: 5 Imported by: 1

README

Config Resolver

Updating the config through resolver variables.

Config example

update config via ENV

@env(key#defaut value)
envs:
  home: "@env(HOME#/tmp/home)"
  path: "@env(PATH#/usr/local/bin)"
import (
  "go.osspkg.com/goppy/config"
)

type (
  ConfigItem struct {
    Home string `yaml:"home"`
    Path string `yaml:"path"`
  }
  Config struct {
    Envs testConfigItem `yaml:"envs"`
  }
)

func main() {
  conf := Config{}
  
  res := config.NewConfigResolve(
    config.EnvResolver(), // env resolver 
  )
  res.OpenFile("./config.yaml") // open config file
  res.Build() // prepare config with resolvers
  res.Decode(&conf) // decoding config
  
  fmt.Println(conf.Envs.Home)
  fmt.Println(conf.Envs.Path)
}

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 New added in v0.0.3

func New(rs ...Resolver) *Config

func (*Config) Build

func (v *Config) Build() error

func (*Config) Decode

func (v *Config) Decode(cs ...interface{}) error

func (*Config) OpenFile

func (v *Config) OpenFile(filename string) error

type Resolver

type Resolver interface {
	Name() string
	Value(name string) (string, bool)
}

func EnvResolver

func EnvResolver() Resolver

Jump to

Keyboard shortcuts

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