mapstr

package
v0.0.0-...-be0592b Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2019 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertArrayMapStrInto

func ConvertArrayMapStrInto(datas []MapStr, output interface{}) error

ConvertArrayMapStrInto convert a MapStr array into a new slice instance

func GetTags

func GetTags(target interface{}, tagName string) []string

GetTags parse a object and get the all tags

func IsNil

func IsNil(value interface{}) bool

IsNil returns whether value is nil value, including map[string]interface{}{nil}, *Struct{nil}

func SetValueToStructByTags

func SetValueToStructByTags(target interface{}, values MapStr) error

SetValueToStructByTags set the struct object field value by tags, default tag name is field

func SetValueToStructByTagsWithTagName

func SetValueToStructByTagsWithTagName(target interface{}, values MapStr, tagName string) error

SetValueToStructByTagsWithTagName set the struct object field value by tags

Types

type MapStr

type MapStr map[string]interface{}

MapStr the common event data definition

func New

func New() MapStr

New create a new MapStr instance

func NewArray

func NewArray() []MapStr

NewArray create MapStr array

func NewArrayFromInterface

func NewArrayFromInterface(datas []map[string]interface{}) []MapStr

NewArrayFromInterface create a new array from interface

func NewArrayFromMapStr

func NewArrayFromMapStr(datas []MapStr) []MapStr

NewArrayFromMapStr create a new array from mapstr array

func NewFromInterface

func NewFromInterface(data interface{}) (MapStr, error)

NewFromInterface create a mapstr instance from the interface Support Input Type: []byte, string, base-type map, struct. If the input value type is []byte or string, then the value must be a valid json. Like: map[string]int will be converted into MapStr Like: struct { TestStr string TestInt int } will be converted into MapStr{"TestStr":"", "TestInt":0}

func NewFromMap

func NewFromMap(data map[string]interface{}) MapStr

NewFromMap create a new MapStr from map[string]interface{} type

func NewFromStruct

func NewFromStruct(targetStruct interface{}, tagName string) MapStr

NewFromStruct convert the struct into MapStr , the struct must be taged with 'tagName' .

eg:
type targetStruct struct{
     Name string `field:"testName"`
}
will be converted the follow map
{"testName":""}

func SetValueToMapStrByTags

func SetValueToMapStrByTags(source interface{}) MapStr

SetValueToMapStrByTags convert a struct to MapStr by tags default tag name is field

func SetValueToMapStrByTagsWithTagName

func SetValueToMapStrByTagsWithTagName(source interface{}, tagName string) MapStr

SetValueToMapStrByTagsWithTagName convert a struct to MapStr by tags

func (MapStr) Bool

func (cli MapStr) Bool(key string) (bool, error)

Bool get the value as bool

func (MapStr) Clone

func (cli MapStr) Clone() MapStr

Clone create a new MapStr by deepcopy

func (MapStr) Different

func (cli MapStr) Different(target MapStr) (more MapStr, less MapStr, changes MapStr)

Different the current value is different from the content of the given data

func (MapStr) Exists

func (cli MapStr) Exists(key string) bool

Exists check the key exists

func (MapStr) Float

func (cli MapStr) Float(key string) (float64, error)

Float get the value as float64

func (MapStr) ForEach

func (cli MapStr) ForEach(callItem func(key string, val interface{}) error) error

ForEach for each the every item

func (MapStr) Get

func (cli MapStr) Get(key string) (val interface{}, exists bool)

Get return the origin value by the key

func (MapStr) Int64

func (cli MapStr) Int64(key string) (int64, error)

Int64 return the value by the key

func (MapStr) IsEmpty

func (cli MapStr) IsEmpty() bool

IsEmpty check the empty status

func (MapStr) MapStr

func (cli MapStr) MapStr(key string) (MapStr, error)

MapStr get the MapStr object

func (MapStr) MapStrArray

func (cli MapStr) MapStrArray(key string) ([]MapStr, error)

MapStrArray get the MapStr object array

func (MapStr) MarshalJSONInto

func (cli MapStr) MarshalJSONInto(target interface{}) error

MarshalJSONInto convert to the input value

func (MapStr) Merge

func (cli MapStr) Merge(second MapStr)

Merge merge second into self,if the key is the same then the new value replaces the old value.

func (MapStr) Remove

func (cli MapStr) Remove(key string) interface{}

Remove delete the item by the key and return the deleted one

func (MapStr) Reset

func (cli MapStr) Reset()

Reset reset the mapstr into the init state

func (MapStr) Set

func (cli MapStr) Set(key string, value interface{})

Set set a new value for the key, the old value will be replaced

func (MapStr) String

func (cli MapStr) String(key string) (string, error)

String get the value as string

func (MapStr) Time

func (cli MapStr) Time(key string) (*time.Time, error)

Time get the value as time.Time

func (MapStr) ToJSON

func (cli MapStr) ToJSON() ([]byte, error)

ToJSON convert to json string

func (MapStr) ToMapInterface

func (cli MapStr) ToMapInterface() map[string]interface{}

ToMapInterface convert to map[string]interface{}

func (MapStr) ToStructByTag

func (cli MapStr) ToStructByTag(targetStruct interface{}, tagName string) error

ToStructByTag convert self into a struct with 'tagName'

eg:
self := MapStr{"testName":"testvalue"}
targetStruct := struct{
    Name string `field:"testName"`
}
After call the function self.ToStructByTag(targetStruct, "field")
the targetStruct.Name value will be 'testvalue'

Jump to

Keyboard shortcuts

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