Skip to content

Commit

Permalink
UnmarshalTags belongs to the agent and should be public
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Castell committed Dec 28, 2018
1 parent c5f5de0 commit 1cf235a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions cmd/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -138,3 +139,17 @@ func handleReload() {
}
//Config reloading will also reload Notification settings
}

// UnmarshalTags is a utility function which takes a slice of strings in
// key=value format and returns them as a tag mapping.
func UnmarshalTags(tags []string) (map[string]string, error) {
result := make(map[string]string)
for _, tag := range tags {
parts := strings.SplitN(tag, "=", 2)
if len(parts) != 2 || len(parts[0]) == 0 {
return nil, fmt.Errorf("Invalid tag: '%s'", tag)
}
result[parts[0]] = parts[1]
}
return result, nil
}
4 changes: 2 additions & 2 deletions cmd/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ func getEnvWithDefault() string {
return ea
}

func Test_unmarshalTags(t *testing.T) {
func TestUnmarshalTags(t *testing.T) {
tagPairs := []string{
"tag1=val1",
"tag2=val2",
}

tags, err := unmarshalTags(tagPairs)
tags, err := UnmarshalTags(tagPairs)

if err != nil {
t.Fatalf("err: %s", err)
Expand Down

0 comments on commit 1cf235a

Please sign in to comment.