Sfoglia il codice sorgente

Merge branch 'lq' of terry/ipole_edge_server into master

lq 3 mesi fa
parent
commit
2f66f67f46

+ 1 - 0
.gitignore

@@ -20,3 +20,4 @@
 /vendor
 /build
 /conf
+/.idea/ipole_edge_server.iml

+ 6 - 5
common/models/devicealarm.go

@@ -31,17 +31,18 @@ func (o DeviceAlarm) Update() error {
 	return err
 }
 
-//用于web端告警信息同步
+// 用于web端告警信息同步
+// todo  lq 该查询还有优化空间,可以考虑使用UNION ALL优化
 func GetUpdateAlarm(id uint64, update string) ([]DeviceAlarm, error) {
 	var array []DeviceAlarm
 	err := G_db.Model(&DeviceAlarm{}).Where("id > ? OR updated_at > ?", id, update).Order("id asc").Find(&array).Error
 	return array, err
 }
 
-//获取告警信息
-//flag=0获取所有告警信息
-//flag=1获取结束的告警信息
-//flag=2获取未结束的告警信息
+// 获取告警信息
+// flag=0获取所有告警信息
+// flag=1获取结束的告警信息
+// flag=2获取未结束的告警信息
 func GetAlarmByCodes(codes []string, flag int) ([]DeviceAlarm, error) {
 	var array []DeviceAlarm
 	var err error

+ 26 - 0
common/util/httpclient.go

@@ -0,0 +1,26 @@
+package util
+
+import (
+	"net"
+	"net/http"
+	"time"
+)
+
+var DefaultHTTPClient *http.Client
+
+func init() {
+	DefaultHTTPClient = &http.Client{
+		Timeout: 30 * time.Second,
+		Transport: &http.Transport{
+			DialContext: (&net.Dialer{
+				Timeout:   3 * time.Second,
+				KeepAlive: 30 * time.Second,
+			}).DialContext,
+			MaxIdleConns:          100,
+			MaxIdleConnsPerHost:   10,
+			IdleConnTimeout:       90 * time.Second,
+			TLSHandshakeTimeout:   5 * time.Second,
+			ExpectContinueTimeout: 1 * time.Second,
+		},
+	}
+}

+ 16 - 1
edge/led_screen/clt_client/httpclient_led.go

@@ -1,8 +1,10 @@
 package clt_client
 
 import (
+	"net"
 	"net/http"
 	"sync"
+	"time"
 )
 
 var once sync.Once
@@ -11,7 +13,20 @@ var CltClient cltclient
 func GetClient() cltclient {
 	once.Do(func() {
 		CltClient = cltclient{
-			http.Client{},
+			HttpClient: http.Client{
+				Timeout: 30 * time.Second,
+				Transport: &http.Transport{
+					DialContext: (&net.Dialer{
+						Timeout:   3 * time.Second,
+						KeepAlive: 30 * time.Second,
+					}).DialContext,
+					MaxIdleConns:          100,
+					MaxIdleConnsPerHost:   10,
+					IdleConnTimeout:       90 * time.Second,
+					TLSHandshakeTimeout:   5 * time.Second,
+					ExpectContinueTimeout: 1 * time.Second,
+				},
+			},
 		}
 		CltClient.LoadVsn()
 	})