-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.go
47 lines (38 loc) · 1013 Bytes
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package api
import (
"github.com/emicklei/go-restful/v3"
"github.com/yoas0bi/micro-toolkit/app"
"github.com/yoas0bi/micro-toolkit/app/health"
"github.com/yoas0bi/micro-toolkit/logger"
"github.com/yoas0bi/micro-toolkit/logger/zap"
restfulspec "github.com/emicklei/go-restful-openapi/v2"
healthgrpc "google.golang.org/grpc/health/grpc_health_v1"
)
var (
h = &handler{}
)
type handler struct {
service healthgrpc.HealthServer
log logger.Logger
}
func (h *handler) Config() error {
h.log = zap.L().Named(h.Name())
h.service = app.GetInternalApp(health.AppName).(healthgrpc.HealthServer)
return nil
}
func (h *handler) Name() string {
return health.AppName
}
func (h *handler) Version() string {
return "v1"
}
func (h *handler) Registry(ws *restful.WebService) {
tags := []string{"健康检查"}
ws.Route(ws.GET("/").To(h.Check).
Doc("查询服务当前状态").
Metadata(restfulspec.KeyOpenAPITags, tags).
Returns(200, "OK", Health{}))
}
func init() {
app.RegistryRESTfulApp(h)
}