1 Star 0 Fork 0

ryancartoon / sensu-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
key_parser.go 934 Bytes
一键复制 编辑 原始数据 按行查看 历史
package store
import "strings"
// SplitKey contains the component parts of a sensu resource key.
type SplitKey struct {
Root string
ResourceType string
Namespace string
ResourceName string
}
// ParseResourceKey splits a resource key into its component parts.
// It assumes the following key structure:
//
// /root/resourcetype/namespace/resourcename
// With the leading slash being optional.
func ParseResourceKey(key string) SplitKey {
var result SplitKey
split := strings.Split(key, "/")
if len(split[0]) == 0 {
split = split[1:]
}
if len(split) > 0 {
result.Root = split[0]
}
if len(split) > 1 {
result.ResourceType = split[1]
}
if len(split) > 2 {
result.Namespace = split[2]
}
if len(split) > 3 {
result.ResourceName = split[3]
}
return result
}
func (s SplitKey) String() string {
b := NewKeyBuilder(s.ResourceType)
b = b.WithNamespace(s.Namespace)
return b.Build(s.ResourceName)
}
1
https://gitee.com/ryancartoon/sensu-go.git
git@gitee.com:ryancartoon/sensu-go.git
ryancartoon
sensu-go
sensu-go
v5.10.1

搜索帮助

53164aa7 5694891 3bd8fe86 5694891