1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package config
import (
"context"
"github.com/grindlemire/graft"
"github.com/kelseyhightower/envconfig"
"github.com/pkg/errors"
)
const ID = graft.ID("config")
type Output struct {
Server ServerConfig
}
type ServerConfig struct {
Port int `envconfig:"PORT" default:"4433"`
LocalCerts bool `envconfig:"LOCAL_CERTS" default:"false" split_words:"true"`
}
func init() {
graft.Register(graft.Node[Output]{
ID: ID,
Cacheable: true,
Run: run,
})
}
func run(ctx context.Context) (Output, error) {
var config ServerConfig
err := envconfig.Process("", &config)
if err != nil {
return Output{}, errors.Wrap(err, "loading environment")
}
return Output{
Server: config,
}, nil
}
|