mirror of https://github.com/hashicorp/consul
agent: move parseMetaPair to config and export
parent
cb98754cd6
commit
aa1519c9f7
|
@ -2115,15 +2115,6 @@ func (a *Agent) loadMetadata(conf *Config) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseMetaPair parses a key/value pair of the form key:value
|
|
||||||
func parseMetaPair(raw string) (string, string) {
|
|
||||||
pair := strings.SplitN(raw, ":", 2)
|
|
||||||
if len(pair) == 2 {
|
|
||||||
return pair[0], pair[1]
|
|
||||||
}
|
|
||||||
return pair[0], ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// unloadMetadata resets the local metadata state
|
// unloadMetadata resets the local metadata state
|
||||||
func (a *Agent) unloadMetadata() {
|
func (a *Agent) unloadMetadata() {
|
||||||
a.state.Lock()
|
a.state.Lock()
|
||||||
|
|
|
@ -214,7 +214,7 @@ func (cmd *Command) readConfig() *Config {
|
||||||
if len(nodeMeta) > 0 {
|
if len(nodeMeta) > 0 {
|
||||||
cmdCfg.Meta = make(map[string]string)
|
cmdCfg.Meta = make(map[string]string)
|
||||||
for _, entry := range nodeMeta {
|
for _, entry := range nodeMeta {
|
||||||
key, value := parseMetaPair(entry)
|
key, value := ParseMetaPair(entry)
|
||||||
cmdCfg.Meta[key] = value
|
cmdCfg.Meta[key] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2079,3 +2079,12 @@ func (d dirEnts) Less(i, j int) bool {
|
||||||
func (d dirEnts) Swap(i, j int) {
|
func (d dirEnts) Swap(i, j int) {
|
||||||
d[i], d[j] = d[j], d[i]
|
d[i], d[j] = d[j], d[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseMetaPair parses a key/value pair of the form key:value
|
||||||
|
func ParseMetaPair(raw string) (string, string) {
|
||||||
|
pair := strings.SplitN(raw, ":", 2)
|
||||||
|
if len(pair) == 2 {
|
||||||
|
return pair[0], pair[1]
|
||||||
|
}
|
||||||
|
return pair[0], ""
|
||||||
|
}
|
||||||
|
|
|
@ -420,7 +420,7 @@ func (s *HTTPServer) parseMetaFilter(req *http.Request) map[string]string {
|
||||||
if filterList, ok := req.URL.Query()["node-meta"]; ok {
|
if filterList, ok := req.URL.Query()["node-meta"]; ok {
|
||||||
filters := make(map[string]string)
|
filters := make(map[string]string)
|
||||||
for _, filter := range filterList {
|
for _, filter := range filterList {
|
||||||
key, value := parseMetaPair(filter)
|
key, value := ParseMetaPair(filter)
|
||||||
filters[key] = value
|
filters[key] = value
|
||||||
}
|
}
|
||||||
return filters
|
return filters
|
||||||
|
|
Loading…
Reference in New Issue