Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/paultag/go-config


https://github.com/paultag/go-config

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

pault.ag/go/config
==================

This package allows you define structs which both define the configuration
file format, and command line flags.

```go
package main

import (
"fmt"
"os"

"pault.ag/go/config"
)

type Example struct {
Option string `flag:"option" description:"This sets all sorts of things"`
Value int `flag:"value" description:"This is an integer value!"`
}

func main() {
conf := Example{
Option: "default",
}
flags, err := config.LoadFlags("example", &conf)
// This will load the RFC822 formatted config from ~/.examplerc and
// return a flag.FlagSet. The Flags will be populated by defaults from
// the struct given.
if err != nil {
panic(err)
}
flags.Parse(os.Args[1:])
fmt.Printf("option %s, value %d\n", conf.Option, conf.Value)
}
```