start on api
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
parent
2c1baa96bb
commit
7574b334cc
364 changed files with 166263 additions and 1 deletions
7
config/config.go
Normal file
7
config/config.go
Normal 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
15
config/utils.go
Normal 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
22
config/utils_test.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue