本文整理匯總了Golang中github.com/micro/go-micro/registry.Service.Metadata方法的典型用法代碼示例。如果您正苦於以下問題:Golang Service.Metadata方法的具體用法?Golang Service.Metadata怎麽用?Golang Service.Metadata使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/micro/go-micro/registry.Service
的用法示例。
在下文中一共展示了Service.Metadata方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Apply
func Apply(labels []*label.LabelSet, s *registry.Service) {
// sort low to high
sortedLabels := Labels(labels)
sort.Sort(sortedLabels)
for _, label := range sortedLabels {
// does the label have a version and does it match?
if len(label.Version) > 0 && label.Version != s.Version {
continue
}
// ok so either the version matches or its a generic apply
// delete they label
if label.Weight == 0 {
v := s.Metadata[label.Key]
// if there's a key value and its the same
// or if the key value is blank
if i := len(label.Value); i > 0 && v == label.Value || i == 0 {
delete(s.Metadata, label.Key)
}
// delete from the nodes
for _, node := range s.Nodes {
v := node.Metadata[label.Key]
if i := len(label.Value); i > 0 && v == label.Value || i == 0 {
delete(node.Metadata, label.Key)
}
}
// other weight is greater than 0, create label
} else {
// Apply at the top level
// Should we actually apply as a sampling here?
// Or at the individual node basis?
if label.Weight == 100 {
if s.Metadata == nil {
s.Metadata = make(map[string]string)
}
s.Metadata[label.Key] = label.Value
}
// Apply to nodes
for _, node := range s.Nodes {
// Apply based on the weight
if rand.Int63n(100) <= label.Weight {
if node.Metadata == nil {
node.Metadata = make(map[string]string)
}
node.Metadata[label.Key] = label.Value
}
}
}
}
}