Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddMapToContext ¶
AddMapToContext returns a context that has ctx as its parent context and has fields populated from the keys and values in m.
Example ¶
package main import ( "context" "fmt" "github.com/kanisterio/kanister/pkg/field" ) type M = field.M func main() { ctx := field.AddMapToContext(context.Background(), M{"foo": "bar"}) fmt.Print(field.FromContext(ctx)) }
Output: ["foo":"bar"]
Example (Multiple) ¶
package main import ( "context" "fmt" "github.com/kanisterio/kanister/pkg/field" ) type M = field.M func main() { ctx := field.AddMapToContext(context.Background(), M{"foo": "bar", "x": "y"}) // Output is not specified because the order of the fields in 'M' is non-deterministic fmt.Print(field.FromContext(ctx)) }
Output:
func Context ¶
Context returns a new context that has ctx as its parent context and has a Field with the given key and value.
Example ¶
package main import ( "context" "fmt" "github.com/kanisterio/kanister/pkg/field" ) func main() { ctx := field.Context(context.Background(), "foo", "bar") fmt.Print(field.FromContext(ctx)) }
Output: ["foo":"bar"]
Types ¶
type Field ¶
type Field interface { Key() string Value() interface{} }
Field is a tuple with a string key and a value of any type
type Fields ¶
type Fields = Fieldser
Fields is an alias for Fieldser to make the interface friendlier. It seems easier to talk about fields than fieldser(s)
func Add ¶
Add returns a collection with all the fields in s plus a new field with the given key and value. Duplicates are not eliminated.
Example ¶
package main import ( "fmt" "github.com/kanisterio/kanister/pkg/field" ) func main() { f := field.New("foo", "bar") f = field.Add(f, "baz", "x") fmt.Print(f) }
Output: ["foo":"bar","baz":"x"]
func FromContext ¶
FromContext returns the fields present in ctx if any
Click to show internal directories.
Click to hide internal directories.