123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- package cache
- import (
- "fmt"
- "strconv"
- )
- func GetString(v interface{}) string {
- switch result := v.(type) {
- case string:
- return result
- case []byte:
- return string(result)
- default:
- if v != nil {
- return fmt.Sprintf("%v", result)
- }
- }
- return ""
- }
- func GetInt(v interface{}) int {
- switch result := v.(type) {
- case int:
- return result
- case int32:
- return int(result)
- case int64:
- return int(result)
- default:
- if d := GetString(v); d != "" {
- value, _ := strconv.Atoi(d)
- return value
- }
- }
- return 0
- }
- func GetInt64(v interface{}) int64 {
- switch result := v.(type) {
- case int:
- return int64(result)
- case int32:
- return int64(result)
- case int64:
- return result
- default:
- if d := GetString(v); d != "" {
- value, _ := strconv.ParseInt(d, 10, 64)
- return value
- }
- }
- return 0
- }
- func GetFloat64(v interface{}) float64 {
- switch result := v.(type) {
- case float64:
- return result
- default:
- if d := GetString(v); d != "" {
- value, _ := strconv.ParseFloat(d, 64)
- return value
- }
- }
- return 0
- }
- func GetBool(v interface{}) bool {
- switch result := v.(type) {
- case bool:
- return result
- default:
- if d := GetString(v); d != "" {
- value, _ := strconv.ParseBool(d)
- return value
- }
- }
- return false
- }
|