Skip to content

Commit

Permalink
add uint/uint8/uint16/uint32/uint64
Browse files Browse the repository at this point in the history
  • Loading branch information
shockerli committed Mar 9, 2021
1 parent fad1814 commit 68df522
Show file tree
Hide file tree
Showing 4 changed files with 1,049 additions and 0 deletions.
65 changes: 65 additions & 0 deletions cvt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,68 @@ func Bool(v interface{}, def ...bool) bool {

return false
}

// Uint64 convert an interface to a uint64 type, with default value
func Uint64(v interface{}, def ...uint64) uint64 {
if v, err := Uint64E(v); err == nil {
return v
}

if len(def) > 0 {
return def[0]
}

return 0
}

// Uint32 convert an interface to a uint32 type, with default value
func Uint32(v interface{}, def ...uint32) uint32 {
if v, err := Uint32E(v); err == nil {
return v
}

if len(def) > 0 {
return def[0]
}

return 0
}

// Uint16 convert an interface to a uint16 type, with default value
func Uint16(v interface{}, def ...uint16) uint16 {
if v, err := Uint16E(v); err == nil {
return v
}

if len(def) > 0 {
return def[0]
}

return 0
}

// Uint8 convert an interface to a uint8 type, with default value
func Uint8(v interface{}, def ...uint8) uint8 {
if v, err := Uint8E(v); err == nil {
return v
}

if len(def) > 0 {
return def[0]
}

return 0
}

// Uint convert an interface to a uint type, with default value
func Uint(v interface{}, def ...uint) uint {
if v, err := UintE(v); err == nil {
return v
}

if len(def) > 0 {
return def[0]
}

return 0
}
Loading

0 comments on commit 68df522

Please sign in to comment.