-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
37 lines (30 loc) · 821 Bytes
/
router.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
/**
* REST API router
* Rosbit Xu
*/
package main
import (
"github.com/rosbit/mgin"
"net/http"
"fmt"
"delay-tasks/conf"
"delay-tasks/rest"
"delay-tasks/utils"
)
func StartService() error {
utils.StartLoop()
api := mgin.NewMgin(mgin.WithLogger("delay-tasks"))
api.POST("/handler/:cate", rest.RegisterCateHandler)
api.POST("/task/:cate", rest.AddTask)
api.DELETE("/task/:cate", rest.DelTask)
api.GET("/task/:cate/:key",rest.FetchTask)
api.Get("/tasks", rest.ListTask)
// health check
api.GET("/health", func(c *mgin.Context) {
c.String(http.StatusOK, "OK\n")
})
serviceConf := conf.ServiceConf
listenParam := fmt.Sprintf("%s:%d", serviceConf.ListenHost, serviceConf.ListenPort)
fmt.Printf("I am listening at %s...\n", listenParam)
return http.ListenAndServe(listenParam, api)
}