gomap

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: MIT Imports: 11 Imported by: 0

README

map

this is a map extension package

you can use it transfers a map to xmp or to json or to struct, you can use it for transfer map<=>struct<=>xml its implements the sub map value edit , you can use "." to edit the sub map

    //create a map
    m:=New()
    //set a value to map
    m.Set("key","value")
    //set an array to map
    m.Set("array_key",[]string{"value1","value2"})
    //set a value to key->sub_key
    m.Set("key.sub_key","value")
    

    //get a value from map
    v :=m.Get("key")
    //get an array from map
    v := m.GetStringArray("array_key")
    //get a value from map with default
    v := m.GetD("key","default_value")

    //marshal map to json
    v.ToJSON()
    //marshal map to xml
    v.ToXML()

    //get the map copy with deep copy
    v.Clone()

    //copy the value from m to v
    v.Join(m)

    //transfer the map to map[string]interface
    v.ToGoMap()

    //merge all values from v to m
    Merge(m,v)
    
    //transfer the struct to map
    StructToMap(&strcut{/*your strcut*/})

    type Struct1 struct{
        Value string 
}           
    type Struct2 struct {
        S1 Struct1
}

    exampleWithSubMap := StructToMap(&Struct2{})
    //to get the Value
    exampleWithSubMap.GetString("S1.Value")




Documentation

Index

Constants

