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