Browse Source

Add module 'easy_toml_config'.

ZRY 8 months ago
parent
commit
ef8554ea9e
3 changed files with 23 additions and 0 deletions
  1. 19 0
      easy_toml_config/easy_toml_config.go
  2. 3 0
      easy_toml_config/go.mod
  3. 1 0
      go.work

+ 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
 	websubsvc
 	svcfw
+	easy_toml_config
 )