From 656dfbac05553b88c0b13f14f80d5e0af944be6d Mon Sep 17 00:00:00 2001 From: Shikong <919411476@qq.com> Date: Sat, 16 Oct 2021 15:22:03 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20ini=20=E6=96=87=E4=BB=B6=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=20reflect=20=E5=8F=8D=E5=B0=84=20=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=20ini?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/reflect/ini/conf.ini | 1 + base/reflect/ini/main.go | 13 +++++++++++++ base/time/main.go | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/base/reflect/ini/conf.ini b/base/reflect/ini/conf.ini index 4f5447f..90b9921 100644 --- a/base/reflect/ini/conf.ini +++ b/base/reflect/ini/conf.ini @@ -4,6 +4,7 @@ host=127.0.0.1 port=3306 user=root password=12341234 +master = true # redis 配置 [redis] host= 127.0.0.1 diff --git a/base/reflect/ini/main.go b/base/reflect/ini/main.go index 26ca306..9fc4705 100644 --- a/base/reflect/ini/main.go +++ b/base/reflect/ini/main.go @@ -16,6 +16,7 @@ type IniConfig struct { } type MysqlConfig struct { + Master bool `ini:"master"` Host string `ini:"host"` Port int `ini:"port"` User string `ini:"user"` @@ -151,6 +152,18 @@ func loadIni(filePath string, v interface{}) (err error) { sectionVal.Field(i).SetInt(int64(intVal)) case reflect.String: sectionVal.Field(i).SetString(val) + case reflect.Bool: + boolVal, err := strconv.ParseBool(val) + if err != nil { + return err + } + sectionVal.Field(i).SetBool(boolVal) + case reflect.Float64: + floatVal, err := strconv.ParseFloat(val, 64) + if err != nil { + return err + } + sectionVal.Field(i).SetFloat(floatVal) } break } diff --git a/base/time/main.go b/base/time/main.go index fa24493..3ed507a 100644 --- a/base/time/main.go +++ b/base/time/main.go @@ -69,7 +69,7 @@ func main() { // 03/15 12/24制 小时 // 04 分 // 05 秒 - // 99 毫秒/微妙/纳秒 + // 99 毫秒/微秒/纳秒 fmt.Println(now.Format("2006-01-02 15:04:05.99")) // 字符串 转 时间对象