-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathmain.go
More file actions
44 lines (41 loc) · 1.05 KB
/
main.go
File metadata and controls
44 lines (41 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"log"
"strings"
//monitor "opcua/examples"
httpclient "github.com/ThingsPanel/modbus-protocol-plugin/http_client"
httpserver "github.com/ThingsPanel/modbus-protocol-plugin/http_server"
mqtt "github.com/ThingsPanel/modbus-protocol-plugin/mqtt"
deviceconfig "github.com/ThingsPanel/modbus-protocol-plugin/services"
"github.com/spf13/viper"
)
func main() {
conf()
log.Println("Starting the application...")
LogInIt()
// 启动mqtt客户端
mqtt.InitClient()
// 启动http客户端
httpclient.Init()
deviceconfig.Start()
// 启动http服务
httpserver.Init()
// 订阅平台下发的消息
mqtt.Subscribe()
select {}
}
func conf() {
log.Println("加载配置文件...")
// 设置环境变量前缀
viper.SetEnvPrefix("MODBUS")
// 使 Viper 能够读取环境变量
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.SetConfigType("yaml")
viper.SetConfigFile("./config.yaml")
err := viper.ReadInConfig()
if err != nil {
log.Println(err.Error())
}
log.Println("加载配置文件完成...")
}