Documentation
¶
Overview ¶
Package gobag provides a simple utility to read json response without any custom struct. Works for nested json using dot notation
A quick usage ¶
supposed body is a json like this
{"name": "gobag", "amount": 1}
then
var data map[string]interface{}
_ = json.Unmarshal(body, &data)
bag := gobag.Bagify(data)
bag.GetString("name") // gobag
bag.GetInt("amount") // 1
Index ¶
- type Bag
- func (b Bag) Get(key string) interface{}
- func (b Bag) GetArray(key string) []interface{}
- func (b Bag) GetArrayFloat(key string) []float64
- func (b Bag) GetArrayInt(key string) []int
- func (b Bag) GetArrayString(key string) []string
- func (b Bag) GetBool(key string) bool
- func (b Bag) GetFloat(key string) float64
- func (b Bag) GetInt(key string) int
- func (b Bag) GetMapString(key string) map[string]interface{}
- func (b Bag) GetString(key string) string
- func (b Bag) IsEmpty() bool
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
}
Bag only contains contains filtered or unexported fields
func (Bag) GetArray ¶ added in v1.2.0
Get a value of any key including nested key by using dot notation
func (Bag) GetArrayFloat ¶
GetArrayFloat returns value in array of float64 defaults to 0 if any of the member is not float64
func (Bag) GetArrayInt ¶
GetArrayInt returns value in array of integer defaults to 0 if any of the member is not integer
func (Bag) GetArrayString ¶
GetArrayString returns value in array of string defaults to "" if any of the member is not integer
func (Bag) GetMapString ¶ added in v1.1.0
GetMapString returns map[string]interface{}