1 Star 0 Fork 0

bughou / go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
value.go 729 Bytes
一键复制 编辑 原始数据 按行查看 历史
bughou 提交于 2022-03-24 11:57 . 迁移完成
package xlsx
import (
"reflect"
"time"
"gitee.com/go-better/dev/algo/find"
)
func GetValue(value reflect.Value, names []string) (interface{}, bool) {
value = find.Find(value, names)
if value.IsValid() {
return format(value), true
}
return nil, false
}
func format(value reflect.Value) interface{} {
switch value.Kind() {
case reflect.Ptr, reflect.Interface:
if value.IsNil() {
return ``
}
value = value.Elem()
}
ifc := value.Interface()
switch v := ifc.(type) {
case bool:
if v {
return "是"
} else {
return "否"
}
case time.Time:
return formatTime(v)
}
return ifc
}
func formatTime(t time.Time) string {
if t.IsZero() {
return ""
}
return t.Format(`2006-01-02 15:04:05`)
}
Go
1
https://gitee.com/bughou/go.git
git@gitee.com:bughou/go.git
bughou
go
go
d31700df43a9

搜索帮助

53164aa7 5694891 3bd8fe86 5694891