Skip to content

Commit

Permalink
publish🚀 v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wenjianzhang authored Mar 17, 2021
2 parents 31ec388 + 9c73558 commit 0be7735
Show file tree
Hide file tree
Showing 49 changed files with 637 additions and 392 deletions.
10 changes: 7 additions & 3 deletions app/admin/apis/monitor/server.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package monitor

import (
"go-admin/common/apis"
"runtime"

"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/mem"
Expand All @@ -18,12 +18,16 @@ const (
GB = 1024 * MB
)

type Monitor struct {
apis.Api
}

// @Summary 系统信息
// @Description 获取JSON
// @Tags 系统信息
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/settings/serverInfo [get]
func ServerInfo(c *gin.Context) {
func (e *Monitor) ServerInfo(c *gin.Context) {

osDic := make(map[string]interface{}, 0)
osDic["goOs"] = runtime.GOOS
Expand Down Expand Up @@ -59,7 +63,7 @@ func ServerInfo(c *gin.Context) {
cpuDic["Percent"] = pkg.Round(percent[0], 2)
cpuDic["cpuNum"], _ = cpu.Counts(false)

app.Custum(c, gin.H{
e.Custom(c, gin.H{
"code": 200,
"os": osDic,
"mem": memDic,
Expand Down
41 changes: 23 additions & 18 deletions app/admin/apis/public/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"github.com/go-admin-team/go-admin-core/sdk/pkg/utils"
"github.com/google/uuid"

"go-admin/common/apis"
"go-admin/common/file_store"
)

Expand All @@ -24,6 +24,10 @@ type FileResponse struct {
Type string `json:"type"`
}

type File struct {
apis.Api
}

// @Summary 上传图片
// @Description 获取JSON
// @Tags 公共接口
Expand All @@ -33,35 +37,36 @@ type FileResponse struct {
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/public/uploadFile [post]
func UploadFile(c *gin.Context) {
func (e *File) UploadFile(c *gin.Context) {
tag, _ := c.GetPostForm("type")
urlPerfix := fmt.Sprintf("http://%s/", c.Request.Host)
var fileResponse FileResponse
if tag == "" {
app.Error(c, 200, errors.New(""), "缺少标识")
e.Error(c, 500, nil, "缺少标识")
//app.Error(c, 200, errors.New(""), "缺少标识")
return
} else {
switch tag {
case "1": // 单图
var done bool
fileResponse, done = singleFile(c, fileResponse, urlPerfix)
fileResponse, done = e.singleFile(c, fileResponse, urlPerfix)
if done {
return
}
app.OK(c, fileResponse, "上传成功")
e.OK(c, fileResponse, "上传成功")
return
case "2": // 多图
multipartFile := multipleFile(c, urlPerfix)
app.OK(c, multipartFile, "上传成功")
multipartFile := e.multipleFile(c, urlPerfix)
e.OK(c, multipartFile, "上传成功")
return
case "3": // base64
fileResponse = baseImg(c, fileResponse, urlPerfix)
app.OK(c, fileResponse, "上传成功")
fileResponse = e.baseImg(c, fileResponse, urlPerfix)
e.OK(c, fileResponse, "上传成功")
}
}
}

func baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix string) FileResponse {
func (e *File) baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix string) FileResponse {
files, _ := c.GetPostForm("file")
file2list := strings.Split(files, ",")
ddd, _ := base64.StdEncoding.DecodeString(file2list[1])
Expand All @@ -80,7 +85,7 @@ func baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix string) FileRe
source, _ := c.GetPostForm("source")
err := thirdUpload(source, fileName, base64File)
if err != nil {
app.Error(c, 200, errors.New(""), "上传第三方失败")
e.Error(c, 200, errors.New(""), "上传第三方失败")
return fileResponse
}
if source != "1" {
Expand All @@ -90,20 +95,20 @@ func baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix string) FileRe
return fileResponse
}

func multipleFile(c *gin.Context, urlPerfix string) []FileResponse {
func (e *File) multipleFile(c *gin.Context, urlPerfix string) []FileResponse {
files := c.Request.MultipartForm.File["file"]
source, _ := c.GetPostForm("source")
var multipartFile []FileResponse
for _, f := range files {
guid := uuid.New().String()
fileName := guid + utils.GetExt(f.Filename)
multipartFileName := "static/uploadfile/" + fileName
e := c.SaveUploadedFile(f, multipartFileName)
err1 := c.SaveUploadedFile(f, multipartFileName)
fileType, _ := utils.GetType(multipartFileName)
if e == nil {
if err1 == nil {
err := thirdUpload(source, fileName, multipartFileName)
if err != nil {
app.Error(c, 200, errors.New(""), "上传第三方失败")
e.Error(c, 500, errors.New(""), "上传第三方失败")
} else {
fileResponse := FileResponse{
Size: pkg.GetFileSize(multipartFileName),
Expand All @@ -123,11 +128,11 @@ func multipleFile(c *gin.Context, urlPerfix string) []FileResponse {
return multipartFile
}

func singleFile(c *gin.Context, fileResponse FileResponse, urlPerfix string) (FileResponse, bool) {
func (e *File) singleFile(c *gin.Context, fileResponse FileResponse, urlPerfix string) (FileResponse, bool) {
files, err := c.FormFile("file")

if err != nil {
app.Error(c, 200, errors.New(""), "图片不能为空")
e.Error(c, 200, errors.New(""), "图片不能为空")
return FileResponse{}, true
}
// 上传文件至指定目录
Expand All @@ -147,7 +152,7 @@ func singleFile(c *gin.Context, fileResponse FileResponse, urlPerfix string) (Fi
source, _ := c.GetPostForm("source")
err = thirdUpload(source, fileName, singleFile)
if err != nil {
app.Error(c, 200, errors.New(""), "上传第三方失败")
e.Error(c, 200, errors.New(""), "上传第三方失败")
return FileResponse{}, true
}
fileResponse.Path = "https://youshikeji.oss-cn-shanghai.aliyuncs.com/img/" + fileName
Expand Down
6 changes: 2 additions & 4 deletions app/admin/apis/sys_job/sys_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"

"go-admin/app/admin/service"
"go-admin/common/apis"
"go-admin/common/dto"
Expand Down Expand Up @@ -41,7 +39,7 @@ func (e *SysJob) RemoveJobForService(c *gin.Context) {
e.Error(c, http.StatusInternalServerError, err, "")
return
}
app.OK(c, nil, s.Msg)
e.OK(c, nil, s.Msg)
}

// StartJobForService 启动job service实现
Expand Down Expand Up @@ -69,5 +67,5 @@ func (e *SysJob) StartJobForService(c *gin.Context) {
e.Error(c, http.StatusInternalServerError, err, "")
return
}
app.OK(c, nil, s.Msg)
e.OK(c, nil, s.Msg)
}
18 changes: 13 additions & 5 deletions app/admin/apis/system/captcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ package system

import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/captcha"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/common/apis"
)

func GenerateCaptchaHandler(c *gin.Context) {
type System struct {
apis.Api
}

func (e *System) GenerateCaptchaHandler(c *gin.Context) {
log := e.GetLogger(c)
id, b64s, err := captcha.DriverDigitFunc()
pkg.HasError(err, "验证码获取失败", 500)
app.Custum(c, gin.H{
if err != nil {
log.Errorf("DriverDigitFunc error, %s", err.Error())
e.Error(c, 500, err, "验证码获取失败")
return
}
e.Custom(c, gin.H{
"code": 200,
"data": b64s,
"id": id,
Expand Down
Loading

0 comments on commit 0be7735

Please sign in to comment.