Ver código fonte

gin-vue-admin 2.0代码重构

QM303176530 5 anos atrás
pai
commit
2abf401392

+ 8 - 7
server/api/v1/sys_captcha.go

@@ -1,8 +1,9 @@
-package api
+package v1
 
 import (
-	"gin-vue-admin/config"
-	"gin-vue-admin/controller/servers"
+	"gin-vue-admin/global"
+	"gin-vue-admin/global/response"
+	"gin-vue-admin/utils"
 	"github.com/dchest/captcha"
 	"github.com/gin-gonic/gin"
 )
@@ -16,11 +17,11 @@ import (
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
 // @Router /base/captcha [post]
 func Captcha(c *gin.Context) {
-	captchaId := captcha.NewLen(config.GinVueAdminconfig.Captcha.KeyLong)
-	servers.ReportFormat(c, true, "验证码获取成功", gin.H{
+	captchaId := captcha.NewLen(global.GVA_CONFIG.Captcha.KeyLong)
+	response.Result(response.SUCCESS, gin.H{
 		"captchaId": captchaId,
 		"picPath":   "/base/captcha/" + captchaId + ".png",
-	})
+	}, "验证码获取成功", c)
 }
 
 // @Tags base
@@ -31,5 +32,5 @@ func Captcha(c *gin.Context) {
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
 // @Router /base/captcha/:captchaId [get]
 func CaptchaImg(c *gin.Context) {
-	servers.GinCapthcaServeHTTP(c.Writer, c.Request)
+	utils.GinCaptchaServeHTTP(c.Writer, c.Request)
 }

+ 6 - 6
QMPlusServer/controller/servers/captcha.go → server/utils/captcha.go

@@ -1,9 +1,9 @@
-package servers
+package utils
 
 import (
 	"bytes"
 	"fmt"
-	"gin-vue-admin/config"
+	"gin-vue-admin/global"
 	"github.com/dchest/captcha"
 	"net/http"
 	"path"
@@ -12,7 +12,7 @@ import (
 )
 
 // 这里需要自行实现captcha 的gin模式
-func GinCapthcaServeHTTP(w http.ResponseWriter, r *http.Request) {
+func GinCaptchaServeHTTP(w http.ResponseWriter, r *http.Request) {
 	dir, file := path.Split(r.URL.Path)
 	ext := path.Ext(file)
 	id := file[:len(file)-len(ext)]
@@ -26,7 +26,7 @@ func GinCapthcaServeHTTP(w http.ResponseWriter, r *http.Request) {
 	}
 	lang := strings.ToLower(r.FormValue("lang"))
 	download := path.Base(dir) == "download"
-	if Serve(w, r, id, ext, lang, download, config.GinVueAdminconfig.Captcha.ImgWidth, config.GinVueAdminconfig.Captcha.ImgHeight) == captcha.ErrNotFound {
+	if Serve(w, r, id, ext, lang, download, global.GVA_CONFIG.Captcha.ImgWidth, global.GVA_CONFIG.Captcha.ImgHeight) == captcha.ErrNotFound {
 		http.NotFound(w, r)
 	}
 }
@@ -39,10 +39,10 @@ func Serve(w http.ResponseWriter, r *http.Request, id, ext, lang string, downloa
 	switch ext {
 	case ".png":
 		w.Header().Set("Content-Type", "image/png")
-		captcha.WriteImage(&content, id, width, height)
+		_ = captcha.WriteImage(&content, id, width, height)
 	case ".wav":
 		w.Header().Set("Content-Type", "audio/x-wav")
-		captcha.WriteAudio(&content, id, lang)
+		_ = captcha.WriteAudio(&content, id, lang)
 	default:
 		return captcha.ErrNotFound
 	}

+ 1 - 1
server/utils/des.go

@@ -1,4 +1,4 @@
-package tools
+package utils
 
 import (
 	"bytes"

+ 1 - 1
server/utils/directory.go

@@ -1,4 +1,4 @@
-package tools
+package utils
 
 import "os"
 

+ 1 - 1
server/utils/hasGap.go

@@ -1,6 +1,6 @@
 // 空值校验工具 仅用于检验空字符串 其余类型请勿使用
 
-package tools
+package utils
 
 import (
 	"errors"

+ 1 - 1
server/utils/md5.go

@@ -1,4 +1,4 @@
-package tools
+package utils
 
 import (
 	"crypto/md5"

+ 3 - 3
QMPlusServer/tools/struct_to_map.go → server/utils/struct_to_map.go

@@ -1,9 +1,9 @@
-package tools
+package utils
 
 import "reflect"
 
 // 利用反射将结构体转化为map
-func StructToMap(obj interface{}) map[string]interface{}{
+func StructToMap(obj interface{}) map[string]interface{} {
 	obj1 := reflect.TypeOf(obj)
 	obj2 := reflect.ValueOf(obj)
 
@@ -12,4 +12,4 @@ func StructToMap(obj interface{}) map[string]interface{}{
 		data[obj1.Field(i).Name] = obj2.Field(i).Interface()
 	}
 	return data
-}
+}

+ 4 - 4
server/utils/upload.go

@@ -1,17 +1,17 @@
-package servers
+package utils
 
 import (
 	"context"
 	"fmt"
-	"gin-vue-admin/config"
+	"gin-vue-admin/global"
 	"github.com/qiniu/api.v7/auth/qbox"
 	"github.com/qiniu/api.v7/storage"
 	"mime/multipart"
 	"time"
 )
 
-var accessKey string = config.GinVueAdminconfig.Qiniu.AccessKey // 你在七牛云的accessKey  这里是我个人测试号的key 仅供测试使用 恳请大家不要乱传东西
-var secretKey string = config.GinVueAdminconfig.Qiniu.SecretKey // 你在七牛云的secretKey  这里是我个人测试号的key 仅供测试使用 恳请大家不要乱传东西
+var accessKey string = global.GVA_CONFIG.Qiniu.AccessKey // 你在七牛云的accessKey  这里是我个人测试号的key 仅供测试使用 恳请大家不要乱传东西
+var secretKey string = global.GVA_CONFIG.Qiniu.SecretKey // 你在七牛云的secretKey  这里是我个人测试号的key 仅供测试使用 恳请大家不要乱传东西
 
 // 接收两个参数 一个文件流 一个 bucket 你的七牛云标准空间的名字
 func Upload(file *multipart.FileHeader, bucket string, urlPath string) (err error, path string, key string) {

+ 1 - 1
server/utils/zipfiles.go

@@ -1,4 +1,4 @@
-package tools
+package utils
 
 import (
 	"archive/zip"