1 Star 0 Fork 0

ryancartoon/sensu-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
parse.go 754 Bytes
一键复制 编辑 原始数据 按行查看 历史
James Phillips 提交于 2019-06-10 23:40 +08:00 . [Graphql] Simple autosuggestion (#3028)
package suggest
import (
"errors"
"strings"
)
var (
separator = "/"
ErrInvalidRef = errors.New("reference to field must take the form :group/:version/:resource/:field/:name")
)
type RefComponents struct {
Group string
Name string
FieldPath string
}
// String prints the identifier
func (r RefComponents) String() string {
return strings.Join([]string{r.Group, r.Name, r.FieldPath}, separator)
}
// ParseRef takes an identifier and returns it's components.
func ParseRef(ref string) (r RefComponents, err error) {
paths := strings.SplitN(ref, separator, 4)
if len(paths) < 3 {
return r, ErrInvalidRef
}
if len(paths) > 3 {
r.FieldPath = paths[3]
}
r.Group = strings.Join(paths[:2], separator)
r.Name = paths[2]
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ryancartoon/sensu-go.git
git@gitee.com:ryancartoon/sensu-go.git
ryancartoon
sensu-go
sensu-go
v5.10.1

搜索帮助