From 772bdabcb2ea4d5d217f5a28e57a1b369bbc6136 Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Mon, 7 Sep 2020 13:56:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8=E5=87=BD?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E6=95=B4=E6=B4=81=E7=BB=93=E6=9E=84=E7=9B=AE?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/main.go | 3 -- server/utils/array_to_string.go | 10 ---- server/utils/des.go | 40 -------------- .../utils/{struct_to_map.go => fmt_plus.go} | 11 +++- server/utils/upload_avatar_local.go | 54 ------------------- 5 files changed, 10 insertions(+), 108 deletions(-) delete mode 100644 server/utils/array_to_string.go delete mode 100644 server/utils/des.go rename server/utils/{struct_to_map.go => fmt_plus.go} (61%) delete mode 100644 server/utils/upload_avatar_local.go diff --git a/server/main.go b/server/main.go index 9bbb166b..a8e566e2 100644 --- a/server/main.go +++ b/server/main.go @@ -4,10 +4,7 @@ import ( "gin-vue-admin/core" "gin-vue-admin/global" "gin-vue-admin/gva/init_data" - - //"gin-vue-admin/gva/init_data" "gin-vue-admin/initialize" - //"runtime" ) // @title Swagger Example API diff --git a/server/utils/array_to_string.go b/server/utils/array_to_string.go deleted file mode 100644 index b99012f1..00000000 --- a/server/utils/array_to_string.go +++ /dev/null @@ -1,10 +0,0 @@ -package utils - -import ( - "fmt" - "strings" -) - -func ArrayToString(array []interface{}) string { - return strings.Replace(strings.Trim(fmt.Sprint(array), "[]"), " ", ",", -1) -} diff --git a/server/utils/des.go b/server/utils/des.go deleted file mode 100644 index ecdbe78f..00000000 --- a/server/utils/des.go +++ /dev/null @@ -1,40 +0,0 @@ -package utils - -import ( - "bytes" - "crypto/cipher" - "crypto/des" -) - -func padding(src []byte, blocksize int) []byte { - n := len(src) - padnum := blocksize - n%blocksize - pad := bytes.Repeat([]byte{byte(padnum)}, padnum) - dst := append(src, pad...) - return dst -} - -func unpadding(src []byte) []byte { - n := len(src) - unpadnum := int(src[n-1]) - dst := src[:n-unpadnum] - return dst -} - -func EncryptDES(src []byte) []byte { - key := []byte("qimiao66") - block, _ := des.NewCipher(key) - src = padding(src, block.BlockSize()) - blockmode := cipher.NewCBCEncrypter(block, key) - blockmode.CryptBlocks(src, src) - return src -} - -func DecryptDES(src []byte) []byte { - key := []byte("qimiao66") - block, _ := des.NewCipher(key) - blockmode := cipher.NewCBCDecrypter(block, key) - blockmode.CryptBlocks(src, src) - src = unpadding(src) - return src -} diff --git a/server/utils/struct_to_map.go b/server/utils/fmt_plus.go similarity index 61% rename from server/utils/struct_to_map.go rename to server/utils/fmt_plus.go index 2cc309da..9fca8882 100644 --- a/server/utils/struct_to_map.go +++ b/server/utils/fmt_plus.go @@ -1,6 +1,10 @@ package utils -import "reflect" +import ( + "fmt" + "reflect" + "strings" +) // 利用反射将结构体转化为map func StructToMap(obj interface{}) map[string]interface{} { @@ -13,3 +17,8 @@ func StructToMap(obj interface{}) map[string]interface{} { } return data } + +//将数组格式化为字符串 +func ArrayToString(array []interface{}) string { + return strings.Replace(strings.Trim(fmt.Sprint(array), "[]"), " ", ",", -1) +} diff --git a/server/utils/upload_avatar_local.go b/server/utils/upload_avatar_local.go deleted file mode 100644 index b8081877..00000000 --- a/server/utils/upload_avatar_local.go +++ /dev/null @@ -1,54 +0,0 @@ -package utils - -import ( - "gin-vue-admin/global" - "go.uber.org/zap" - "io" - "mime/multipart" - "os" - "path" - "strings" - "time" -) - -func UploadAvatarLocal(file *multipart.FileHeader) (err error, localPath string, key string) { - // 读取文件后缀 - ext := path.Ext(file.Filename) - // 读取文件名并加密 - fileName := strings.TrimSuffix(file.Filename, ext) - fileName = MD5V([]byte(fileName)) - // 拼接新文件名 - lastName := fileName + "_" + time.Now().Format("20060102150405") + ext - // 读取全局变量的定义路径 - savePath := global.GVA_CONFIG.LocalUpload.AvatarPath - // 尝试创建此路径 - err = os.MkdirAll(savePath, os.ModePerm) - if err != nil{ - global.GVA_LOG.Error("upload local file fail:", zap.Any("err", err)) - return err, "", "" - } - // 拼接路径和文件名 - dst := savePath + "/" + lastName - // 下面为上传逻辑 - // 打开文件 defer 关闭 - src, err := file.Open() - if err != nil { - global.GVA_LOG.Error("upload local file fail:", zap.Any("err", err)) - return err, "", "" - } - defer src.Close() - // 创建文件 defer 关闭 - out, err := os.Create(dst) - if err != nil { - global.GVA_LOG.Error("upload local file fail:", zap.Any("err", err)) - return err, "", "" - } - defer out.Close() - // 传输(拷贝)文件 - _, err = io.Copy(out, src) - if err != nil { - global.GVA_LOG.Error("upload local file fail:", zap.Any("err", err)) - return err, "", "" - } - return nil, dst, lastName -}