forked from Mistobaan/env
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal.go
More file actions
30 lines (26 loc) · 669 Bytes
/
local.go
File metadata and controls
30 lines (26 loc) · 669 Bytes
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
package main
import (
"fmt"
env "github.com/danryan/env"
"github.com/davecgh/go-spew/spew"
)
var _ = spew.Sdump()
type Config struct {
Name string `env:"key=NAME required"`
Port int `env:"key=PORT default=9000"`
Adapter string `env:"key=ADAPTER default=shell in=shell,slack,hipchat"`
Enabled bool //`env:"key=IS_ENABLED default=true"`
}
// HAL_NAME=hal
// HAL_PORT=
// HAL_ADAPTER=
func main() {
// os.Setenv("IS_ENABLED", "asdf")
c := &Config{}
if err := env.Process(c); err != nil {
fmt.Println("error:", err)
return
// panic(err)
}
fmt.Printf("name: %s, port: %d, adapter: %s, enabled: %v\n", c.Name, c.Port, c.Adapter, c.Enabled)
}