1 Star 1 Fork 29

go-course / cmdb-g7

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
http.go 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
Mr.Yu 提交于 2022-05-28 15:07 . 补充secret模块
package api
import (
restfulspec "github.com/emicklei/go-restful-openapi"
"github.com/emicklei/go-restful/v3"
"github.com/infraboard/mcube/app"
"github.com/infraboard/mcube/http/label"
"github.com/infraboard/mcube/http/response"
"github.com/infraboard/mcube/logger"
"github.com/infraboard/mcube/logger/zap"
"gitee.com/go-course/cmdb-g7/apps/host"
)
var (
h = &handler{}
)
type handler struct {
service host.ServiceServer
log logger.Logger
}
func (h *handler) Config() error {
h.log = zap.L().Named(host.AppName)
h.service = app.GetGrpcApp(host.AppName).(host.ServiceServer)
return nil
}
func (h *handler) Name() string {
return host.AppName
}
func (h *handler) Version() string {
return "v1"
}
func (h *handler) Registry(ws *restful.WebService) {
tags := []string{h.Name()}
ws.Route(ws.POST("/").To(h.CreateHost).
Doc("create a host").
Metadata(restfulspec.KeyOpenAPITags, tags).
Metadata(label.Resource, h.Name()).
Metadata(label.Action, label.Create.Value()).
Reads(host.Host{}).
Writes(response.NewData(host.Host{})))
ws.Route(ws.GET("/").To(h.QueryHost).
Doc("get all hosts").
Metadata(restfulspec.KeyOpenAPITags, tags).
Metadata(label.Resource, h.Name()).
Metadata(label.Action, label.List.Value()).
Reads(host.QueryHostRequest{}).
Writes(response.NewData(host.HostSet{})).
Returns(200, "OK", host.HostSet{}))
ws.Route(ws.GET("/{id}").To(h.DescribeHost).
Doc("describe an host").
Param(ws.PathParameter("id", "identifier of the host").DataType("integer").DefaultValue("1")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Metadata(label.Resource, h.Name()).
Metadata(label.Action, label.Get.Value()).
Writes(response.NewData(host.Host{})).
Returns(200, "OK", response.NewData(host.Host{})).
Returns(404, "Not Found", nil))
}
func init() {
app.RegistryRESTfulApp(h)
}
1
https://gitee.com/go-course/cmdb-g7.git
git@gitee.com:go-course/cmdb-g7.git
go-course
cmdb-g7
cmdb-g7
eccb8114820a

搜索帮助