2
0

server_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. package manager
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/ioutil"
  6. "math/rand"
  7. "net/http"
  8. "strings"
  9. "sync/atomic"
  10. "testing"
  11. "time"
  12. "github.com/gin-gonic/gin"
  13. . "github.com/smartystreets/goconvey/convey"
  14. . "github.com/tuna/tunasync/internal"
  15. )
  16. const (
  17. _magicBadWorkerID = "magic_bad_worker_id"
  18. )
  19. func TestHTTPServer(t *testing.T) {
  20. var listenPort = 5000
  21. Convey("HTTP server should work", t, func(ctx C) {
  22. listenPort++
  23. port := listenPort
  24. addr := "127.0.0.1"
  25. baseURL := fmt.Sprintf("http://%s:%d", addr, port)
  26. InitLogger(true, true, false)
  27. s := GetTUNASyncManager(&Config{Debug: true})
  28. s.cfg.Server.Addr = addr
  29. s.cfg.Server.Port = port
  30. So(s, ShouldNotBeNil)
  31. s.setDBAdapter(&mockDBAdapter{
  32. workerStore: map[string]WorkerStatus{
  33. _magicBadWorkerID: WorkerStatus{
  34. ID: _magicBadWorkerID,
  35. }},
  36. statusStore: make(map[string]MirrorStatus),
  37. })
  38. go s.Run()
  39. time.Sleep(50 * time.Millisecond)
  40. resp, err := http.Get(baseURL + "/ping")
  41. So(err, ShouldBeNil)
  42. So(resp.StatusCode, ShouldEqual, http.StatusOK)
  43. So(resp.Header.Get("Content-Type"), ShouldEqual, "application/json; charset=utf-8")
  44. defer resp.Body.Close()
  45. body, err := ioutil.ReadAll(resp.Body)
  46. So(err, ShouldBeNil)
  47. var p map[string]string
  48. err = json.Unmarshal(body, &p)
  49. So(err, ShouldBeNil)
  50. So(p[_infoKey], ShouldEqual, "pong")
  51. Convey("when database fail", func(ctx C) {
  52. resp, err := http.Get(fmt.Sprintf("%s/workers/%s/jobs", baseURL, _magicBadWorkerID))
  53. So(err, ShouldBeNil)
  54. So(resp.StatusCode, ShouldEqual, http.StatusInternalServerError)
  55. defer resp.Body.Close()
  56. var msg map[string]string
  57. err = json.NewDecoder(resp.Body).Decode(&msg)
  58. So(err, ShouldBeNil)
  59. So(msg[_errorKey], ShouldEqual, fmt.Sprintf("failed to list jobs of worker %s: %s", _magicBadWorkerID, "database fail"))
  60. })
  61. Convey("when register multiple workers", func(ctx C) {
  62. N := 10
  63. var cnt uint32
  64. for i := 0; i < N; i++ {
  65. go func(id int) {
  66. w := WorkerStatus{
  67. ID: fmt.Sprintf("worker%d", id),
  68. }
  69. resp, err := PostJSON(baseURL+"/workers", w, nil)
  70. ctx.So(err, ShouldBeNil)
  71. ctx.So(resp.StatusCode, ShouldEqual, http.StatusOK)
  72. atomic.AddUint32(&cnt, 1)
  73. }(i)
  74. }
  75. time.Sleep(2 * time.Second)
  76. So(cnt, ShouldEqual, N)
  77. Convey("list all workers", func(ctx C) {
  78. resp, err := http.Get(baseURL + "/workers")
  79. So(err, ShouldBeNil)
  80. defer resp.Body.Close()
  81. var actualResponseObj []WorkerStatus
  82. err = json.NewDecoder(resp.Body).Decode(&actualResponseObj)
  83. So(err, ShouldBeNil)
  84. So(len(actualResponseObj), ShouldEqual, N+1)
  85. })
  86. })
  87. Convey("when register a worker", func(ctx C) {
  88. w := WorkerStatus{
  89. ID: "test_worker1",
  90. }
  91. resp, err := PostJSON(baseURL+"/workers", w, nil)
  92. So(err, ShouldBeNil)
  93. So(resp.StatusCode, ShouldEqual, http.StatusOK)
  94. Convey("list all workers", func(ctx C) {
  95. resp, err := http.Get(baseURL + "/workers")
  96. So(err, ShouldBeNil)
  97. defer resp.Body.Close()
  98. var actualResponseObj []WorkerStatus
  99. err = json.NewDecoder(resp.Body).Decode(&actualResponseObj)
  100. So(err, ShouldBeNil)
  101. So(len(actualResponseObj), ShouldEqual, 2)
  102. })
  103. Convey("delete an existent worker", func(ctx C) {
  104. req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/workers/%s", baseURL, w.ID), nil)
  105. So(err, ShouldBeNil)
  106. clt := &http.Client{}
  107. resp, err := clt.Do(req)
  108. So(err, ShouldBeNil)
  109. defer resp.Body.Close()
  110. res := map[string]string{}
  111. err = json.NewDecoder(resp.Body).Decode(&res)
  112. So(err, ShouldBeNil)
  113. So(res[_infoKey], ShouldEqual, "deleted")
  114. })
  115. Convey("delete non-existent worker", func(ctx C) {
  116. invalidWorker := "test_worker233"
  117. req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/workers/%s", baseURL, invalidWorker), nil)
  118. So(err, ShouldBeNil)
  119. clt := &http.Client{}
  120. resp, err := clt.Do(req)
  121. So(err, ShouldBeNil)
  122. defer resp.Body.Close()
  123. res := map[string]string{}
  124. err = json.NewDecoder(resp.Body).Decode(&res)
  125. So(err, ShouldBeNil)
  126. So(res[_errorKey], ShouldEqual, "invalid workerID "+invalidWorker)
  127. })
  128. Convey("flush disabled jobs", func(ctx C) {
  129. req, err := http.NewRequest("DELETE", baseURL+"/jobs/disabled", nil)
  130. So(err, ShouldBeNil)
  131. clt := &http.Client{}
  132. resp, err := clt.Do(req)
  133. So(err, ShouldBeNil)
  134. defer resp.Body.Close()
  135. res := map[string]string{}
  136. err = json.NewDecoder(resp.Body).Decode(&res)
  137. So(err, ShouldBeNil)
  138. So(res[_infoKey], ShouldEqual, "flushed")
  139. })
  140. Convey("update mirror status of a existed worker", func(ctx C) {
  141. status := MirrorStatus{
  142. Name: "arch-sync1",
  143. Worker: "test_worker1",
  144. IsMaster: true,
  145. Status: Success,
  146. Upstream: "mirrors.tuna.tsinghua.edu.cn",
  147. Size: "unknown",
  148. }
  149. resp, err := PostJSON(fmt.Sprintf("%s/workers/%s/jobs/%s", baseURL, status.Worker, status.Name), status, nil)
  150. So(err, ShouldBeNil)
  151. defer resp.Body.Close()
  152. So(resp.StatusCode, ShouldEqual, http.StatusOK)
  153. Convey("list mirror status of an existed worker", func(ctx C) {
  154. var ms []MirrorStatus
  155. resp, err := GetJSON(baseURL+"/workers/test_worker1/jobs", &ms, nil)
  156. So(err, ShouldBeNil)
  157. So(resp.StatusCode, ShouldEqual, http.StatusOK)
  158. // err = json.NewDecoder(resp.Body).Decode(&mirrorStatusList)
  159. m := ms[0]
  160. So(m.Name, ShouldEqual, status.Name)
  161. So(m.Worker, ShouldEqual, status.Worker)
  162. So(m.Status, ShouldEqual, status.Status)
  163. So(m.Upstream, ShouldEqual, status.Upstream)
  164. So(m.Size, ShouldEqual, status.Size)
  165. So(m.IsMaster, ShouldEqual, status.IsMaster)
  166. So(time.Now().Sub(m.LastUpdate), ShouldBeLessThan, 1*time.Second)
  167. So(m.LastStarted.IsZero(), ShouldBeTrue) // hasn't been initialized yet
  168. So(time.Now().Sub(m.LastEnded), ShouldBeLessThan, 1*time.Second)
  169. })
  170. // start syncing
  171. status.Status = PreSyncing
  172. time.Sleep(1 * time.Second)
  173. resp, err = PostJSON(fmt.Sprintf("%s/workers/%s/jobs/%s", baseURL, status.Worker, status.Name), status, nil)
  174. So(err, ShouldBeNil)
  175. defer resp.Body.Close()
  176. So(resp.StatusCode, ShouldEqual, http.StatusOK)
  177. Convey("update mirror status to PreSync - starting sync", func(ctx C) {
  178. var ms []MirrorStatus
  179. resp, err := GetJSON(baseURL+"/workers/test_worker1/jobs", &ms, nil)
  180. So(err, ShouldBeNil)
  181. So(resp.StatusCode, ShouldEqual, http.StatusOK)
  182. // err = json.NewDecoder(resp.Body).Decode(&mirrorStatusList)
  183. m := ms[0]
  184. So(m.Name, ShouldEqual, status.Name)
  185. So(m.Worker, ShouldEqual, status.Worker)
  186. So(m.Status, ShouldEqual, status.Status)
  187. So(m.Upstream, ShouldEqual, status.Upstream)
  188. So(m.Size, ShouldEqual, status.Size)
  189. So(m.IsMaster, ShouldEqual, status.IsMaster)
  190. So(time.Now().Sub(m.LastUpdate), ShouldBeLessThan, 3*time.Second)
  191. So(time.Now().Sub(m.LastUpdate), ShouldBeGreaterThan, 1*time.Second)
  192. So(time.Now().Sub(m.LastStarted), ShouldBeLessThan, 2*time.Second)
  193. So(time.Now().Sub(m.LastEnded), ShouldBeLessThan, 3*time.Second)
  194. So(time.Now().Sub(m.LastEnded), ShouldBeGreaterThan, 1*time.Second)
  195. })
  196. Convey("list all job status of all workers", func(ctx C) {
  197. var ms []WebMirrorStatus
  198. resp, err := GetJSON(baseURL+"/jobs", &ms, nil)
  199. So(err, ShouldBeNil)
  200. So(resp.StatusCode, ShouldEqual, http.StatusOK)
  201. m := ms[0]
  202. So(m.Name, ShouldEqual, status.Name)
  203. So(m.Status, ShouldEqual, status.Status)
  204. So(m.Upstream, ShouldEqual, status.Upstream)
  205. So(m.Size, ShouldEqual, status.Size)
  206. So(m.IsMaster, ShouldEqual, status.IsMaster)
  207. So(time.Now().Sub(m.LastUpdate.Time), ShouldBeLessThan, 3*time.Second)
  208. So(time.Now().Sub(m.LastStarted.Time), ShouldBeLessThan, 2*time.Second)
  209. So(time.Now().Sub(m.LastEnded.Time), ShouldBeLessThan, 3*time.Second)
  210. })
  211. Convey("Update size of a valid mirror", func(ctx C) {
  212. msg := struct {
  213. Name string `json:"name"`
  214. Size string `json:"size"`
  215. }{status.Name, "5GB"}
  216. url := fmt.Sprintf("%s/workers/%s/jobs/%s/size", baseURL, status.Worker, status.Name)
  217. resp, err := PostJSON(url, msg, nil)
  218. So(err, ShouldBeNil)
  219. So(resp.StatusCode, ShouldEqual, http.StatusOK)
  220. Convey("Get new size of a mirror", func(ctx C) {
  221. var ms []MirrorStatus
  222. resp, err := GetJSON(baseURL+"/workers/test_worker1/jobs", &ms, nil)
  223. So(err, ShouldBeNil)
  224. So(resp.StatusCode, ShouldEqual, http.StatusOK)
  225. // err = json.NewDecoder(resp.Body).Decode(&mirrorStatusList)
  226. m := ms[0]
  227. So(m.Name, ShouldEqual, status.Name)
  228. So(m.Worker, ShouldEqual, status.Worker)
  229. So(m.Status, ShouldEqual, status.Status)
  230. So(m.Upstream, ShouldEqual, status.Upstream)
  231. So(m.Size, ShouldEqual, "5GB")
  232. So(m.IsMaster, ShouldEqual, status.IsMaster)
  233. So(time.Now().Sub(m.LastUpdate), ShouldBeLessThan, 3*time.Second)
  234. So(time.Now().Sub(m.LastStarted), ShouldBeLessThan, 2*time.Second)
  235. So(time.Now().Sub(m.LastEnded), ShouldBeLessThan, 3*time.Second)
  236. })
  237. })
  238. Convey("Update schedule of valid mirrors", func(ctx C) {
  239. msg := MirrorSchedules{
  240. []MirrorSchedule{
  241. MirrorSchedule{"arch-sync1", time.Now().Add(time.Minute * 10)},
  242. MirrorSchedule{"arch-sync2", time.Now().Add(time.Minute * 7)},
  243. },
  244. }
  245. url := fmt.Sprintf("%s/workers/%s/schedules", baseURL, status.Worker)
  246. resp, err := PostJSON(url, msg, nil)
  247. So(err, ShouldBeNil)
  248. So(resp.StatusCode, ShouldEqual, http.StatusOK)
  249. })
  250. Convey("Update size of an invalid mirror", func(ctx C) {
  251. msg := struct {
  252. Name string `json:"name"`
  253. Size string `json:"size"`
  254. }{"Invalid mirror", "5GB"}
  255. url := fmt.Sprintf("%s/workers/%s/jobs/%s/size", baseURL, status.Worker, status.Name)
  256. resp, err := PostJSON(url, msg, nil)
  257. So(err, ShouldBeNil)
  258. So(resp.StatusCode, ShouldEqual, http.StatusInternalServerError)
  259. })
  260. // what if status changed to failed
  261. status.Status = Failed
  262. time.Sleep(3 * time.Second)
  263. resp, err = PostJSON(fmt.Sprintf("%s/workers/%s/jobs/%s", baseURL, status.Worker, status.Name), status, nil)
  264. So(err, ShouldBeNil)
  265. defer resp.Body.Close()
  266. So(resp.StatusCode, ShouldEqual, http.StatusOK)
  267. Convey("What if syncing job failed", func(ctx C) {
  268. var ms []MirrorStatus
  269. resp, err := GetJSON(baseURL+"/workers/test_worker1/jobs", &ms, nil)
  270. So(err, ShouldBeNil)
  271. So(resp.StatusCode, ShouldEqual, http.StatusOK)
  272. // err = json.NewDecoder(resp.Body).Decode(&mirrorStatusList)
  273. m := ms[0]
  274. So(m.Name, ShouldEqual, status.Name)
  275. So(m.Worker, ShouldEqual, status.Worker)
  276. So(m.Status, ShouldEqual, status.Status)
  277. So(m.Upstream, ShouldEqual, status.Upstream)
  278. So(m.Size, ShouldEqual, status.Size)
  279. So(m.IsMaster, ShouldEqual, status.IsMaster)
  280. So(time.Now().Sub(m.LastUpdate), ShouldBeGreaterThan, 3*time.Second)
  281. So(time.Now().Sub(m.LastStarted), ShouldBeGreaterThan, 3*time.Second)
  282. So(time.Now().Sub(m.LastEnded), ShouldBeLessThan, 1*time.Second)
  283. })
  284. })
  285. Convey("update mirror status of an inexisted worker", func(ctx C) {
  286. invalidWorker := "test_worker2"
  287. status := MirrorStatus{
  288. Name: "arch-sync2",
  289. Worker: invalidWorker,
  290. IsMaster: true,
  291. Status: Success,
  292. LastUpdate: time.Now(),
  293. LastStarted: time.Now(),
  294. LastEnded: time.Now(),
  295. Upstream: "mirrors.tuna.tsinghua.edu.cn",
  296. Size: "4GB",
  297. }
  298. resp, err := PostJSON(fmt.Sprintf("%s/workers/%s/jobs/%s",
  299. baseURL, status.Worker, status.Name), status, nil)
  300. So(err, ShouldBeNil)
  301. So(resp.StatusCode, ShouldEqual, http.StatusBadRequest)
  302. defer resp.Body.Close()
  303. var msg map[string]string
  304. err = json.NewDecoder(resp.Body).Decode(&msg)
  305. So(err, ShouldBeNil)
  306. So(msg[_errorKey], ShouldEqual, "invalid workerID "+invalidWorker)
  307. })
  308. Convey("update schedule of an non-existent worker", func(ctx C) {
  309. invalidWorker := "test_worker2"
  310. sch := MirrorSchedules{
  311. []MirrorSchedule{
  312. MirrorSchedule{"arch-sync1", time.Now().Add(time.Minute * 10)},
  313. MirrorSchedule{"arch-sync2", time.Now().Add(time.Minute * 7)},
  314. },
  315. }
  316. resp, err := PostJSON(fmt.Sprintf("%s/workers/%s/schedules",
  317. baseURL, invalidWorker), sch, nil)
  318. So(err, ShouldBeNil)
  319. So(resp.StatusCode, ShouldEqual, http.StatusBadRequest)
  320. defer resp.Body.Close()
  321. var msg map[string]string
  322. err = json.NewDecoder(resp.Body).Decode(&msg)
  323. So(err, ShouldBeNil)
  324. So(msg[_errorKey], ShouldEqual, "invalid workerID "+invalidWorker)
  325. })
  326. Convey("handle client command", func(ctx C) {
  327. cmdChan := make(chan WorkerCmd, 1)
  328. workerServer := makeMockWorkerServer(cmdChan)
  329. workerPort := rand.Intn(10000) + 30000
  330. bindAddress := fmt.Sprintf("127.0.0.1:%d", workerPort)
  331. workerBaseURL := fmt.Sprintf("http://%s", bindAddress)
  332. w := WorkerStatus{
  333. ID: "test_worker_cmd",
  334. URL: workerBaseURL + "/cmd",
  335. }
  336. resp, err := PostJSON(baseURL+"/workers", w, nil)
  337. So(err, ShouldBeNil)
  338. So(resp.StatusCode, ShouldEqual, http.StatusOK)
  339. go func() {
  340. // run the mock worker server
  341. workerServer.Run(bindAddress)
  342. }()
  343. time.Sleep(50 * time.Millisecond)
  344. // verify the worker mock server is running
  345. workerResp, err := http.Get(workerBaseURL + "/ping")
  346. So(err, ShouldBeNil)
  347. defer workerResp.Body.Close()
  348. So(workerResp.StatusCode, ShouldEqual, http.StatusOK)
  349. Convey("when client send wrong cmd", func(ctx C) {
  350. clientCmd := ClientCmd{
  351. Cmd: CmdStart,
  352. MirrorID: "ubuntu-sync",
  353. WorkerID: "not_exist_worker",
  354. }
  355. resp, err := PostJSON(baseURL+"/cmd", clientCmd, nil)
  356. So(err, ShouldBeNil)
  357. defer resp.Body.Close()
  358. So(resp.StatusCode, ShouldEqual, http.StatusBadRequest)
  359. })
  360. Convey("when client send correct cmd", func(ctx C) {
  361. clientCmd := ClientCmd{
  362. Cmd: CmdStart,
  363. MirrorID: "ubuntu-sync",
  364. WorkerID: w.ID,
  365. }
  366. resp, err := PostJSON(baseURL+"/cmd", clientCmd, nil)
  367. So(err, ShouldBeNil)
  368. defer resp.Body.Close()
  369. So(resp.StatusCode, ShouldEqual, http.StatusOK)
  370. time.Sleep(50 * time.Microsecond)
  371. select {
  372. case cmd := <-cmdChan:
  373. ctx.So(cmd.Cmd, ShouldEqual, clientCmd.Cmd)
  374. ctx.So(cmd.MirrorID, ShouldEqual, clientCmd.MirrorID)
  375. default:
  376. ctx.So(0, ShouldEqual, 1)
  377. }
  378. })
  379. })
  380. })
  381. })
  382. }
  383. type mockDBAdapter struct {
  384. workerStore map[string]WorkerStatus
  385. statusStore map[string]MirrorStatus
  386. }
  387. func (b *mockDBAdapter) Init() error {
  388. return nil
  389. }
  390. func (b *mockDBAdapter) ListWorkers() ([]WorkerStatus, error) {
  391. workers := make([]WorkerStatus, len(b.workerStore))
  392. idx := 0
  393. for _, w := range b.workerStore {
  394. workers[idx] = w
  395. idx++
  396. }
  397. return workers, nil
  398. }
  399. func (b *mockDBAdapter) GetWorker(workerID string) (WorkerStatus, error) {
  400. w, ok := b.workerStore[workerID]
  401. if !ok {
  402. return WorkerStatus{}, fmt.Errorf("invalid workerId")
  403. }
  404. return w, nil
  405. }
  406. func (b *mockDBAdapter) DeleteWorker(workerID string) error {
  407. delete(b.workerStore, workerID)
  408. return nil
  409. }
  410. func (b *mockDBAdapter) CreateWorker(w WorkerStatus) (WorkerStatus, error) {
  411. // _, ok := b.workerStore[w.ID]
  412. // if ok {
  413. // return workerStatus{}, fmt.Errorf("duplicate worker name")
  414. // }
  415. b.workerStore[w.ID] = w
  416. return w, nil
  417. }
  418. func (b *mockDBAdapter) RefreshWorker(workerID string) (w WorkerStatus, err error) {
  419. w, err = b.GetWorker(workerID)
  420. if err == nil {
  421. w.LastOnline = time.Now()
  422. w, err = b.CreateWorker(w)
  423. }
  424. return w, err
  425. }
  426. func (b *mockDBAdapter) GetMirrorStatus(workerID, mirrorID string) (MirrorStatus, error) {
  427. id := mirrorID + "/" + workerID
  428. status, ok := b.statusStore[id]
  429. if !ok {
  430. return MirrorStatus{}, fmt.Errorf("no mirror %s exists in worker %s", mirrorID, workerID)
  431. }
  432. return status, nil
  433. }
  434. func (b *mockDBAdapter) UpdateMirrorStatus(workerID, mirrorID string, status MirrorStatus) (MirrorStatus, error) {
  435. // if _, ok := b.workerStore[workerID]; !ok {
  436. // // unregistered worker
  437. // return MirrorStatus{}, fmt.Errorf("invalid workerID %s", workerID)
  438. // }
  439. id := mirrorID + "/" + workerID
  440. b.statusStore[id] = status
  441. return status, nil
  442. }
  443. func (b *mockDBAdapter) ListMirrorStatus(workerID string) ([]MirrorStatus, error) {
  444. var mirrorStatusList []MirrorStatus
  445. // simulating a database fail
  446. if workerID == _magicBadWorkerID {
  447. return []MirrorStatus{}, fmt.Errorf("database fail")
  448. }
  449. for k, v := range b.statusStore {
  450. if wID := strings.Split(k, "/")[1]; wID == workerID {
  451. mirrorStatusList = append(mirrorStatusList, v)
  452. }
  453. }
  454. return mirrorStatusList, nil
  455. }
  456. func (b *mockDBAdapter) ListAllMirrorStatus() ([]MirrorStatus, error) {
  457. var mirrorStatusList []MirrorStatus
  458. for _, v := range b.statusStore {
  459. mirrorStatusList = append(mirrorStatusList, v)
  460. }
  461. return mirrorStatusList, nil
  462. }
  463. func (b *mockDBAdapter) Close() error {
  464. return nil
  465. }
  466. func (b *mockDBAdapter) FlushDisabledJobs() error {
  467. return nil
  468. }
  469. func makeMockWorkerServer(cmdChan chan WorkerCmd) *gin.Engine {
  470. r := gin.Default()
  471. r.GET("/ping", func(c *gin.Context) {
  472. c.JSON(http.StatusOK, gin.H{_infoKey: "pong"})
  473. })
  474. r.POST("/cmd", func(c *gin.Context) {
  475. var cmd WorkerCmd
  476. c.BindJSON(&cmd)
  477. cmdChan <- cmd
  478. })
  479. return r
  480. }