start on api

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
Evan Hazlett 2017-07-29 10:11:50 -04:00
parent 2c1baa96bb
commit 7574b334cc
No known key found for this signature in database
GPG key ID: A519480096146526
364 changed files with 166263 additions and 1 deletions

7
config/config.go Normal file
View file

@ -0,0 +1,7 @@
package config
// Config is the top level configuration
type Config struct {
ListenAddr string
EnableMetrics bool
}

15
config/utils.go Normal file
View file

@ -0,0 +1,15 @@
package config
import (
"github.com/BurntSushi/toml"
)
// ParseConfig returns a Config object from a raw string config TOML
func ParseConfig(data string) (*Config, error) {
var cfg Config
if _, err := toml.Decode(data, &cfg); err != nil {
return nil, err
}
return &cfg, nil
}

22
config/utils_test.go Normal file
View file

@ -0,0 +1,22 @@
package config
import (
"testing"
)
var (
sampleConfig = `
ListenAddr = ":8080"
`
)
func TestParseConfig(t *testing.T) {
cfg, err := ParseConfig(sampleConfig)
if err != nil {
t.Fatalf("error parsing config: %s", err)
}
if cfg.ListenAddr != ":8080" {
t.Fatalf("expected listen addr :8080; received %s", cfg.ListenAddr)
}
}