conf

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2021 License: MIT Imports: 7 Imported by: 0

README

conf

conf package detect file format automatically by It's extension

installation

go get github.com/gilsuk/conf

usage

config.json

{
  "LogLevel": "production",
  "MaxAllowed": 10,
  "Port": 8080
}

config.yaml

LogLevel: "production"
MaxAllowed: 10
Port: 8080
type configuration struct {
    LogLevel string
    MaxAllowed  int
    Port int
}

confWithDefault := &configuration{
    LogLevel: "debug",
    MaxAllowed: 5,
    Port: 3000,
}

// out default config values to a file for example
conf.Out("config_example.json", confWithDefault)
conf.Out("config_example.json", confWithDefault)

// load config values from a file
// after loaded, config values are overrided
conf.Load("config.json", confWithDefault)
conf.Load("config.yaml", confWithDefault)

fmt.Printf("%+v", *confWithDefault)

output

{LogLevel:production MaxAllowed:10 Port:8080}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(path string, confStruct interface{}) error

func Out

func Out(path string, confStruct interface{}) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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