| 17 | } |
| 18 | |
| 19 | func (api *API) setupServerRoutes() { |
| 20 | log.Debug("registering server api ...") |
| 21 | |
| 22 | api.Router.Use(middleware.DefaultCompress) |
| 23 | |
| 24 | api.Router.Route("/api", func(r chi.Router) { |
| 25 | r.Route("/v1", func(r chi.Router) { |
| 26 | r.Route("/units", func(r chi.Router) { |
| 27 | // GET /api/v1/units/ |
| 28 | r.Get("/", cached(600, api.ListUnits)) |
| 29 | // GET /api/v1/units/by_country |
| 30 | r.Get("/by_country", cached(600, api.UnitsByCountry)) |
| 31 | }) |
| 32 | r.Route("/unit", func(r chi.Router) { |
| 33 | // GET /api/v1/unit/<fingerprint> |
| 34 | r.Get("/{fingerprint:[a-fA-F0-9]+}", cached(600, api.ShowUnit)) |
| 35 | r.Route("/inbox", func(r chi.Router) { |
| 36 | // GET /api/v1/unit/inbox/ |
| 37 | r.Get("/", api.GetInbox) |
| 38 | r.Route("/{msg_id:[0-9]+}", func(r chi.Router) { |
| 39 | // GET /api/v1/unit/inbox/<msg_id> |
| 40 | r.Get("/", api.GetInboxMessage) |
| 41 | // GET /api/v1/unit/inbox/<msg_id>/<mark> |
| 42 | r.Get("/{mark:[a-z]+}", api.MarkInboxMessage) |
| 43 | }) |
| 44 | }) |
| 45 | // POST /api/v1/unit/<fingerprint>/inbox |
| 46 | r.Post("/{fingerprint:[a-fA-F0-9]+}/inbox", api.SendMessageTo) |
| 47 | // POST /api/v1/unit/enroll |
| 48 | r.Post("/enroll", api.UnitEnroll) |
| 49 | r.Route("/report", func(r chi.Router) { |
| 50 | // POST /api/v1/unit/report/ap |
| 51 | r.Post("/ap", api.UnitReportAP) |
| 52 | // POST /api/v1/unit/report/aps |
| 53 | r.Post("/aps", api.UnitReportMultipleAP) |
| 54 | }) |
| 55 | }) |
| 56 | }) |
| 57 | }) |
| 58 | } |