forked from katzien/go-structure-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (30 loc) · 841 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
package main
import (
"fmt"
"log"
"net/http"
"github.com/julienschmidt/httprouter"
"github.com/katzien/go-structure-examples/modular/beers"
"github.com/katzien/go-structure-examples/modular/reviews"
"github.com/katzien/go-structure-examples/modular/storage"
)
var router *httprouter.Router
func init() {
var err error
err = storage.NewStorage(storage.Memory)
if err != nil {
log.Fatal(err)
}
storage.PopulateBeers()
storage.PopulateReviews()
router = httprouter.New()
router.GET("/beers", beers.GetBeers)
router.GET("/beers/:id", beers.GetBeer)
router.GET("/beers/:id/reviews", reviews.GetBeerReviews)
router.POST("/beers", beers.AddBeer)
router.POST("/beers/:id/reviews", reviews.AddBeerReview)
}
func main() {
fmt.Println("The beer server is on tap now.")
log.Fatal(http.ListenAndServe(":8080", router))
}