代码拉取完成,页面将自动刷新
package endpoint
import (
"fmt"
"github.com/infraboard/mcube/pb/resource"
)
func (s *EndpointSpecSet) Service() (svcs []string) {
var m = map[string]int{}
for i := range s.Items {
item := s.Items[i]
m[item.Service]++
}
for k := range m {
svcs = append(svcs, k)
}
return
}
func NewEndpointSet(specs *EndpointSpecSet) *EndpointSet {
set := &EndpointSet{
Items: []*Endpoint{},
}
for i := range specs.Items {
spec := specs.Items[i]
set.Add(NewEndpoint(spec))
}
return set
}
func (s *EndpointSet) Add(items ...*Endpoint) {
s.Items = append(s.Items, items...)
}
func (s *EndpointSet) ToMongoDocs() (docs []any) {
for i := range s.Items {
docs = append(docs, s.Items[i])
}
return
}
func NewEndpoint(spec *EndpointSpec) *Endpoint {
m := resource.NewMeta()
// 补充Id
m.Id = spec.GenId()
return &Endpoint{
Meta: m,
Spec: spec,
}
}
func NewEndpointSpecSet() *EndpointSpecSet {
return &EndpointSpecSet{
Items: []*EndpointSpec{},
}
}
func (s *EndpointSpecSet) Add(items ...*EndpointSpec) {
s.Items = append(s.Items, items...)
}
func NewEndpointSpec(service, path string) *EndpointSpec {
return &EndpointSpec{
Service: service,
Path: path,
}
}
// Role需要应用Endpoint的Id, Endpoint的Id不能随机生成
func (s *EndpointSpec) GenId() string {
return fmt.Sprintf("%s.%s", s.Service, s.Path)
}
func GetValueFromMeta(meta map[string]any, key string) string {
v := meta[key]
if v == nil {
return ""
}
return v.(string)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。