golang config struct loader
Go to file
Jay 5629dbc1af
continuous-integration/drone/push Build is passing Details
Merge pull request 'bump version and changelog' (#5) from release/v1.0.1 into develop
2020-06-11 03:22:20 +00:00
test first version 2020-06-05 10:11:45 +00:00
.drone.yml [feat] add ci config 2020-06-05 14:34:19 +00:00
.gitignore [chore] add ignore file 2020-06-11 03:04:06 +00:00
CHANGELOG.md bump version and changelog 2020-06-11 03:06:43 +00:00
README.md [feat] add ci config 2020-06-05 14:34:19 +00:00
go.mod [feat] add load opts fromEnv 2020-06-11 02:57:46 +00:00
go.sum [feat] add load opts fromEnv 2020-06-11 02:57:46 +00:00
loader.go [feat] add load opts fromEnv 2020-06-11 02:57:46 +00:00
loader_test.go [fix] fix type error 2020-06-11 03:03:35 +00:00

README.md

Config Loader

Build Status

Install

go get -u git.trj.tw/golang/config-loader

Usage

struct tag

default : default value define

length : use for slice type min default length

support type

  • string
  • int, int8, int16, int32, int64
  • uint, uint8, uint16, uint32, uint64
  • float32, float64
  • bool
  • struct
  • slice
    • []string
    • []int, []int8, []int16, []int32, []int64
    • []uint, []uint8, []uint16, []uint32, []uint64
    • []float32, []float64
    • []bool
    • []struct

example

package main

import (
  "fmt"
  "log"

  confloader "git.trj.tw/golang/config-loader"
)

type Server struct {
  Port int `json:"port" default:"10230"`
}
type Config struct {
  Server     Server
  Switchs    []int  `json:"switchs" default:"1" length:"2"`
  URL        string `json:"url" default:"https://google.com"`
  OutputFile bool   `json:"output_file" default:"true"`
}

func main() {
  conf := &Config{}
  if err := confloader.Load(conf, nil); err != nil {
    log.Fatal(err)
  }

  fmt.Println(conf)
}