7 Star 24 Fork 30

go-course/go8

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
http.go 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
Mr.Yu 提交于 2022-10-22 16:16 . 补充restful 客户端
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/response"
"github.com/infraboard/mcube/logger"
"github.com/infraboard/mcube/logger/zap"
"gitee.com/go-course/go8/projects/devcloud/mcenter/apps/token"
)
var (
h = &handler{}
)
type handler struct {
service token.Service
log logger.Logger
}
func (h *handler) Config() error {
h.log = zap.L().Named(token.AppName)
h.service = app.GetGrpcApp(token.AppName).(token.Service)
return nil
}
func (h *handler) Name() string {
return token.AppName
}
func (h *handler) Version() string {
return "v1"
}
func (h *handler) Registry(ws *restful.WebService) {
tags := []string{"令牌管理"}
ws.Route(ws.POST("/").To(h.IssueToken).
Doc("颁发令牌(登录)").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(token.IssueTokenRequest{}).
Writes(response.NewData(token.Token{})))
ws.Route(ws.DELETE("/").To(h.RevolkToken).
Doc("撤销令牌(登出)").
Metadata(restfulspec.KeyOpenAPITags, tags))
ws.Route(ws.PATCH("/").To(h.ChangeNamespace).
Doc("切换空间").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(token.ChangeNamespaceRequest{}))
ws.Route(ws.GET("/").To(h.ValidateToken).
Doc("验证令牌").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(token.ValidateTokenRequest{}).
Writes(response.NewData(token.Token{})).
Returns(200, "OK", token.Token{}))
}
func init() {
app.RegistryRESTfulApp(h)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/go-course/go8.git
git@gitee.com:go-course/go8.git
go-course
go8
go8
6a8978f41a84

搜索帮助

D67c1975 1850385 1daf7b77 1850385