Skip to content

PeteChu/gojsonconf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gojsonconf

Introduction

This package is a simple json configuration decoder into struct.

Installation

go get github.com/petechu/gojsonconf

Usage

Example 1

Configuration file:

// conf.json
{
  "Port": "3000",
  "Host": "example.com"
}

Code:

type Conf Struct {
    Port string
    Host string
}

conf := Conf{}
err := gojsonconf.GetConfig("conf.json", &conf)
if err != nil {
  // do something
}

fmt.Println(conf.Port) // 3000
fmt.Println(conf.Host) // example.com

Example 2

Configuration file:

// conf.json
{
  "port": "3000",
  "host": "example.com"
}

Code:

type Conf Struct {
    Port string `json:"port"`
    Host string `json:"host"`
}

conf := Conf{}
err := gojsonconf.GetConfig("conf.json", &conf)
if err != nil {
  // do something
}

fmt.Println(conf.Port) // 3000
fmt.Println(conf.Host) // example.com

About

A Golang package to read JSON configuration file.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages