-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.go
37 lines (29 loc) · 904 Bytes
/
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
package main
import (
"flag"
"log"
"net/http"
"time"
db "github.com/antoineaugusti/feature-flags/db"
h "github.com/antoineaugusti/feature-flags/http"
s "github.com/antoineaugusti/feature-flags/services"
"github.com/boltdb/bolt"
)
func main() {
address := flag.String("a", ":8080", "address to listen")
boltLocation := flag.String("d", "bolt.db", "location of the database file")
flag.Parse()
// Open the DB connection
database, err := bolt.Open(*boltLocation, 0600, &bolt.Options{Timeout: 1 * time.Second})
if err != nil {
log.Fatal(err)
}
// Close the DB connection on exit
defer database.Close()
// Generate the default bucket
db.GenerateDefaultBucket(db.GetBucketName(), database)
api := h.APIHandler{FeatureService: s.FeatureService{DB: database}}
// Create and listen for the HTTP server
router := h.NewRouter(api)
log.Fatal(http.ListenAndServe(*address, router))
}