mirror of
https://gitee.com/johng/gf
synced 2026-07-03 20:01:04 +08:00
优化框架gmap/gjson/gparser/gcfg包,增加常用的基本数据类型转换获取方法
This commit is contained in:
@ -9,6 +9,8 @@ package gmap
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"gitee.com/johng/gf/g/util/gconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type StringIntMap struct {
|
||||
@ -68,6 +70,74 @@ func (this *StringIntMap) Get(key string) int {
|
||||
return val
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetBool(key string) bool {
|
||||
return gconv.Bool(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetInt(key string) int {
|
||||
return gconv.Int(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetInt8(key string) int8 {
|
||||
return gconv.Int8(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetInt16(key string) int16 {
|
||||
return gconv.Int16(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetInt32(key string) int32 {
|
||||
return gconv.Int32(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetInt64(key string) int64 {
|
||||
return gconv.Int64(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetUint (key string) uint {
|
||||
return gconv.Uint(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetUint8 (key string) uint8 {
|
||||
return gconv.Uint8(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetUint16 (key string) uint16 {
|
||||
return gconv.Uint16(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetUint32 (key string) uint32 {
|
||||
return gconv.Uint32(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetUint64 (key string) uint64 {
|
||||
return gconv.Uint64(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetFloat32 (key string) float32 {
|
||||
return gconv.Float32(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetFloat64 (key string) float64 {
|
||||
return gconv.Float64(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetString (key string) string {
|
||||
return gconv.String(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetStrings (key string) []string {
|
||||
return gconv.Strings(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetTime (key string, format...string) time.Time {
|
||||
return gconv.Time(this.Get(key), format...)
|
||||
}
|
||||
|
||||
func (this *StringIntMap) GetTimeDuration (key string) time.Duration {
|
||||
return gconv.TimeDuration(this.Get(key))
|
||||
}
|
||||
|
||||
// 获取键值,如果键值不存在则写入默认值
|
||||
func (this *StringIntMap) GetWithDefault(key string, value int) int {
|
||||
this.mu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user