github.com/infraboard/keyauth@v0.8.1/apps/domain/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/domain" 8 "github.com/infraboard/keyauth/apps/user/types" 9 ) 10 11 var ( 12 api = &handler{} 13 ) 14 15 type handler struct { 16 service domain.ServiceServer 17 } 18 19 // Registry 注册HTTP服务路由 20 func (h *handler) Registry(router router.SubRouter) { 21 domainRouter := router.ResourceRouter("domain") 22 23 domainRouter.BasePath("domains") 24 domainRouter.Handle("POST", "/", h.CreateDomain).SetAllow(types.UserType_SUPPER) 25 domainRouter.Handle("GET", "/", h.ListDomains).SetAllow(types.UserType_SUPPER) 26 domainRouter.Handle("GET", "/:name", h.GetDomain).SetAllow(types.UserType_DOMAIN_ADMIN) 27 domainRouter.Handle("PUT", "/:name", h.PutDomain).SetAllow(types.UserType_DOMAIN_ADMIN) 28 domainRouter.Handle("PATCH", "/:name", h.PatchDomain).SetAllow(types.UserType_DOMAIN_ADMIN) 29 domainRouter.Handle("DELETE", "/:name", h.DeleteDomain).SetAllow(types.UserType_SUPPER) 30 domainRouter.Handle("PUT", "/:name/security", h.UpdateDomainSecurity).SetAllow(types.UserType_DOMAIN_ADMIN) 31 } 32 33 func (h *handler) Config() error { 34 h.service = app.GetGrpcApp(domain.AppName).(domain.ServiceServer) 35 return nil 36 } 37 38 func (h *handler) Name() string { 39 return domain.AppName 40 } 41 42 func init() { 43 app.RegistryHttpApp(api) 44 }