1 Star 0 Fork 0

PengHengBen/devcloud-mini

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
model.go 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
chris Peng 提交于 2024-01-08 17:50 +08:00 . 完成权限注册
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)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/penghengben/devcloud-mini.git
git@gitee.com:penghengben/devcloud-mini.git
penghengben
devcloud-mini
devcloud-mini
52595909206d

搜索帮助