github.com/infraboard/keyauth@v0.8.1/apps/policy/http/http.go (about) 1 package http 2 3 import ( 4 "github.com/infraboard/mcube/app" 5 "github.com/infraboard/mcube/http/router" 6 7 "github.com/infraboard/keyauth/apps/policy" 8 "github.com/infraboard/keyauth/apps/user/types" 9 ) 10 11 var ( 12 api = &handler{} 13 ) 14 15 type handler struct { 16 service policy.ServiceServer 17 } 18 19 // Registry 注册HTTP服务路由 20 func (h *handler) Registry(router router.SubRouter) { 21 r := router.ResourceRouter("policy") 22 r.BasePath("policies") 23 r.Handle("POST", "/", h.Create).SetAllow(types.UserType_PERM_ADMIN) 24 r.Handle("GET", "/", h.List).SetAllow(types.UserType_PERM_ADMIN) 25 r.Handle("GET", "/:id", h.Get) 26 r.Handle("DELETE", "/:id", h.Delete).SetAllow(types.UserType_PERM_ADMIN) 27 } 28 29 func (h *handler) Config() error { 30 h.service = app.GetGrpcApp(policy.AppName).(policy.ServiceServer) 31 return nil 32 } 33 34 func (h *handler) Name() string { 35 return policy.AppName 36 } 37 38 func init() { 39 app.RegistryHttpApp(api) 40 }