1 Star 1 Fork 0

kade/library

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
metric.go 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
kade 提交于 2024-03-25 11:39 . 第三方库,初步完成
package metric
import (
restfulspec "github.com/emicklei/go-restful-openapi/v2"
"github.com/emicklei/go-restful/v3"
"gitee.com/go-kade/library/ioc/config/http"
"gitee.com/go-kade/library/ioc"
"gitee.com/go-kade/library/ioc/apps/metric"
"gitee.com/go-kade/library/ioc/config/log"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/rs/zerolog"
)
func init() {
ioc.Api().Registry(&restfulHandler{
Metric: metric.NewDefaultMetric(),
})
}
type restfulHandler struct {
log *zerolog.Logger
ioc.ObjectImpl
*metric.Metric
}
func (h *restfulHandler) Init() error {
h.log = log.Sub(metric.AppName)
return nil
}
func (h *restfulHandler) Name() string {
return metric.AppName
}
func (h *restfulHandler) Version() string {
return "v1"
}
func (h *restfulHandler) Meta() ioc.ObjectMeta {
meta := ioc.DefaultObjectMeta()
meta.CustomPathPrefix = h.Endpoint
return meta
}
func (h *restfulHandler) Registry(ws *restful.WebService) {
tags := []string{"指标"}
ws.Route(ws.GET("/").
To(h.MetricHandleFunc).
Doc("创建Job").
Metadata(restfulspec.KeyOpenAPITags, tags),
)
h.log.Info().Msgf("Get the Metric using http://%s%s", http.Get().Addr(), h.Endpoint)
}
func (h *restfulHandler) MetricHandleFunc(r *restful.Request, w *restful.Response) {
// 基于标准库 包装了一层
promhttp.Handler().ServeHTTP(w, r.Request)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/go-kade/library.git
git@gitee.com:go-kade/library.git
go-kade
library
library
v1.3.4

搜索帮助