github.com/infraboard/keyauth@v0.8.1/apps/ip2region/http/http.go (about) 1 package http 2 3 import ( 4 "github.com/infraboard/mcube/app" 5 "github.com/infraboard/mcube/http/label" 6 "github.com/infraboard/mcube/http/router" 7 8 "github.com/infraboard/keyauth/apps/ip2region" 9 ) 10 11 var ( 12 api = &handler{} 13 ) 14 15 type handler struct { 16 service ip2region.Service 17 } 18 19 // Registry 注册HTTP服务路由 20 func (h *handler) Registry(router router.SubRouter) { 21 geoipRouter := router.ResourceRouter("IP") 22 geoipRouter.BasePath("ip2region") 23 geoipRouter.Handle("GET", "/query", h.LoopupIP).AddLabel(label.Get) 24 25 geoipRouter.Permission(true) 26 geoipRouter.Handle("POST", "/dbfile", h.UpdateDBFile).AddLabel(label.Create) 27 28 } 29 30 func (h *handler) Config() error { 31 h.service = app.GetInternalApp(ip2region.AppName).(ip2region.Service) 32 return nil 33 } 34 35 func (h *handler) Name() string { 36 return ip2region.AppName 37 } 38 39 func init() { 40 app.RegistryHttpApp(api) 41 }