From cc8263fb876b44a25960bc553ed13b9fbbef18e6 Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期三, 24 四月 2024 18:50:08 +0800 Subject: [PATCH] 添加1400客户端 --- client/client.go | 15 +++++++ client/system.go | 49 ++++++++++++++++++++++++ config/config.go | 17 ++++++++ go.sum | 2 + go.mod | 1 main.go | 4 ++ 6 files changed, 88 insertions(+), 0 deletions(-) diff --git a/client/client.go b/client/client.go new file mode 100644 index 0000000..d1004d8 --- /dev/null +++ b/client/client.go @@ -0,0 +1,15 @@ +package client + +import ( + "gat1400Exchange/config" + "gat1400Exchange/pkg/logger" +) + +func Init1400Client() { + if !config.ClientConf.Enable { + logger.Debug("GAT/1400 Client disabled") + return + } + + register() +} diff --git a/client/system.go b/client/system.go new file mode 100644 index 0000000..805d169 --- /dev/null +++ b/client/system.go @@ -0,0 +1,49 @@ +package client + +import ( + "fmt" + "io/ioutil" + + "gat1400Exchange/config" + "gat1400Exchange/pkg/logger" + + dac "github.com/xinsnake/go-http-digest-auth-client" +) + +const ( + RegisterUrI = "/VIID/System/Register" + UnRegisterUrI = "/VIID/System/UnRegister" + KeepaliveUrI = "/VIID/System/Keepalive" + TimeUrI = "/VIID/System/Time" +) + +func register() { + url := fmt.Sprintf("http://%s:%s%s", config.ClientConf.ServerAddr, config.ClientConf.ServerPort, RegisterUrI) + dr := dac.NewRequest(config.ClientConf.Username, config.ClientConf.Password, "GET", url, "") + resp, err := dr.Execute() + if err != nil { + logger.Error(err.Error()) + return + } + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + logger.Error(err.Error()) + return + } + + fmt.Printf(string(body)) +} + +func keepalive() { + +} + +func unRegister() { + +} + +func syncTime() { + +} diff --git a/config/config.go b/config/config.go index 97fdb61..6802574 100644 --- a/config/config.go +++ b/config/config.go @@ -16,6 +16,20 @@ Password string `mapstructure:"password"` } +type client struct { + DeviceID string `mapstructure:"device-id"` + Username string `mapstructure:"username"` + Password string `mapstructure:"password"` + ServerAddr string `mapstructure:"server-addr"` + ServerPort string `mapstructure:"server-port"` + Proto string `mapstructure:"proto" ` // http, https + UploadType string `mapstructure:"upload-type"` // binary, url + ChannelNo string `mapstructure:"channel-number"` // 閫氶亾鍙�, 鍚宨d + HeartbeatInterval int `mapstructure:"heartbeat-interval"` // 蹇冭烦鍛ㄦ湡 + HeartbeatCount int `mapstructure:"heartbeat-count"` // 蹇冭烦瓒呮椂娆℃暟 + Enable bool `mapstructure:"enable"` +} + type logConfig struct { LogWay string `mapstructure:"log-way"` // 鏃ュ織杈撳嚭 Path string `mapstructure:"path"` // 鏃ュ織瀛樺偍璺緞 @@ -29,6 +43,7 @@ ReportInterval int `mapstructure:"report-interval"` RetryInterval int `mapstructure:"retry-interval"` CutFaceImage bool `mapstructure:"cut-face-image"` + Enable bool `mapstructure:"enable"` } type rateLimitConfig struct { @@ -40,6 +55,7 @@ var LogConf = &logConfig{} var ForwardConf = &forward{} var RateLimitConf = &rateLimitConfig{} +var ClientConf = &client{} // Init is an exported method that takes the environment starts the viper // (external lib) and returns the configuration struct. @@ -67,6 +83,7 @@ v.UnmarshalKey("log", LogConf) v.UnmarshalKey("forward", ForwardConf) v.UnmarshalKey("rate-limit", RateLimitConf) + v.UnmarshalKey("client", ClientConf) if LogConf.Level == "" { LogConf.Level = "info" diff --git a/go.mod b/go.mod index 956fd1a..7abc737 100644 --- a/go.mod +++ b/go.mod @@ -59,6 +59,7 @@ github.com/subosito/gotenv v1.6.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect + github.com/xinsnake/go-http-digest-auth-client v0.6.0 // indirect go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.9.0 // indirect golang.org/x/arch v0.7.0 // indirect diff --git a/go.sum b/go.sum index 5eddeba..8f41283 100644 --- a/go.sum +++ b/go.sum @@ -149,6 +149,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/xinsnake/go-http-digest-auth-client v0.6.0 h1:nrYFWDrB2F7VwYlNravXZS0nOtg9axlATH3Jns55/F0= +github.com/xinsnake/go-http-digest-auth-client v0.6.0/go.mod h1:QK1t1v7ylyGb363vGWu+6Irh7gyFj+N7+UZzM0L6g8I= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= diff --git a/main.go b/main.go index 1c8a2cf..b93a388 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ import ( "context" "fmt" + "gat1400Exchange/client" "gat1400Exchange/cron" "net/http" "os" @@ -37,6 +38,9 @@ Handler: r, } + // 鍚姩1400瀹㈡埛绔� + go client.Init1400Client() + // 鍚姩缃戠粶瑙嗛瀛楃鍙犲姞鍣ㄦ湇鍔� go service.NVCSServer() -- Gitblit v1.8.0