Просмотр исходного кода

@author liuqing
@commit go 1.17 → go 1.21 go版本升级

lq 3 месяцев назад
Родитель
Сommit
40f37cd2e3

+ 1 - 2
cloud/ipolesvr/gwhandler.go

@@ -1,7 +1,6 @@
 package main
 
 import (
-	"io/ioutil"
 	"os"
 	"path/filepath"
 	"runtime"
@@ -328,7 +327,7 @@ func SaveFile(tenant, GID, strType string, fo []protocol.FileObject) {
 		return
 	}
 	for _, v := range fo {
-		if err := ioutil.WriteFile(Dir+v.File, []byte(v.Content), os.ModePerm); err != nil {
+		if err := os.WriteFile(Dir+v.File, []byte(v.Content), os.ModePerm); err != nil {
 			logrus.Errorf("SaveFile:保存模型文件失败,文件名:%s,原因:%s", Dir+v.File, err.Error())
 		}
 	}

+ 2 - 2
cloud/ipolesvr/srsmgr.go

@@ -1,7 +1,7 @@
 package main
 
 import (
-	"io/ioutil"
+	"io"
 	"net/http"
 	"os"
 	"path/filepath"
@@ -192,7 +192,7 @@ type H map[string]interface{}
 
 func (o *SrsMgr) HookHandler(c echo.Context) error {
 	if c.Request().Body != nil {
-		buf, err := ioutil.ReadAll(c.Request().Body)
+		buf, err := io.ReadAll(c.Request().Body)
 		var obj CallbackAPIObject
 		err = json.Unmarshal(buf, &obj)
 		if err != nil {

+ 1 - 2
cloud/mediasvr/main.go

@@ -3,7 +3,6 @@ package main
 import (
 	"encoding/base64"
 	"encoding/json"
-	"io/ioutil"
 	"net/http"
 	"os"
 	"path/filepath"
@@ -52,7 +51,7 @@ func getFile(streams, date string) []string {
 	var fileList []string
 	for _, dir := range config.DvrDir {
 		path := string(filepath.Separator) + dir + string(filepath.Separator) + streams + string(filepath.Separator) + date
-		if rd, err := ioutil.ReadDir(config.Rootdir + path); err == nil {
+		if rd, err := os.ReadDir(config.Rootdir + path); err == nil {
 			for _, fi := range rd {
 				//过滤掉路径和非mp4文件
 				if !fi.IsDir() && strings.HasSuffix(fi.Name(), ".mp4") {

+ 0 - 1
cloud/websvr/controllers/cbase.go

@@ -94,7 +94,6 @@ const (
 func Krand(size int, kind int) []byte {
 	ikind, kinds, result := kind, [][]int{[]int{10, 48}, []int{26, 97}, []int{26, 65}}, make([]byte, size)
 	isAll := kind > 2 || kind < 0
-	rand.Seed(time.Now().UnixNano())
 	for i := 0; i < size; i++ {
 		if isAll {
 			ikind = rand.Intn(3)

+ 9 - 9
cloud/websvr/controllers/ccamera.go

@@ -2,7 +2,7 @@ package controllers
 
 import (
 	"fmt"
-	"io/ioutil"
+	"io"
 	"os"
 	"strconv"
 	"strings"
@@ -437,7 +437,7 @@ func (o *CameraController) Snapshot() {
 	}
 	defer f.Close()
 	f.Seek(0, 0)
-	content, err := ioutil.ReadAll(f)
+	content, err := io.ReadAll(f)
 	if err != nil {
 		return
 	}
@@ -458,7 +458,7 @@ func (o *CameraController) Snapshot() {
 	filepath = filepath + strDate + string(os.PathSeparator)
 	os.MkdirAll(filepath, os.ModePerm)
 	filepath = filepath + fh.Filename
-	err = ioutil.WriteFile(filepath, content, os.ModePerm)
+	err = os.WriteFile(filepath, content, os.ModePerm)
 	if err != nil {
 		beego.Error("Snapshot存储抓图发生错误:", err)
 	}
@@ -474,14 +474,14 @@ func (o *CameraController) PresetPicture() {
 	}
 	defer f.Close()
 	f.Seek(0, 0)
-	content, err := ioutil.ReadAll(f)
+	content, err := io.ReadAll(f)
 	if err != nil {
 		return
 	}
 	filepath := "file" + string(os.PathSeparator) + "preset" + string(os.PathSeparator)
 	os.MkdirAll(filepath, os.ModePerm)
 	filepath = filepath + fh.Filename
-	err = ioutil.WriteFile(filepath, content, os.ModePerm)
+	err = os.WriteFile(filepath, content, os.ModePerm)
 	if err != nil {
 		beego.Error("Snapshot存储抓图发生错误:", err)
 	}
@@ -497,7 +497,7 @@ func (o *CameraController) FLV() {
 	}
 	defer f.Close()
 	f.Seek(0, 0)
-	content, err := ioutil.ReadAll(f)
+	content, err := io.ReadAll(f)
 	if err != nil {
 		return
 	}
@@ -518,7 +518,7 @@ func (o *CameraController) FLV() {
 	filepath = filepath + strDate + string(os.PathSeparator)
 	os.MkdirAll(filepath, os.ModePerm)
 	filepath = filepath + fh.Filename
-	err = ioutil.WriteFile(filepath, content, os.ModePerm)
+	err = os.WriteFile(filepath, content, os.ModePerm)
 	if err != nil {
 		beego.Error("MP4存储发生错误:", err)
 	}
@@ -541,7 +541,7 @@ func (o *CameraController) GetSnapshot() {
 	//dir := "file/snapshot/" + util.MlNow().Format("2006-01-02") + "/"
 	filepath := "file" + string(os.PathSeparator) + "snapshot" + string(os.PathSeparator) +
 		code + string(os.PathSeparator) + date + string(os.PathSeparator)
-	fis, err := ioutil.ReadDir(filepath)
+	fis, err := os.ReadDir(filepath)
 	if err != nil {
 		beego.Error(fmt.Sprintf("未找到该路径[%s],请先抓图", err.Error()))
 		o.Response(Failure, "未找到该路径,请先抓图", nil)
@@ -576,7 +576,7 @@ func (o *CameraController) GetFLV() {
 	//dir := "file/snapshot/" + util.MlNow().Format("2006-01-02") + "/"
 	filepath := "file" + string(os.PathSeparator) + "flv" + string(os.PathSeparator) +
 		code + string(os.PathSeparator) + date + string(os.PathSeparator)
-	fis, err := ioutil.ReadDir(filepath)
+	fis, err := os.ReadDir(filepath)
 	if err != nil {
 		beego.Error(fmt.Sprintf("未找到该路径[%s],请先录制mp4", err.Error()))
 		o.Response(Failure, "未找到该路径,请先录制mp4", nil)

+ 2 - 2
cloud/websvr/controllers/ciotmodel.go

@@ -2,7 +2,7 @@ package controllers
 
 import (
 	"fmt"
-	"io/ioutil"
+	"io"
 
 	"github.com/astaxie/beego"
 
@@ -44,7 +44,7 @@ func (o *IotModelController) ModelUpload() {
 	defer f.Close()
 
 	f.Seek(0, 0)
-	content, err := ioutil.ReadAll(f)
+	content, err := io.ReadAll(f)
 	if err != nil {
 		o.Response(Failure, fmt.Sprintf("读文件错误:%s", err.Error()), nil)
 		return

+ 1 - 2
common/configor/utils.go

@@ -5,7 +5,6 @@ import (
 	"errors"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"os"
 	"path"
 	"reflect"
@@ -101,7 +100,7 @@ func (configor *Configor) getConfigurationFiles(watchMode bool, files ...string)
 }
 
 func processFile(config interface{}, file string, errorOnUnmatchedKeys bool) error {
-	data, err := ioutil.ReadFile(file)
+	data, err := os.ReadFile(file)
 	if err != nil {
 		return err
 	}

+ 0 - 3
common/onvif/examples/discovery/discovery.go

@@ -2,11 +2,8 @@ package main
 
 import (
 	"fmt"
-	"log"
 	"time"
 
-	"github.com/kr/pretty"
-
 	"lc/common/onvif/discovery"
 	"lc/common/onvif/profiles/devicemgmt"
 	"lc/common/onvif/profiles/media"

+ 0 - 3
common/onvif/examples/recording/recording.go

@@ -1,11 +1,8 @@
 package main
 
 import (
-	"log"
 	"time"
 
-	"github.com/kr/pretty"
-
 	"lc/common/onvif/profiles/recording"
 	"lc/common/onvif/soap"
 )

+ 2 - 2
common/onvif/soap/soap.go

@@ -3,6 +3,7 @@ package soap
 import (
 	"bytes"
 	"context"
+	crand "crypto/rand"
 	"crypto/sha1"
 	"crypto/tls"
 	"encoding/base64"
@@ -207,10 +208,9 @@ func NewWSSSecurityHeader(user, pass string) *WSSSecurityHeader {
 
 	// Nonce
 	b := make([]byte, 16)
-	rand.Read(b)
+	crand.Read(b)
 	//nonce := fmt.Sprintf("%x-%x-%x-%x-%x",
 	//	b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
-	rand.Seed(time.Now().UnixNano())
 	nonce := randomString(20)
 
 	hdr.UsernameToken.Nonce.EncodingType = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"

+ 2 - 2
common/util/gzip.go

@@ -3,7 +3,7 @@ package util
 import (
 	"bytes"
 	"compress/gzip"
-	"io/ioutil"
+	"io"
 )
 
 func GzipEncode(in []byte) ([]byte, error) {
@@ -34,5 +34,5 @@ func GzipDecode(in []byte) ([]byte, error) {
 	}
 	defer reader.Close()
 
-	return ioutil.ReadAll(reader)
+	return io.ReadAll(reader)
 }

+ 2 - 3
edge/camera/ipc_media.go

@@ -2,7 +2,6 @@ package main
 
 import (
 	"errors"
-	"io/ioutil"
 	"net/http"
 	"os"
 	"strconv"
@@ -220,7 +219,7 @@ func (o *LcDevice) Snapshot(token string) {
 			fileName, err = o.SnapshotFromRtsp(token)
 		} else {
 			fileName = util.GetPath(4) + o.onvifDev.Code + "_" + strconv.FormatInt(util.MlNow().Unix(), 10) + ".jpg"
-			if err = ioutil.WriteFile(fileName, resp.Body(), os.ModePerm); err != nil {
+			if err = os.WriteFile(fileName, resp.Body(), os.ModePerm); err != nil {
 				logrus.Errorf("存储图片失败:%s", err.Error())
 				return
 			}
@@ -257,7 +256,7 @@ func (o *LcDevice) Snapshot2(file string) error {
 		return errors.New("调用截图接口发生错误")
 	}
 	fileName = util.GetPath(4) + file
-	err = ioutil.WriteFile(fileName, resp.Body(), os.ModePerm)
+	err = os.WriteFile(fileName, resp.Body(), os.ModePerm)
 	if err != nil {
 		return err
 	}

+ 6 - 7
edge/ipole/handlefile.go

@@ -1,7 +1,6 @@
 package main
 
 import (
-	"io/ioutil"
 	"os"
 	"regexp"
 	"strconv"
@@ -52,7 +51,7 @@ func SaveFile(fname, content string, flag uint8) error {
 		SavePath = util.GetPath(2)
 	}
 	//存成临时文件
-	if err := ioutil.WriteFile(util.GetPath(4)+fname, []byte(content), os.ModePerm); err != nil {
+	if err := os.WriteFile(util.GetPath(4)+fname, []byte(content), os.ModePerm); err != nil {
 		return err
 	}
 	//备份原文件
@@ -74,12 +73,12 @@ func SaveFile(fname, content string, flag uint8) error {
 func ReadFileContent(topic string, o *protocol.Pack_SeqFileObject) {
 	switch topic {
 	case protocol.TP_GW_APP:
-		if buf, err := ioutil.ReadFile(util.GetPath(0) + "app.json"); err == nil {
+		if buf, err := os.ReadFile(util.GetPath(0) + "app.json"); err == nil {
 			o.Data.File = "app.json"
 			o.Data.Content = string(buf)
 		}
 	case protocol.TP_GW_SERIAL:
-		if buf, err := ioutil.ReadFile(util.GetPath(0) + "serial.json"); err == nil {
+		if buf, err := os.ReadFile(util.GetPath(0) + "serial.json"); err == nil {
 			o.Data.File = "serial.json"
 			o.Data.Content = string(buf)
 		}
@@ -104,7 +103,7 @@ func ReadMutilFileContent(topic string, id uint, o *protocol.Pack_MutilFileObjec
 			fname := strconv.Itoa(int(id)) + ".json"
 			AddFileObject(FileDir, fname, o)
 		} else {
-			rd, _ := ioutil.ReadDir(FileDir)
+			rd, _ := os.ReadDir(FileDir)
 			for _, fi := range rd {
 				if !fi.IsDir() {
 					ok, _ := regexp.MatchString(`[1-9].*json`, fi.Name())
@@ -115,7 +114,7 @@ func ReadMutilFileContent(topic string, id uint, o *protocol.Pack_MutilFileObjec
 			}
 		}
 	} else if topic == protocol.TP_GW_LOG { //日志
-		rd, _ := ioutil.ReadDir(FileDir)
+		rd, _ := os.ReadDir(FileDir)
 		for _, fi := range rd {
 			if !fi.IsDir() {
 				ok := strings.HasSuffix(fi.Name(), ".log")
@@ -132,7 +131,7 @@ func ReadMutilFileContent(topic string, id uint, o *protocol.Pack_MutilFileObjec
 }
 
 func AddFileObject(fpath, fname string, o *protocol.Pack_MutilFileObject) {
-	if buf, err := ioutil.ReadFile(fpath + fname); err == nil {
+	if buf, err := os.ReadFile(fpath + fname); err == nil {
 		var fo protocol.FileObject
 		fo.File = fname
 		fo.Content = string(buf)

+ 1 - 2
edge/ipole/mqtthandle.go

@@ -1,7 +1,6 @@
 package main
 
 import (
-	"io/ioutil"
 	"os"
 	"strings"
 
@@ -114,7 +113,7 @@ func HandleTpRLog(m mqtt.Message) {
 	var ret protocol.Pack_Ack
 	var err error
 	if err = obj.DeCode(m.PayloadString()); err == nil {
-		rd, _ := ioutil.ReadDir(util.GetPath(3))
+		rd, _ := os.ReadDir(util.GetPath(3))
 		for _, fi := range rd {
 			if ok := strings.HasSuffix(fi.Name(), ".log"); ok {
 				err = os.Remove(util.GetPath(3) + fi.Name())

+ 0 - 3
edge/its/main.go

@@ -1,9 +1,7 @@
 package main
 
 import (
-	"math/rand"
 	"runtime"
-	"time"
 
 	"github.com/sirupsen/logrus"
 
@@ -58,7 +56,6 @@ func main() {
 	GetMQTTMgr()
 	GetWebSvr().MQTTSubscribe()
 	GetITSDeviceMgr().LoadITSDevice()
-	rand.Seed(time.Now().UnixNano())
 
 	gopool = util.NewPool(10)
 	gopool.Add(GetMQTTMgr().MQTTMessageHandle, 1)

+ 3 - 3
edge/led_screen/clt_client/delete.go

@@ -2,7 +2,7 @@ package clt_client
 
 import (
 	"github.com/sirupsen/logrus"
-	"io/ioutil"
+	"io"
 	"lc/common/mqtt"
 	"net/http"
 )
@@ -23,7 +23,7 @@ func (c cltclient) DelPrograms(m mqtt.Message, baseurl string) {
 			return
 		}
 		defer resp.Body.Close()
-		ioutil.ReadAll(resp.Body)
+		io.ReadAll(resp.Body)
 	}
 }
 
@@ -40,5 +40,5 @@ func (c cltclient) CleanAll(baseurl string) {
 		return
 	}
 	defer resp.Body.Close()
-	ioutil.ReadAll(resp.Body)
+	io.ReadAll(resp.Body)
 }

+ 3 - 3
edge/led_screen/clt_client/get.go

@@ -2,7 +2,7 @@ package clt_client
 
 import (
 	"github.com/sirupsen/logrus"
-	"io/ioutil"
+	"io"
 	"net/http"
 )
 
@@ -15,7 +15,7 @@ func (c cltclient) SnapShot(url string) []byte {
 		return nil
 	}
 	defer resp.Body.Close()
-	body, err := ioutil.ReadAll(resp.Body)
+	body, err := io.ReadAll(resp.Body)
 	if err != nil {
 		logrus.Errorf("查询结果body读取错误:%v", err)
 		return nil
@@ -31,7 +31,7 @@ func (c cltclient) CommonGet(url string) ([]byte, error) {
 		return nil, err
 	}
 	defer resp.Body.Close()
-	all, err := ioutil.ReadAll(resp.Body)
+	all, err := io.ReadAll(resp.Body)
 	if err != nil {
 		return nil, err
 	}

+ 2 - 3
edge/led_screen/clt_client/post.go

@@ -5,7 +5,6 @@ import (
 	"errors"
 	"github.com/sirupsen/logrus"
 	"io"
-	"io/ioutil"
 	"lc/common/mqtt"
 	"mime/multipart"
 	"net/http"
@@ -37,7 +36,7 @@ DoReq:
 	n := 0
 	resp, err := c.HttpClient.Do(req)
 	defer resp.Body.Close()
-	ioutil.ReadAll(resp.Body)
+	io.ReadAll(resp.Body)
 	if err != nil && n < 3 {
 		logrus.Errorf("节目发布http错误:%v, 消息内容: %+v", err, pro)
 		n++
@@ -97,6 +96,6 @@ func (c cltclient) CommonPost(payload []byte, url string) error {
 		return err
 	}
 	defer resp.Body.Close()
-	ioutil.ReadAll(resp.Body)
+	io.ReadAll(resp.Body)
 	return nil
 }

+ 2 - 3
edge/led_screen/clt_client/put.go

@@ -5,7 +5,6 @@ import (
 	"errors"
 	"github.com/sirupsen/logrus"
 	"io"
-	"io/ioutil"
 	"lc/common/mqtt"
 	"net/http"
 )
@@ -27,7 +26,7 @@ func (c cltclient) SwitchProgram(m mqtt.Message, baseurl string) {
 		return
 	}
 	defer resp.Body.Close()
-	ioutil.ReadAll(resp.Body)
+	io.ReadAll(resp.Body)
 }
 
 // brightness
@@ -45,6 +44,6 @@ func (c cltclient) CommonPut(payload []byte, url string) error {
 		return err
 	}
 	defer resp.Body.Close()
-	ioutil.ReadAll(resp.Body)
+	io.ReadAll(resp.Body)
 	return nil
 }

+ 1 - 3
go.mod

@@ -1,11 +1,10 @@
 module lc
 
-go 1.17
+go 1.21
 
 require (
 	github.com/BurntSushi/toml v0.3.1
 	github.com/astaxie/beego v1.12.2
-	github.com/beevik/etree v1.1.0
 	github.com/clbanning/mxj v1.8.4
 	github.com/eclipse/paho.mqtt.golang v1.3.5
 	github.com/go-ini/ini v1.61.0
@@ -69,7 +68,6 @@ require (
 	github.com/smartystreets/goconvey v1.6.4 // indirect
 	github.com/tebeka/strftime v0.1.5 // indirect
 	github.com/valyala/fasttemplate v1.2.1 // indirect
-	golang.org/dl v0.0.0-20230404172053-c7dbe52702e1 // indirect
 	golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
 	golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect
 	golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 // indirect

+ 0 - 5
go.sum

@@ -17,8 +17,6 @@ github.com/astaxie/beego v1.12.2 h1:CajUexhSX5ONWDiSCpeQBNVfTzOtPb9e9d+3vuU5FuU=
 github.com/astaxie/beego v1.12.2/go.mod h1:TMcqhsbhN3UFpN+RCfysaxPAbrhox6QSS3NIAEp/uzE=
 github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ=
 github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542/go.mod h1:kSeGC/p1AbBiEp5kat81+DSQrZenVBZXklMLaELspWU=
-github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs=
-github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
 github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
 github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
@@ -65,7 +63,6 @@ github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
 github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
 github.com/go-ozzo/ozzo-validation/v4 v4.2.2 h1:5uhbQAuRK6taB9orHJXA5GtOCuQbsHktskg8aWciC68=
 github.com/go-ozzo/ozzo-validation/v4 v4.2.2/go.mod h1:2NKgrcHl3z6cJs+3Oo940FPRiTzuqKbvfrL2RxCj6Ew=
-github.com/go-redis/redis v6.14.2+incompatible h1:UE9pLhzmWf+xHNmZsoccjXosPicuiNaInPgym8nzfg0=
 github.com/go-redis/redis v6.14.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
 github.com/go-redis/redis/v7 v7.4.0 h1:7obg6wUoj05T0EpY0o8B59S9w5yeMWql7sw2kwNW1x4=
 github.com/go-redis/redis/v7 v7.4.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
@@ -251,8 +248,6 @@ github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52
 github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
 github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc=
 github.com/yuin/gopher-lua v0.0.0-20171031051903-609c9cd26973/go.mod h1:aEV29XrmTYFr3CiRxZeGHpkvbwq+prZduBqMaascyCU=
-golang.org/dl v0.0.0-20230404172053-c7dbe52702e1 h1:E391gyv//wdNS4eEoUdR4YNer/Zbfa7fg8Swe2cK6oc=
-golang.org/dl v0.0.0-20230404172053-c7dbe52702e1/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ=
 golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=