-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
46 lines (36 loc) · 1.24 KB
/
main.go
File metadata and controls
46 lines (36 loc) · 1.24 KB
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
package main
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/gusta-project/go-api/api"
"github.com/gusta-project/go-api/middleware"
"github.com/gusta-project/go-api/model"
// this provides short and long options which is nice
// but flag is probably the better choice later on if we read everything
// from a config file
"github.com/karrick/golf"
)
var port = golf.IntP('l', "listen", 3000, "port to listen on")
// FIXME: maybe just use a connect string
// FIXME:² read from a config file
var pgHost = golf.StringP('h', "host", "localhost", "postgres host")
var pgPort = golf.IntP('p', "port", 5432, "postgres port")
var pgDatabase = golf.StringP('d', "database", "gusta", "postgres database")
var pgUser = golf.StringP('u', "user", "gusta", "postgres user")
var pgPass = golf.String("pass", "changeme", "postgres password")
var pgUseSSL = golf.BoolP('s', "ssl", false, "postgres use SSL")
func main() {
golf.Parse()
log.SetFlags(0)
m := model.NewPostgres(*pgHost, *pgPort, *pgUser, *pgDatabase, *pgPass, *pgUseSSL)
a := api.New(m)
defer m.Close()
r := mux.NewRouter()
a.Register(r)
r.Use(middleware.Log)
addr := fmt.Sprintf(":%d", *port)
log.Printf("listen on: %d", *port)
log.Fatal(http.ListenAndServe(addr, r))
}