luci: go.chromium.org/luci/common/data/strpair Index | Examples | Files

package strpair

import "go.chromium.org/luci/common/data/strpair"

Package strpair implements parsing and formatting of lists of colon-delimited key-value pair strings.

Example of pairs:

master:tryserver.chromium.linux
builder:linux_chromium_rel_ng
buildset:patch/gerrit/chromium-review.googlesource.com/677784/5

Index

Examples

Package Files

pair.go

func Format Uses

func Format(k, v string) string

Format formats a pair from a key and a value.

func Parse Uses

func Parse(pair string) (k, v string)

Parse parses a colon-delimited key-value pair.

If pair does not have ":", the whole string becomes the key with an empty value.

Code:

pairs := []string{
    "foo:bar",
    "swarming_tag:a:1",
    "swarming_tag:b:2",
}
tags := ParseMap(ParseMap(pairs)["swarming_tag"])
fmt.Println(tags.Get("a"))
fmt.Println(tags.Get("b"))

Output:

1
2

type Map Uses

type Map map[string][]string

Map contains parsed string pairs.

func ParseMap Uses

func ParseMap(raw []string) Map

ParseMap parses a list of colon-delimited key-value pair strings.

func (Map) Add Uses

func (m Map) Add(key, value string)

Add adds the value to key. It appends to any existing values associated with key.

func (Map) Contains Uses

func (m Map) Contains(key, value string) bool

Contains returns true if m contains the key-value pair.

func (Map) Copy Uses

func (m Map) Copy() Map

Copy returns a deep copy of m.

func (Map) Del Uses

func (m Map) Del(key string)

Del deletes the values associated with key.

func (Map) Format Uses

func (m Map) Format() []string

Format converts m to a sorted list of strings.

func (Map) Get Uses

func (m Map) Get(key string) string

Get gets the first value associated with the given key. If there are no values associated with the key, Get returns the empty string. To access multiple values, use the map directly.

func (Map) Set Uses

func (m Map) Set(key, value string)

Set sets the key to value. It replaces any existing values.

Package strpair imports 2 packages (graph) and is imported by 15 packages. Updated 2018-10-19. Refresh now. Tools for package owners.