Browse Source

Add module 'easy_toml_config'.

ZRY 9 tháng trước cách đây
mục cha
commit
ef8554ea9e

+ 19 - 0
easy_toml_config/easy_toml_config.go

@@ -0,0 +1,19 @@
+package easy_toml_config
+
+import (
+	"fmt"
+	"github.com/pelletier/go-toml/v2"
+	"os"
+)
+
+func LoadConfigFromFile(filename string, v interface{}) error {
+	f, err := os.ReadFile(filename)
+	if err != nil {
+		return fmt.Errorf("failed read config file '%s': %v", filename, err)
+	}
+	err = toml.Unmarshal(f, v)
+	if err != nil {
+		return fmt.Errorf("failed parse config file '%s': %v", filename, err)
+	}
+	return nil
+}

+ 3 - 0
easy_toml_config/go.mod

@@ -0,0 +1,3 @@
+module git.swzry.com/zry/zry-go-program-framework/easy_toml_config
+
+go 1.20

+ 1 - 0
go.work

@@ -4,4 +4,5 @@ use (
 	core
 	core
 	websubsvc
 	websubsvc
 	svcfw
 	svcfw
+	easy_toml_config
 )
 )