2015-03-01 19:45:13 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/labstack/bolt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type user struct {
|
|
|
|
Id string
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
|
|
|
var users map[string]*user
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
users = map[string]*user{
|
|
|
|
"1": &user{
|
|
|
|
Id: "1",
|
|
|
|
Name: "Wreck-It Ralph",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func createUser(c *bolt.Context) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func getUsers(c *bolt.Context) {
|
2015-03-06 06:46:17 +02:00
|
|
|
c.RenderJSON(http.StatusOK, users)
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func getUser(c *bolt.Context) {
|
2015-03-06 06:46:17 +02:00
|
|
|
c.RenderJSON(http.StatusOK, users[c.P(0)])
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
b := bolt.New()
|
|
|
|
b.Get("/users", getUsers)
|
|
|
|
b.Get("/users/:id", getUser)
|
2015-03-06 06:46:17 +02:00
|
|
|
b.Run(":8080")
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|