主备机接口

main
wangbin 2 months ago
parent 3bf587648a
commit 62a6242dd6

@ -1024,3 +1024,27 @@ func FormatTimes(now time.Time, format string) string {
return now.Format(format)
}
func CheckIPReachable(ip string, port int, timeout time.Duration) bool {
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, port), timeout)
if err != nil {
return false
}
conn.Close()
return true
}
func GetAvailableEndpoint() string {
primaryIP := LoadConfig().SeverData.ServerIP
backupIP := LoadConfig().SeverData.BackUpServerIP // 替换为实际备选IP
port := 9800
timeout := 3 * time.Second
if CheckIPReachable(primaryIP, port, timeout) {
return primaryIP
}
if CheckIPReachable(backupIP, port, timeout) {
return backupIP
}
return ""
}

@ -1817,7 +1817,15 @@ func GetAgenda(AgID string) {
//通过接口获取会议,人员信息
var agendaPersons []Model.T_AgendaPerson = make([]Model.T_AgendaPerson, 0)
url := "http://" + Common.LoadConfig().SeverData.ServerIP + ":9800/vhwcapi/v1/web/api/service/congresscontrol/getpersonforcheckdoor"
targetIP := Common.GetAvailableEndpoint()
if targetIP == "" {
log.Error("所有IP均不可达")
log.Println("所有IP均不可达")
return
}
url := "http://" + targetIP + ":9800/vhwcapi/v1/web/api/service/congresscontrol/getpersonforcheckdoor"
jsonData := `{}`
body, statusCode, err := Common.SendPostRequest(url, jsonData, "application/json")
if err != nil {

Loading…
Cancel
Save