Browse Source

modbus 获取数据并上传

huangyan 7 months ago
parent
commit
70a508b401
2 changed files with 31 additions and 0 deletions
  1. 6 0
      .idea/vcs.xml
  2. 25 0
      configs/config.go

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 25 - 0
configs/config.go

@@ -0,0 +1,25 @@
+package configs
+
+import (
+	"github.com/spf13/viper"
+	"os"
+)
+
+var Config *viper.Viper
+
+func init() {
+	Config = viper.New()
+	dir, _ := os.Getwd()
+
+	_, err := os.Stat(dir + "/config.yaml")
+	if err != nil {
+		panic(any("配置文件不存在,请检查配置文件!"))
+	}
+
+	Config.SetConfigName("config")
+	Config.SetConfigType("yaml")
+	Config.AddConfigPath(dir)
+	if err := Config.ReadInConfig(); err != nil {
+		panic(any(err.Error()))
+	}
+}