/
routes.go
59 lines (46 loc) · 953 Bytes
/
routes.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"github.com/labstack/echo"
"github.com/s-aska/Justaway-Ex/crawler/crawler"
)
type (
responseConnect struct {
Success bool
}
responseCount struct {
Count int
}
)
type Router struct {
crawler *crawler.Crawler
}
func (r *Router) start(c echo.Context) error {
go r.crawler.Connect(c.Param("id"))
return c.JSON(200, &responseConnect{
Success: true,
})
}
func (r *Router) stop(c echo.Context) error {
go r.crawler.Disconnect(c.Param("id"))
return c.JSON(200, &responseConnect{
Success: true,
})
}
func (r *Router) status(c echo.Context) error {
count := r.crawler.Count()
return c.JSON(200, &responseCount{
Count: count,
})
}
func (r *Router) startup(c echo.Context) error {
r.crawler.ConnectAll()
return c.JSON(200, &responseConnect{
Success: true,
})
}
func (r *Router) shutdown(c echo.Context) error {
r.crawler.DisconnectAll()
return c.JSON(200, &responseConnect{
Success: true,
})
}