rcrowley / go-tigertonic

A Go framework for building JSON web services inspired by Dropwizard

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dropwizard-like configuration file parser

rcrowley opened this issue · comments

@mihasya's favorite thing about Dropwizard is the way configuration classes are declared and instantiated from YAML files. The flags package notwithstanding, Tiger Tonic should really have the same.

The example configuration loader from the Boundary's Comparing Go and Java blog post is pretty simple and perhaps a good start:

type Config struct {
  Db struct {
    Name     string
    User     string
    Password string
  }
}

func ReadConfig() Config {
  if len(os.Args) != 2 {
    log.Fatal("You must supply a configuration filename")
  }
  filename := os.Args[1]
  bytes, err := ioutil.ReadFile(filename)
  if err != nil {
    panic(err)
  }
  var c Config
  err = json.Unmarshal(bytes, &c)
  if err != nil {
    panic(err)
  }
  return c
}

It's impressive that you've read the entire Internet, @wadey.

And yes, that's an excellent start. I'd probably want to add support for non-zero default values by way of a tag.

@wadey @mihasya is this too stupid and simple? It's usefulness is, I bet, rather tied to per-request context in #27.

I would prefer some sort of abstraction with a json impl that is easy enough to swap out for something like yml. Not sure you care :D I can try and come up with a way to do this if you'd like, not sure when I'll actually get to it

@mihasya How's this new change strike you?

AYE! 🤘 ✊ 🚬