提交 2abf4013 编写于 作者: Mr.奇淼('s avatar Mr.奇淼(

gin-vue-admin 2.0代码重构

上级 91659efa
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)
}
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
}
......
package tools
package utils
import (
"bytes"
......
package tools
package utils
import "os"
......
// 空值校验工具 仅用于检验空字符串 其余类型请勿使用
package tools
package utils
import (
"errors"
......
package tools
package utils
import (
"crypto/md5"
......
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
}
\ No newline at end of file
}
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) {
......
package tools
package utils
import (
"archive/zip"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册