strpair

package
Version: v0.0.0-...-51f9457 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

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

Constants

This section is empty.

Variables

This section is empty.

Functions

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)
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

Types

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.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL