golang config struct loader
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
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
3 years ago
test first version 3 years ago
.drone.yml [feat] add ci config 3 years ago
.gitignore [chore] add ignore file 3 years ago
CHANGELOG.md bump version and changelog 3 years ago
README.md [feat] add ci config 3 years ago
go.mod [feat] add load opts fromEnv 3 years ago
go.sum [feat] add load opts fromEnv 3 years ago
loader.go [feat] add load opts fromEnv 3 years ago
loader_test.go [fix] fix type error 3 years ago


Config Loader

Build Status


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


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


package main

import (

  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 {