...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package main
16
17 import (
18 "io/ioutil"
19
20 "github.com/palantir/go-baseapp/baseapp"
21 "github.com/palantir/go-baseapp/baseapp/datadog"
22 "github.com/pkg/errors"
23 "gopkg.in/yaml.v2"
24 )
25
26 type Config struct {
27 Server baseapp.HTTPConfig `yaml:"server"`
28 Datadog datadog.Config `yaml:"datadog"`
29 Logging baseapp.LoggingConfig `yaml:"logging"`
30
31 App AppConfig `yaml:"app"`
32 }
33
34 type AppConfig struct {
35 Message string `yaml:"message"`
36 }
37
38 func ReadConfig(path string) (Config, error) {
39 var c Config
40
41 bytes, err := ioutil.ReadFile(path)
42 if err != nil {
43 return c, errors.Wrapf(err, "failed reading server config file: %s", path)
44 }
45
46 if err := yaml.UnmarshalStrict(bytes, &c); err != nil {
47 return c, errors.Wrap(err, "failed parsing configuration file")
48 }
49
50 return c, nil
51 }
52
View as plain text