123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package client
- import (
- "fmt"
- "time"
- )
- func ToStrings(data interface{}) []string {
- var i []string
- if vv, ok := data.([]interface{}); ok {
- for _, in := range vv {
- i = append(i, fmt.Sprint(in))
- }
- }
- return i
- }
- func ToString(data interface{}) string {
- if data == nil {
- return ""
- }
- return fmt.Sprint(data)
- }
- func ToFloat64(data interface{}) float64 {
- var i float64
- if vv, ok := data.(float64); ok {
- i = vv
- return i
- }
- if vv, ok := data.(int64); ok {
- i = float64(vv)
- return i
- }
- return i
- }
- func ToFloat32(data interface{}) float32 {
- if v, ok := data.(float32); ok {
- return v
- }
- if v, ok := data.(float64); ok {
- return float32(v)
- }
- if v, ok := data.(int64); ok {
- return float32(v)
- }
- return 0
- }
- const (
- GRPC_DATETIME_FROM_SQL_FORMAT = "2006-01-02T15:04:05.999999999-07:00"
- GRPC_DATETIME_FROM_SQL_FORMAT2 = "2006-01-02T15:04:05.999999999Z"
- )
- func ToTime(data interface{}) (*time.Time, error) {
- if v, ok := data.(time.Time); ok {
- return &v, nil
- }
- str := ToString(data)
- dateTime, err := time.Parse(GRPC_DATETIME_FROM_SQL_FORMAT, str)
- if err != nil {
- dateTime, err = time.Parse(GRPC_DATETIME_FROM_SQL_FORMAT2, str)
- if err != nil {
- return nil, err
- }
- }
- return &dateTime, nil
- }
|