data

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2022 License: Apache-2.0 Imports: 6 Imported by: 7

README

data

Some utilities for handling data in Go.

  • object.go - a map that preserves key order during JSON round trip
  • decimal.go - a wrapper for math/big.Float that marshals to/from JSON
  • misc.go - some miscellaneous helpers

Documentation

Overview

Decimal is a big.Float equivalent that marshals to/from JSON.

Index

Constants

View Source
const DecimalPrecision = uint(250)

we establish this "reasonable" max precision

Variables

This section is empty.

Functions

func AsArray

func AsArray(v interface{}) []interface{}

func AsBool

func AsBool(v interface{}) bool

func AsFloat64

func AsFloat64(v interface{}) float64

func AsInt

func AsInt(v interface{}) int

func AsInt64

func AsInt64(v interface{}) int64

func AsMap

func AsMap(v interface{}) map[string]interface{}

func AsString

func AsString(v interface{}) string

func AsStringArray

func AsStringArray(v interface{}) []string

func Equivalent

func Equivalent(obj1 interface{}, obj2 interface{}) bool

func Get

func Get(m map[string]interface{}, key string) interface{}

func GetArray

func GetArray(m map[string]interface{}, key string) []interface{}

func GetBool

func GetBool(m map[string]interface{}, key string) bool

func GetInt

func GetInt(m map[string]interface{}, key string) int

func GetInt64

func GetInt64(m map[string]interface{}, key string) int64

func GetMap

func GetMap(m map[string]interface{}, key string) map[string]interface{}

func GetString

func GetString(m map[string]interface{}, key string) string

func GetStringArray

func GetStringArray(m map[string]interface{}, key string) []string

func Json

func Json(obj interface{}) string

func JsonKeysInOrder

func JsonKeysInOrder(data []byte) ([]string, error)

func Kind

func Kind(v interface{}) string

func Pretty

func Pretty(obj interface{}) string

func ToString

func ToString(obj interface{}) string

Types

type Decimal

type Decimal struct {
	big.Float
}

func AsDecimal

func AsDecimal(v interface{}) *Decimal

func DecimalValue

func DecimalValue(val *Decimal, defval interface{}) *Decimal

func GetDecimal

func GetDecimal(m map[string]interface{}, key string) *Decimal

func NewDecimal

func NewDecimal(val float64) *Decimal

func ParseDecimal

func ParseDecimal(text string) (*Decimal, error)

func (*Decimal) AsBigFloat

func (d *Decimal) AsBigFloat() *big.Float

func (*Decimal) AsFloat64

func (d *Decimal) AsFloat64() float64

func (*Decimal) AsInt

func (d *Decimal) AsInt() int

func (*Decimal) AsInt32

func (d *Decimal) AsInt32() int32

func (*Decimal) AsInt64

func (d *Decimal) AsInt64() int64

func (Decimal) MarshalJSON

func (d Decimal) MarshalJSON() ([]byte, error)

Encode as a JSON number. The JSON spec allows for arbitrary precision, so this is the correct thing to do.

func (*Decimal) String

func (d *Decimal) String() string

func (*Decimal) UnmarshalJSON

func (d *Decimal) UnmarshalJSON(b []byte) error

type Object

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

data.Object - a map that preserves the order of the keys (which are always converted

to strings). Values can be anything.

func AsObject

func AsObject(v interface{}) *Object

func NewObject

func NewObject() *Object

func ObjectFromMap

func ObjectFromMap(m map[string]interface{}) *Object

func (*Object) Get

func (s *Object) Get(key string) interface{}

func (*Object) GetArray

func (s *Object) GetArray(key string) []interface{}

func (*Object) GetBool

func (s *Object) GetBool(key string) bool

func (*Object) GetDecimal

func (s *Object) GetDecimal(key string) *Decimal

func (*Object) GetInt

func (s *Object) GetInt(key string) int

func (*Object) GetInt64

func (s *Object) GetInt64(key string) int64

func (*Object) GetMap

func (s *Object) GetMap(key string) map[string]interface{}

func (*Object) GetObject

func (s *Object) GetObject(key string) *Object

func (*Object) GetString

func (s *Object) GetString(key string) string

func (*Object) GetStringArray

func (s *Object) GetStringArray(key string) []string

func (*Object) Has

func (s *Object) Has(key string) bool

func (*Object) Keys

func (s *Object) Keys() []string

func (*Object) Length

func (s *Object) Length() int

func (Object) MarshalJSON

func (s Object) MarshalJSON() ([]byte, error)

func (*Object) Put

func (s *Object) Put(key string, val interface{})

func (*Object) String

func (s *Object) String() string

func (*Object) UnmarshalJSON

func (s *Object) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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