forked from golang-bristol/beer-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (31 loc) · 790 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
package main
import (
"fmt"
"log"
"net/http"
"github.com/julienschmidt/httprouter"
)
// db is an interface to interact with data on multiple type of data storage
var db Storage
var router *httprouter.Router
func init() {
var err error
// TODO: Add configuration to select type of storage, file location or
// database connection.
db, err = newStorage(Memory)
if err != nil {
log.Fatal(err)
}
PopulateBeers()
PopulateReviews()
router = httprouter.New()
router.GET("/beers", GetBeers)
router.GET("/beers/:id", GetBeer)
router.GET("/beers/:id/reviews", GetBeerReviews)
router.POST("/beers", AddBeer)
router.POST("/beers/:id/reviews", AddBeerReview)
}
func main() {
fmt.Println("The beer server is on tap now.")
log.Fatal(http.ListenAndServe(":8080", router))
}