-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
45 lines (36 loc) · 892 Bytes
/
main.go
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
44
45
package main
import (
"os"
"os/signal"
envconfig "github.com/kelseyhightower/envconfig"
log "github.com/sirupsen/logrus"
)
/*
Config is
ENVIRONMENT VARIABLES:
-----------------------------
Set values via env variables, prefixed with ERRANDS_
eg:
ERRANDS_PORT=:4545 - Will change the listening port to 4545
ERRANDS_STORAGE="/errands/" - Will change the DB location to /errands/
*/
type Config struct {
Storage string `split_words:"true" default:"./errands.db"`
Port string `split_words:"true" default:":5555"`
}
func main() {
// Parse Env Vars:
var cfg Config
err := envconfig.Process("ERRANDS", &cfg)
if err != nil {
log.Fatal(err)
}
// trap SIGINT to trigger a shutdown.
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt)
server := NewErrandsServer(&cfg)
log.Info("listening for signals")
<-signals
log.Info("Exiting")
server.kill()
}