mirror of
https://github.com/labstack/echo.git
synced 2024-12-26 20:54:00 +02:00
44 lines
627 B
Go
44 lines
627 B
Go
|
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) {
|
||
|
c.Render(http.StatusOK, bolt.FMT_JSON, users)
|
||
|
}
|
||
|
|
||
|
func getUser(c *bolt.Context) {
|
||
|
c.Render(http.StatusOK, bolt.FMT_JSON, users[c.P(0)])
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
b := bolt.New()
|
||
|
b.Get("/users", getUsers)
|
||
|
b.Get("/users/:id", getUser)
|
||
|
// go b.RunHttp(":8080")
|
||
|
// go b.RunWebSocket(":8081")
|
||
|
b.RunTcp(":8082")
|
||
|
}
|