1 Star 1 Fork 0

ayun2001 / ok-boost-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
labels.go 963 Bytes
一键复制 编辑 原始数据 按行查看 历史
李盛雁 提交于 2023-12-04 16:23 . 更新 prometheus 相关代码
package prometheus
import (
"sort"
"gitee.com/ayun2001/ok-boost-go/pkg/pool/bytes"
"gitee.com/ayun2001/ok-boost-go/pkg/utils"
"github.com/prometheus/client_golang/prometheus"
)
var bufferPool = bytes.NewBufferPool(0)
func ConvertMapToKeys(labels map[string]string) []string {
keys := make([]string, 0, len(labels))
for k := range labels {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}
func ConvertLabelsToKeys(labels prometheus.Labels) []string {
return ConvertMapToKeys(labels)
}
func ConvertMapToString(labels map[string]string) string {
var buff = bufferPool.Get()
defer bufferPool.Put(buff)
keys := make([]string, 0, len(labels))
for k := range labels {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
buff.WriteString("#" + k + ":" + labels[k])
}
return utils.BytesToString(buff.Bytes())
}
func ConvertLabelsToString(labels prometheus.Labels) string {
return ConvertMapToString(labels)
}
Go
1
https://gitee.com/ayun2001/ok-boost-go.git
git@gitee.com:ayun2001/ok-boost-go.git
ayun2001
ok-boost-go
ok-boost-go
d07672de674d

搜索帮助