/
main.go
57 lines (43 loc) · 1.1 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"path/filepath"
"github.com/buddhamagnet/houseofcards/web"
"github.com/EconomistDigitalSolutions/watchman/journal"
_ "github.com/EconomistDigitalSolutions/watchman/meter"
"github.com/buddhamagnet/goconsul"
)
var (
port string
buildstamp string
githash string
version string
serviceName string
)
func init() {
flag.StringVar(&port, "port", ":9494", "port to listen on")
flag.StringVar(&version, "version", "", "output build date and commit data")
serviceName = os.Getenv("SERVICE_NAME")
if serviceName == "" {
serviceName = filepath.Base(os.Args[0])
}
journal.Service = serviceName
}
func main() {
if os.Getenv("SERVICE_REGISTRATION") == "1" {
if err := goconsul.RegisterService(); err != nil {
log.Fatal(err)
}
}
flag.Parse()
web.NewRouter(buildstamp, githash)
if version != "" {
journal.LogChannel("build", fmt.Sprintf("build date: %s commit: %s", buildstamp, githash))
}
journal.LogChannel("information", fmt.Sprintf("%s up on port %s", serviceName, port))
log.Fatal(http.ListenAndServe(port, nil))
}