forked from RackHD/ipam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (60 loc) · 1.52 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"flag"
"log"
"net/http"
"os"
"github.com/RackHD/ipam/controllers"
"github.com/RackHD/ipam/ipam"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"gopkg.in/mgo.v2"
)
var mongo string
func init() {
flag.StringVar(&mongo, "mongo", "ipam_mongo:27017", "port to connect to mongodb container")
}
func main() {
flag.Parse()
// Default to enable mgo debug. Set to false to disable.
var mgoDebug = true
if mgoDebug {
mgo.SetDebug(true)
var aLogger *log.Logger
aLogger = log.New(os.Stderr, "", log.LstdFlags)
mgo.SetLogger(aLogger)
}
// Start off with a new mux router.
router := mux.NewRouter().StrictSlash(true)
session, err := mgo.Dial(mongo)
if err != nil {
log.Fatalf("%s", err)
}
defer session.Close()
// Create the IPAM business logic object.
ipam, err := ipam.NewIpam(session)
if err != nil {
log.Fatalf("%s", err)
}
// Oddly enough don't need to capture the router for it to continue to exist.
_, err = controllers.NewPoolsController(router, ipam)
if err != nil {
log.Fatalf("%s", err)
}
_, err = controllers.NewSubnetsController(router, ipam)
if err != nil {
log.Fatalf("%s", err)
}
_, err = controllers.NewReservationsController(router, ipam)
if err != nil {
log.Fatalf("%s", err)
}
_, err = controllers.NewLeasesController(router, ipam)
if err != nil {
log.Fatalf("%s", err)
}
// Show off request logging middleware.
logged := handlers.LoggingHandler(os.Stdout, router)
log.Printf("Listening on port 8000...")
http.ListenAndServe(":8000", logged)
}