bag

package module
v0.0.0-...-1190520 Latest Latest
Warning

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

Go to latest
Published: May 30, 2013 License: MIT Imports: 1 Imported by: 2

README

Bag

Build Status

Package bag implements some utility methods on top of a generic map in order to minimize the number of written type assertions in your project.

Documentation

Documentation is available at godoc.org

License

This code is free to use and distribute, under the MIT license.

Documentation

Overview

Package bag implements some utility methods on top of a generic map in order to minimize the number of written type assertions in your project.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bag

type Bag struct {
	// contains filtered or unexported fields
}

A Bag uses a map[string]interface{} to hold data. It is safe for concurrent use.

func From

func From(m map[string]interface{}) *Bag

Instantiates a Bag from an already existing map

func NewBag

func NewBag() *Bag

Instantiates a Bag

Example
bag := NewBag()
bag.Set("foo", "hey, this is a string and here is a number:")
bag.Set("bar", 42)

fmt.Println(bag.GetString("foo"), bag.GetInt("bar"))
Output:

hey, this is a string and here is a number: 42

func (*Bag) Get

func (b *Bag) Get(key string) (value interface{})

Returns value associated to key.

func (*Bag) GetBool

func (b *Bag) GetBool(key string) bool

Same as GetString but with the bool type

func (*Bag) GetByteSlice

func (b *Bag) GetByteSlice(key string) (value []byte)

func (*Bag) GetInt

func (b *Bag) GetInt(key string) int

Same as GetString but with the int type

func (*Bag) GetMapStringString

func (b *Bag) GetMapStringString(key string) map[string]string

func (*Bag) GetString

func (b *Bag) GetString(key string) string

Equivalent to Get but does a string type assertion on the value. ok is the result of the type assertion.

func (*Bag) Has

func (b *Bag) Has(key string) bool

Has() returns true if key is present in data

func (*Bag) Map

func (b *Bag) Map() map[string]interface{}

Returns the underlying map

func (*Bag) Set

func (b *Bag) Set(key string, value interface{})

Jump to

Keyboard shortcuts

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