github.com/infraboard/keyauth@v0.8.1/apps/namespace/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/namespace" 8 "github.com/infraboard/keyauth/apps/user/types" 9 ) 10 11 var ( 12 api = &handler{} 13 ) 14 15 type handler struct { 16 service namespace.ServiceServer 17 } 18 19 // Registry 注册HTTP服务路由 20 func (h *handler) Registry(router router.SubRouter) { 21 // 需要做权限限制 22 r := router.ResourceRouter("namespace") 23 r.BasePath("namespaces") 24 r.Handle("POST", "/", h.Create).SetAllow(types.UserType_PERM_ADMIN) 25 r.Handle("GET", "/", h.List).SetAllow(types.UserType_PERM_ADMIN) 26 r.Handle("DELETE", "/:id", h.Delete).SetAllow(types.UserType_PERM_ADMIN) 27 r.Handle("GET", "/:id", h.Get) 28 29 // 获取自己的namespace 不需做权限限制 30 self := router.ResourceRouter("namespace") 31 self.BasePath("self/namespaces") 32 self.Handle("GET", "/", h.ListSelfNamespace) 33 } 34 35 func (h *handler) Config() error { 36 h.service = app.GetGrpcApp(namespace.AppName).(namespace.ServiceServer) 37 return nil 38 } 39 40 func (h *handler) Name() string { 41 return namespace.AppName 42 } 43 44 func init() { 45 app.RegistryHttpApp(api) 46 }