Help us shape the future of Go! Take the 2026 Go Developer Survey

gobag

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2019 License: MIT Imports: 2 Imported by: 0

README

gobag

Built with ❤️

A dead simple utility to read json response without any custom struct. Works for nested json using dot notation

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

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 Bagify

func Bagify(data interface{}) Bag

Bagify constructs Bag by providing anything

func (Bag) Get

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

Get a value of any key including nested key by using dot notation

func (Bag) GetArrayFloat

func (b Bag) GetArrayFloat(key string) []float64

GetArrayFloat returns value in array of float64 defaults to 0 if any of the member is not float64

func (Bag) GetArrayInt

func (b Bag) GetArrayInt(key string) []int

GetArrayInt returns value in array of integer defaults to 0 if any of the member is not integer

func (Bag) GetArrayString

func (b Bag) GetArrayString(key string) []string

GetArrayString returns value in array of string defaults to "" if any of the member is not integer

func (Bag) GetBool

func (b Bag) GetBool(key string) bool

GetBool returns value in boolean

func (Bag) GetFloat

func (b Bag) GetFloat(key string) float64

GetFloat returns value in integer. Works for json numbers

func (Bag) GetInt

func (b Bag) GetInt(key string) int

GetInt returns value in integer. Works for json numbers

func (Bag) GetString

func (b Bag) GetString(key string) string

GetString returns value in string

func (Bag) IsEmpty

func (b Bag) IsEmpty() bool

IsEmpty returns whether the data constructed is empty or not

Jump to

Keyboard shortcuts

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