-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (35 loc) · 828 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 (
"net/http"
"encoding/json"
"github.com/julienschmidt/httprouter"
)
func init() {
router := httprouter.New()
router.GET("/tasks", getTasks)
router.POST("/tasks", createTask)
router.GET("/tasks/:id", showTask)
router.PUT("/tasks/:id", updateTask)
router.DELETE("/tasks/:id", deleteTask)
http.Handle("/", router)
}
func checkErr(err error) {
if err != nil {
panic(err)
}
}
func sendJSONResponse(w http.ResponseWriter, status int, data interface{}) {
d, err := json.Marshal(data)
if err != nil {
return
}
w.WriteHeader(status)
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Write(d)
}
func atob(str string) bool {
if str == "true" || str == "1" {
return true
}
return false
}