-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
56 lines (47 loc) · 1.33 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
package main
import (
"crypto/tls"
"flag"
"fmt"
"github.com/aon1/slack-horoscope/config"
"github.com/aon1/slack-horoscope/handlers"
"github.com/aon1/slack-horoscope/server"
"github.com/aon1/slack-horoscope/services"
horoscopeService "github.com/aon1/slack-horoscope/services/babi.hefesto.io"
"github.com/aon1/slack-horoscope/services/restclient"
"log"
"net/http"
"os"
)
func main() {
var (
api handlers.API
service services.Services
restClient restclient.RestClient
)
confFile := flag.String("config", "config.yml", "specify the config file to use")
conf, err := config.New(*confFile)
if err != nil {
log.Fatalf("unable to parse configuration file: %v", err)
}
service, err = horoscopeService.New(restClient, conf.HoroscopeServices.BabiHefestoIO)
if err != nil {
log.Fatalf("unable to start horoscope service: %v", err)
}
api, err = handlers.New(service)
if err != nil {
log.Fatalf("unable to create handlers: %v", err)
}
s, err := server.New(api)
if err != nil {
log.Fatalf("error initializing server: %v", err)
}
port := map[bool]string{true: os.Getenv("PORT"), false: "3000"}[ os.Getenv("PORT") != ""]
srv := &http.Server{
Addr: fmt.Sprintf(":%v", port),
Handler: s,
TLSConfig: &tls.Config{},
}
log.Printf("Starting server over http on port: %v", port)
log.Fatal(srv.ListenAndServe())
}