-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
51 lines (40 loc) · 1.23 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
package main
import (
"flag"
"fmt"
"log"
"net"
"net/http"
"os"
"code.cloudfoundry.org/lager"
"github.com/alphagov/paas-aiven-broker/broker"
"github.com/alphagov/paas-aiven-broker/provider"
)
var configFilePath string
func main() {
flag.StringVar(&configFilePath, "config", "./config.json", "Location of the config file")
flag.Parse()
file, err := os.Open(configFilePath)
if err != nil {
log.Fatalf("Error opening config file %s: %s\n", configFilePath, err)
}
defer file.Close()
config, err := broker.NewConfig(file)
if err != nil {
log.Fatalf("Error validating config file: %v\n", err)
}
aivenProvider, err := provider.New(config.Provider)
if err != nil {
log.Fatalf("Error creating Aiven provider: %v\n", err)
}
logger := lager.NewLogger("aiven-service-broker")
logger.RegisterSink(lager.NewWriterSink(os.Stdout, config.API.LagerLogLevel))
aivenBroker := broker.New(config, aivenProvider, logger)
brokerServer := broker.NewAPI(aivenBroker, logger, config)
listener, err := net.Listen("tcp", ":"+config.API.Port)
if err != nil {
log.Fatalf("Error listening to port %s: %s", config.API.Port, err)
}
fmt.Println("Aiven service broker started on port " + config.API.Port + "...")
http.Serve(listener, brokerServer)
}