zhangzengfei
2024-04-24 cc8263fb876b44a25960bc553ed13b9fbbef18e6
添加1400客户端
2个文件已添加
4个文件已修改
88 ■■■■■ 已修改文件
client/client.go 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
client/system.go 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
config/config.go 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
go.mod 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
go.sum 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
client/client.go
New file
@@ -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()
}
client/system.go
New file
@@ -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() {
}
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"`     // 通道号, 同id
    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"
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
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=
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()