Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

silalahi/configs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Configs

Build Status GoDoc Build Status

Package config provides convenient access methods to configuration stored as JSON. This is a simplified library from this

Usage

Example JSON configuration:

{
  "development":  {
      "database": {
          "host":"localhost",
          "username":"root",
          "password":"12345",
          "port":12345,
          "name":"dev"
        }
    },
    "production": {
      "database":{
        "host":"localhost",
        "username":"root",
        "password":"12345",
        "port":12345,
        "name":"dev"
      }
    }
}

We can load the JSON configuration file by using:

cfg, err := Load("/path/to/config.json")
if err != nil {
  panic(err)
}

And we can change root path by using:

// Get development environment configuration
cfg, err = cfg.Get("development")
if err != nil {
  panic(err)
}

Get configuration value by using:

// Get database host or return empty string if not exists
host := cfg.UString("database.host")

// Get database host or return default passed value if not exists
host := cfg.UString("database.host", "default")

// Get database host and error
host, err := cfg.String("database.host")

These are all method to get configuration value:

// Load reads a JSON configuration from given filename
func Load

// Get returns a nested config according to a dotted path.
func (*Config) Get

// Return single value or default
func (*Config) UBool
func (*Config) UFloat64
func (*Config) UInt
func (*Config) UList
func (*Config) UMap
func (*Config) UString

// Return value and error
func (*Config) Bool
func (*Config) Float64
func (*Config) Int
func (*Config) List
func (*Config) Map
func (*Config) String

See documentation in GoDoc for more detail

About

A Go library to load configuration stored as JSON file

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%