github.com/infraboard/keyauth@v0.8.1/apps/endpoint/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/endpoint"
     8  )
     9  
    10  var (
    11  	api = &handler{}
    12  )
    13  
    14  type handler struct {
    15  	endpoint endpoint.ServiceServer
    16  }
    17  
    18  // Registry 注册HTTP服务路由
    19  func (h *handler) Registry(router router.SubRouter) {
    20  	r := router.ResourceRouter("endpoint")
    21  	r.BasePath("endpoints")
    22  	r.Handle("POST", "/", h.Create)
    23  	r.Handle("GET", "/", h.List)
    24  	r.Handle("GET", "/:id", h.Get)
    25  
    26  	rr := router.ResourceRouter("resource")
    27  	rr.BasePath("resources")
    28  	rr.Handle("GET", "/", h.ListResource)
    29  }
    30  
    31  func (h *handler) Config() error {
    32  	h.endpoint = app.GetGrpcApp(endpoint.AppName).(endpoint.ServiceServer)
    33  	return nil
    34  }
    35  
    36  func (h *handler) Name() string {
    37  	return endpoint.AppName
    38  }
    39  
    40  func init() {
    41  	app.RegistryHttpApp(api)
    42  }