<commit_before>
[![GoDoc](https://godoc.org/github.com/tj/go-config?status.svg)](http://godoc.org/github.com/tj/go-config)
[![Build Status](https://travis-ci.org/tj/go-config.svg?branch=master)](https://travis-ci.org/tj/go-config)

# go-config

 Simpler Go configuration with structs.

## Features

- Declare configuration with structs and tags
- Type coercion out of the box
- Validation out of the box
- Pluggable resolvers
- Built-in resolvers (flag, env)
- Unambiguous resolution (must be specified via `from`)

## Example

Source:

```go
package main

import (
  "log"
  "os"
  "time"

  "github.com/tj/go-config"
)

type Options struct {
  Timeout     time.Duration `desc:"message timeout"`
  Concurrency uint          `desc:"message concurrency"`
  CacheSize   config.Bytes  `desc:"cache size in bytes"`
  BatchSize   uint          `desc:"batch size" validate:"min=1,max=1000"`
  LogLevel    string        `desc:"log severity level" from:"env,flag"`
}

var options = &Options{
  Timeout:     time.Second * 5,
  Concurrency: 10,
  CacheSize:   config.ParseBytes("100mb"),
  BatchSize:   250,
}

func main() {
  config.MustResolve(options)
  log.Printf("%+v", options)
}
```

Command-line:

```
$ LOG_LEVEL=error example --timeout 10s --concurrenct 100 --cache-size 1gb<commit_msg>README: don't use global variables<commit_after>
[![GoDoc](https://godoc.org/github.com/tj/go-config?status.svg)](http://godoc.org/github.com/tj/go-config)
[![Build Status](https://travis-ci.org/tj/go-config.svg?branch=master)](https://travis-ci.org/tj/go-config)

# go-config

Simpler Go configuration with structs.

## Features

- Declare configuration with structs and tags
- Type coercion out of the box
- Validation out of the box
- Pluggable resolvers
- Built-in resolvers (flag, env)
- Unambiguous resolution (must be specified via `from`)

## Example

Source:

```go
package main

import (
	"log"
	"os"
	"time"

	"github.com/tj/go-config"
)

type Options struct {
	Timeout     time.Duration `desc:"message timeout"`
	Concurrency uint          `desc:"message concurrency"`
	CacheSize   config.Bytes  `desc:"cache size in bytes"`
	BatchSize   uint          `desc:"batch size" validate:"min=1,max=1000"`
	LogLevel    string        `desc:"log severity level" from:"env,flag"`
}

var
func main() {
	options = Options{
		Timeout:     time.Second * 5,
		Concurrency: 10,
		CacheSize:   config.ParseBytes("100mb"),
		BatchSize:   250,
	}
	config.MustResolve(&options)
	log.Printf("%+v", options)
}
```

Command-line:

```
$ LOG_LEVEL=error example --timeout 10s --concurrency 100 --cache-size 1gb
{'fraction_non_alphanumeric': 0.14717273431448488, 'fraction_numerical': 0.015491866769945779, 'mean_word_length': 3.765682656826568, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '848162', 'n_tokens_mistral': 940, 'n_tokens_neox': 881, 'n_words': 213}