Documentation ¶
Overview ¶
基于map[string]interface{}定义的Dic类型,定义一些扩展的方法
Index ¶
- Variables
- type Dic
- func (d Dic) Clear()
- func (d Dic) Contains(key string) bool
- func (d Dic) Copy() Dic
- func (d Dic) Delete(key string) interface{}
- func (d Dic) Equals(obj interface{}) bool
- func (d Dic) Get(key string) interface{}
- func (d Dic) GetBool(key string, defVal bool) bool
- func (d Dic) GetDic(key string) (Dic, error)
- func (d Dic) GetDuration(key string, defVal time.Duration) time.Duration
- func (d Dic) GetFloat32(key string, defVal float32) float32
- func (d Dic) GetFloat64(key string, defVal float64) float64
- func (d Dic) GetInt(key string, defVal int) int
- func (d Dic) GetInt16(key string, defVal int16) int16
- func (d Dic) GetInt32(key string, defVal int32) int32
- func (d Dic) GetInt64(key string, defVal int64) int64
- func (d Dic) GetInt8(key string, defVal int8) int8
- func (d Dic) GetMap(key string) (map[string]interface{}, error)
- func (d Dic) GetString(key string, defVal string) string
- func (d Dic) GetUint(key string, defVal uint) uint
- func (d Dic) GetUint16(key string, defVal uint16) uint16
- func (d Dic) GetUint32(key string, defVal uint32) uint32
- func (d Dic) GetUint64(key string, defVal uint64) uint64
- func (d Dic) GetUint8(key string, defVal uint8) uint8
- func (d Dic) JSON() string
- func (d Dic) Keys() []string
- func (d Dic) LoadJSON(jsonStr string) error
- func (d Dic) Put(key string, value interface{})
- func (d Dic) Set(key string, value interface{}) Dic
- func (d Dic) Size() int
- func (d Dic) String() string
- func (d Dic) ToMap() map[string]interface{}
- func (d Dic) Values() []interface{}
- type SyncDicPair
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrTypeCast = errors.New("failed to type cast")
)
Functions ¶
This section is empty.
Types ¶
type Dic ¶
type Dic map[string]interface{}
Dic 基于map[string]interface{}定义,更方便使用
Example ¶
package main import ( "fmt" "github.com/recallsong/go-utils/container/dic" ) func main() { dic := dic.Dic{ "int": 123, "str": "hello", "dic": dic.New().Set("key", "str_val"), "map": map[string]interface{}{"key": 123}, "slice": []int{1, 2, 3}, } dic["other"] = "other_values" dic.Set("other1", "value1").Set("other2", "value2") fmt.Println(dic) d, _ := dic.GetDic("dic") fmt.Println(d) m, _ := dic.GetDic("map") fmt.Println(m) s := dic.Get("slice") fmt.Println(s) size := dic.Size() fmt.Println(size) keys := dic.Keys() fmt.Println(len(keys)) }
Output: {"dic":{"key":"str_val"},"int":123,"map":{"key":123},"other":"other_values","other1":"value1","other2":"value2","slice":[1,2,3],"str":"hello"} {"key":"str_val"} {"key":123} [1 2 3] 8 8
func (Dic) GetDuration ¶
GetDuration 根据key获取time.Duration类型的值,如果失败则返回defVal
func (Dic) GetFloat32 ¶
GetFloat32 根据key获取float32类型的值,如果值不是float32类型,将返回defVal
func (Dic) GetFloat64 ¶
GetFloat64 根据key获取float64类型的值,如果值不是float64类型,将返回defVal
Click to show internal directories.
Click to hide internal directories.