Ai
1 Star 0 Fork 0

ryancartoon/sensu-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
resource.go 792 Bytes
一键复制 编辑 原始数据 按行查看 历史
James Phillips 提交于 2019-06-10 23:40 +08:00 . [Graphql] Simple autosuggestion (#3028)
package suggest
import (
"path"
"regexp"
)
var (
nsRe = regexp.MustCompile("{namespace}")
)
// Resource represents a Sensu resource
type Resource struct {
Group string
Name string
Path string
Fields []Field
}
// URIPath given a namespace returns the API path used to get/list/put/delete
// the resource.
func (r *Resource) URIPath(ns string) string {
if r.Path != "" {
return nsRe.ReplaceAllString(r.Path, ns)
}
if r.Group == "core/v2" {
return path.Join("/", "api", r.Group, "namespaces", ns, r.Name)
}
return path.Join("/", "api", r.Group, r.Name)
}
// LookupField uses given ref to find the appropriate field.
func (r *Resource) LookupField(ref RefComponents) Field {
for _, f := range r.Fields {
if f.Matches(ref.FieldPath) {
return f
}
}
return nil
}
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

搜索帮助