Goconf

Alternatives To Goconf
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
30 Days Of Javascript36,212
a day ago1January 25, 2022251JavaScript
30 days of JavaScript programming challenge is a step-by-step guide to learn JavaScript programming language in 30 days. This challenge may take more than 100 days, please just follow your own pace. These videos may help too: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
Httpie27,8561,6454210 days ago55May 06, 2022146bsd-3-clausePython
🥧 HTTPie for Terminal — modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more.
Cli20,2183,0703,59413 hours ago137September 11, 202246mitGo
A simple, fast, and fun package for building command line apps in Go
Fx16,2831116a month ago47September 15, 202022mitGo
Terminal JSON viewer
Http Prompt8,71771a month ago24March 05, 202153mitPython
An interactive command-line HTTP and API testing client built on top of HTTPie featuring autocomplete, syntax highlighting, and more. https://twitter.com/httpie
Yq8,695435 days ago10February 06, 202074mitGo
yq is a portable command-line YAML, JSON, XML, CSV, TOML and properties processor
Miller7,755
a day ago64March 31, 202295otherGo
Miller is like awk, sed, cut, join, and sort for name-indexed data such as CSV, TSV, and tabular JSON
Structured Text Tools6,672
a month ago15
A list of command line tools for manipulating structured text data
Visidata6,5835511 days ago48December 16, 202181gpl-3.0Python
A terminal spreadsheet multitool for discovering and arranging data
Fq6,580
12 hours ago96August 25, 202240otherGo
jq for binary formats - tool, language and decoders for working with binary and text formats
Alternatives To Goconf
Select To Compare


Alternative Project Comparisons
Readme

[Archived] This repository has been archived,See sandwich-go/xconf instead.

goconf 

Build Status Go Walker GoDoc Go Report CardSourcegraph

Overview

  • Read configuration automatically based on the given struct's field name.
  • Load configuration from multiple sources
  • file inherit

Values are resolved with the following priorities (lowest to highest):

  1. Options struct default value
  2. Flags default value
  3. Config file value, TOML or JSON file
  4. OS Env
  5. Command line flag

About field tags in structs

type TestOptions struct {
    Hosts []string `flag:"hosts" cfg:"hosts" default:"127.0.0.0,127.0.0.1"`
}
  • flag is the name passed from the command line.
  • cfg is the name used in config files.
  • default is the default value

If do not define flag tag, flag will be snake case of the fild name.

If do not define cfg tag, cfg value will be flag value.

For example, flag and cfg will be http_address.

  HTTPAddress string

Usage

load multiple config files

package main

import "github.com/timestee/goconf"

type TestOptions struct {
    goconf.AutoOptions
    HTTPAddress string `default:"0.0.0.0:0000"`
    Hosts []string `flag:"hosts" cfg:"hosts" default:"127.0.0.0,127.0.0.1"`
    LogLevel int `default:"3"`
    BoolVar bool `default:"false"`
}

func main() {
   ops := &TestOptions{}
   goconf.MustResolve(ops,"conf_1.toml","conf_2.toml")
}

go run main.go --log_level=1

The output will be:

[Config] auto flag succ, name: _auto_conf_files_ val:
[Config] auto flag succ, name: http_address val: 0.0.0.0:0000
[Config] auto flag fail, name: hosts val: 127.0.0.0,127.0.0.1 err: type not support []string
[Config] auto flag succ, name: log_level val: 3
[Config] auto flag succ, name: bool_var val: false
[Config] file: [conf_1.toml conf_2.toml]
[Config] load: conf_1.toml
[Config] load: conf_2.toml
[Config]
{
   "AutoConfFiles": "",
   "HTTPAddress": "127.0.0.1:2",
   "Hosts": [
      "10.0.61.29",
      "10.0.61.30",
      "10.0.61.31",
      "10.0.61.32"
   ],
   "LogLevel": 1,
   "BoolVar": true
}

load config file with file inherited

package main

import "github.com/timestee/goconf"

type TestOptions struct {
    goconf.AutoOptions
    HTTPAddress string `default:"0.0.0.0:0000"`
    Hosts []string `flag:"hosts" cfg:"hosts" default:"127.0.0.0,127.0.0.1"`
    LogLevel int `default:"3"`
    BoolVar bool `default:"false"`
}

func main() {
   ops := &TestOptions{}
   // conf_3 inherit from conf_1 and conf_2
   goconf.MustResolve(ops,"conf_3.toml")
}

go run main.go --http_address=0.0.0.0:1111111

The output will be:

[Config] auto flag succ, name: _auto_conf_files_ val:
[Config] auto flag succ, name: http_address val: 0.0.0.0:0000
[Config] auto flag fail, name: hosts val: 127.0.0.0,127.0.0.1 err: type not support []string
[Config] auto flag succ, name: log_level val: 3
[Config] auto flag succ, name: bool_var val: false
[Config] file: [conf_3.toml]
[Config] load: ./conf_1.toml
[Config] load: ./conf_2.toml
[Config] load: conf_3.toml
[Config]
{
   "AutoConfFiles": "",
   "HTTPAddress": "0.0.0.0:1111111",
   "Hosts": [
      "10.0.61.29",
      "10.0.61.30",
      "10.0.61.31",
      "10.0.61.32",
      "10.0.61.33"
   ],
   "LogLevel": 2,
   "BoolVar": true
}
Popular Command Line Projects
Popular Json Projects
Popular Command Line Interface Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Golang
Command Line
Json
Struct
Flags
Toml