aboutsummaryrefslogtreecommitdiff
path: root/main.go
blob: 165cacb07686f2ecfa831df6b148256edc31cac2 (plain)
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
package main

import (
	"sync"

	"git.capotej.com/capotej/communique/cgi"
	"git.capotej.com/capotej/communique/config"
	"git.capotej.com/capotej/communique/http"
	"git.capotej.com/capotej/communique/registry"
	"github.com/BurntSushi/toml"
	"go.uber.org/zap"
	"go.uber.org/zap/zapio"
)

func main() {
	// ctx := context.Background()
	// Logger
	logger, _ := zap.NewDevelopment()
	defer logger.Sync() // flushes buffer, if any
	log := logger.Sugar()

	// Config
	var cfg config.Config
	//TODO use a flag here
	_, err := toml.DecodeFile("sample-config.toml", &cfg)
	if err != nil {
		log.Fatal(err)
	}
	log.Debugf("Loaded TOML Config: %+v", cfg)
	registry := registry.NewRegistry(cfg)

	var mainWg sync.WaitGroup

	// Internal CGI Servers
	cgiServers := cgi.NewServers()
	mainWg.Add(1)
	go cgiServers.Start(cfg)

	// External Http Server
	writer := &zapio.Writer{Log: logger, Level: zap.DebugLevel}
	defer writer.Close()
	server := http.NewServer(registry)
	mainWg.Add(1)
	go server.Start(writer)

	mainWg.Wait()
}