Back to godoc.org

Package strpair

v0.0.0-...-1557bcf
Latest Go to latest

The latest major version is .

Published: Aug 13, 2020 | License: Apache-2.0 | Module: github.com/luci/luci-go

Overview

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

func Format

func Format(k, v string) string

Format formats a pair from a key and a value.

func Parse

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.

Example (Hierarchical)

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"))
1
2

type Map

type Map map[string][]string

Map contains parsed string pairs.

func ParseMap

func ParseMap(raw []string) Map

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

func (Map) Add

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

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

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

func (Map) Copy

func (m Map) Copy() Map

Copy returns a deep copy of m.

func (Map) Del

func (m Map) Del(key string)

Del deletes the values associated with key.

func (Map) Format

func (m Map) Format() []string

Format converts m to a sorted list of strings.

func (Map) Get

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

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

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

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier