-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
42 lines (32 loc) · 961 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
38
39
40
41
42
package main
import (
"net/http"
"github.com/gorilla/mux"
"github.com/jfo84/cleopatchra/api/db"
"github.com/jfo84/cleopatchra/api/pull"
"github.com/jfo84/cleopatchra/api/pulls"
"github.com/jfo84/cleopatchra/api/repo"
"github.com/jfo84/cleopatchra/api/repos"
)
func indexHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/repos", 301)
return
}
func main() {
db := db.OpenDB()
r := mux.NewRouter().StrictSlash(true)
reposController := repos.NewController(db)
r.HandleFunc("/repos", reposController.Get)
repoController := repo.NewController(db)
r.HandleFunc("/repos/{repoID}", repoController.Get)
pullsController := pulls.NewController(db)
r.HandleFunc("/repos/{repoID}/pulls", pullsController.Get)
pullController := pull.NewController(db)
r.HandleFunc("/pulls/{pullID}", pullController.Get)
r.HandleFunc("/", indexHandler)
addr := ":7000"
err := http.ListenAndServe(addr, r)
if err != nil {
panic(err)
}
}