本文整理汇总了Golang中github.com/intelsdi-x/snap/core.Namespace.AddDynamicElement方法的典型用法代码示例。如果您正苦于以下问题:Golang Namespace.AddDynamicElement方法的具体用法?Golang Namespace.AddDynamicElement怎么用?Golang Namespace.AddDynamicElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/intelsdi-x/snap/core.Namespace
的用法示例。
在下文中一共展示了Namespace.AddDynamicElement方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createMetricNamespace
// createMetricNamespace returns metric namespace based on given `ns` which is used as a prefix; all dynamic elements
// in the `metricName` are defined based on content of map `dynamicElements`
func (creator *nsCreator) createMetricNamespace(ns core.Namespace, metricName string) (core.Namespace, error) {
metricName = strings.TrimSpace(metricName)
if len(metricName) == 0 {
return nil, errors.New("Cannot create metric namespace: empty metric name")
}
elements := strings.Split(metricName, "/")
// check if metricName contains only static elements
if !strings.Contains(metricName, "*") {
ns = ns.AddStaticElements(elements...)
return ns, nil
}
// when metric name contains dynamic element iterate over elements
for index, element := range elements {
if element == "*" {
// the following element is dynamic
dynamicElement, ok := creator.dynamicElements[elements[index-1]]
// check if this dynamic element is supported (name and description are available)
if !ok {
return nil, fmt.Errorf("Unknown dynamic element in metric `%s` under index %d", metricName, index)
}
// add recognize dynamic element (define its name and description)
ns = ns.AddDynamicElement(dynamicElement.name, dynamicElement.description)
if len(elements)-1 == index {
// in case when an asterisk is the last element, add `value` at the end of ns
ns = ns.AddStaticElement("value")
}
} else {
// the following element is static
ns = ns.AddStaticElement(element)
}
}
if len(ns) == 0 {
return nil, fmt.Errorf("Cannot create metric namespace for metric %s", metricName)
}
return ns, nil
}