View Source
const CustomHeader = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>`

CustomHeader xml header

Variables

View Source
var ErrNilMap = errors.New("nil map")

ErrNilMap ...

Functions

func ParseInt

func ParseInt(v interface{}) (int64, bool)

ParseInt parse interface to int64

func ParseNumber

func ParseNumber(v interface{}) (float64, bool)

ParseNumber parse interface to number

func ParseString

func ParseString(v interface{}) (string, bool)

ParseString parse interface to string

func ToString

func ToString(s string) fmt.Stringer

ToString ... @Description: @param string @return fmt.Stringer

Types

type CDATA

type CDATA struct {
	XMLName xml.Name
	Value   string `xml:",cdata"`
}

CDATA xml cdata defines

type JSONer

type JSONer interface {
	ParseJson([]byte) error
	ToJSON() (v []byte, err error)
}

JSONer ...

type Map

type Map map[string]interface{}

Map ...

func Merge

func Merge(maps ...Map) Map

Merge marge all maps to target Map, the newer value will replace the older value

func New

func New() Map

New ...

func StructToMap

func StructToMap(s interface{}) Map

StructToMap ...

func ToMap

func ToMap(p interface{}) Map

ToMap transfer to map[string]interface{} or MapAble to GMap

func (Map) Append

func (m Map) Append(p Map) Map

Append append source map to target map; if the key value is exist and it is a []interface value, this will append into it otherwise, it will replace the value

func (Map) AppendArray added in v0.0.6

func (m Map) AppendArray(key string, v ...interface{}) Map

AppendArray ... @Description: append array interface to key @receiver Map @param string @param ...interface{} @return Map

func (Map) Check

func (m Map) Check(s ...string) int

Check check all input keys return -1 if all is exist return index when not found

func (Map) Clone

func (m Map) Clone() Map

Clone copy a map

func (Map) Delete

func (m Map) Delete(key string) bool

Delete ... @Description: delete key value if key is exist @receiver Map @param string @return bool

func (Map) DeletePath

func (m Map) DeletePath(keys []string) bool

DeletePath delete keys value if keys is exist

func (Map) Expect

func (m Map) Expect(keys []string) Map

Expect get map expect keys

func (Map) Get

func (m Map) Get(s string) interface{}

Get ... @Description: get interface from map without default @receiver Map @param string @return interface{}

func (Map) GetArray

func (m Map) GetArray(s string) []interface{}

GetArray ... @Description: get []interface value without default @receiver Map @param string @return []interface{}

func (Map) GetArrayD

func (m Map) GetArrayD(s string, d []interface{}) []interface{}

GetArrayD ... @Description: get []interface value with default @receiver Map @param string @param []interface{} @return []interface{}

func (Map) GetBool

func (m Map) GetBool(s string) bool

GetBool ... @Description: get bool from map with out default @receiver Map @param string @return bool

func (Map) GetBoolD

func (m Map) GetBoolD(s string, b bool) bool

GetBoolD ... @Description: get bool from map with default @receiver Map @param string @param bool @return bool

func (Map) GetBytes

func (m Map) GetBytes(s string) []byte

GetBytes ... @Description: get bytes from map with default @receiver Map @param string @return []byte

func (Map) GetBytesD

func (m Map) GetBytesD(s string, d []byte) []byte

GetBytesD ... @Description: get bytes from map with default @receiver Map @param string @param []byte @return []byte

func (Map) GetD

func (m Map) GetD(s string, d interface{}) interface{}

GetD ... @Description: get interface from map with default @receiver Map @param string @param interface{} @return interface{}

func (Map) GetInt64

func (m Map) GetInt64(s string) (int64, bool)

GetInt64 ... @Description: get int64 from map with out default @receiver Map @param string @return int64 @return bool

func (Map) GetInt64D

func (m Map) GetInt64D(s string, d int64) int64

GetInt64D ... @Description: get int64 from map with default @receiver Map @param string @param int64 @return int64

func (Map) GetMap

func (m Map) GetMap(s string) Map

GetMap ... @Description: get map from map without default @receiver Map @param string @return Map

func (Map) GetMapArray

func (m Map) GetMapArray(s string) []Map

GetMapArray get map from map with out default

func (Map) GetMapArrayD

func (m Map) GetMapArrayD(s string, d []Map) []Map

GetMapArrayD ... @Description: get gomap from gomap with default @receiver Map @param string @param []Map @return []Map

func (Map) GetMapD

func (m Map) GetMapD(s string, d Map) Map

GetMapD ... @Description: get map from map with default @receiver Map @param string @param Map @return Map

func (Map) GetNumber

func (m Map) GetNumber(s string) (float64, bool)

GetNumber ... @Description: get float64 from map with out default @receiver Map @param string @return float64 @return bool

func (Map) GetNumberD

func (m Map) GetNumberD(s string, d float64) float64

GetNumberD ... @Description: get float64 from map with default @receiver Map @param string @param float64 @return float64

func (Map) GetPath

func (m Map) GetPath(keys []string) interface{}

GetPath returns the element in the tree indicated by 'keys'. If keys is of length zero, the current tree is returned.

func (Map) GetString

func (m Map) GetString(s string) string

GetString ... @Description: get string from map with out default @receiver Map @param string @return string

func (Map) GetStringArray

func (m Map) GetStringArray(s string) []string

GetStringArray ... @Description: get string from map without default @receiver Map @param string @return []string

func (Map) GetStringArrayD

func (m Map) GetStringArrayD(s string, d []string) []string

GetStringArrayD ... @Description: get string from map with default @receiver Map @param string @param []string @return []string

func (Map) GetStringD

func (m Map) GetStringD(s string, d string) string

GetStringD ... @Description: get string from map with default @receiver Map @param string @param string @return string

func (Map) Has

func (m Map) Has(key string) bool

Has check if key exist

func (Map) HasPath

func (m Map) HasPath(keys []string) bool

HasPath returns true if the given path of keys exists, false otherwise.

func (Map) Join

func (m Map) Join(s Map) Map

Join insert map s to m with out replace

func (Map) MarshalXML

func (m Map) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML ...

func (Map) Only

func (m Map) Only(keys []string) Map

Only get map with keys

func (Map) ParseJSON

func (m Map) ParseJSON(b []byte) error

ParseJSON parse JSON bytes to map

func (Map) ParseXML

func (m Map) ParseXML(b []byte) error

ParseXML parse XML bytes to map

func (Map) Range

func (m Map) Range(f func(key string, value interface{}) bool)

Range range all maps

func (Map) Replace

func (m Map) Replace(s string, v interface{}) Map

Replace replace will set value, if the key is exist

func (Map) ReplaceFromMap

func (m Map) ReplaceFromMap(s string, v Map) Map

ReplaceFromMap replace will set value from other map, if the key is exist from the both map

func (Map) ReplaceJoin

func (m Map) ReplaceJoin(s Map) Map

ReplaceJoin insert map s to m with replace

func (Map) Set

func (m Map) Set(key string, v interface{}) Map

Set ... @Description: set interface @receiver Map @param string @param interface{} @return Map

func (Map) SetNil

func (m Map) SetNil(s string, v interface{}) Map

SetNil set value, if the key is not exist

func (Map) SetPath

func (m Map) SetPath(keys []string, v interface{}) Map

SetPath is the same as SetPath, but allows you to provide comment information to the key, that will be reused by Marshal().

func (Map) SortKeys

func (m Map) SortKeys() []string

SortKeys 排列key

func (Map) String

func (m Map) String() string

String transfer map to JSON string

func (Map) ToEncodeURL

func (m Map) ToEncodeURL() string

ToEncodeURL transfer map to url encode

func (Map) ToGoMap

func (m Map) ToGoMap() map[string]interface{}

ToGoMap trans return a map[string]interface from Map

func (Map) ToJSON

func (m Map) ToJSON() (v []byte, err error)

ToJSON transfer map to JSON

func (Map) ToMap

func (m Map) ToMap() Map

ToMap implements MapAble by self

func (Map) ToStruct

func (m Map) ToStruct(v interface{}) (e error)

ToStruct transfer Map to struct

func (Map) ToXML

func (m Map) ToXML() ([]byte, error)

ToXML transfer map to XML

func (Map) UnmarshalXML

func (m Map) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML ...

type Mapper

type Mapper interface {
	ToMap() Map
}

Mapper ...

type String

type String string

String String

func (String) String

func (s String) String() string

String String

type Stringer

type Stringer interface {
	String() string
}

Stringer ...

type XMLer

type XMLer interface {
	ParseXML([]byte) error
	ToXML() []byte
}

XMLer ...

Jump to

Keyboard shortcuts

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