Skip to content

Commit

Permalink
releases 1.1.3
Browse files Browse the repository at this point in the history
releases 1.1.3
  • Loading branch information
wenjianzhang authored Aug 12, 2020
2 parents 055a68d + 8ebcd77 commit ed238f0
Show file tree
Hide file tree
Showing 46 changed files with 1,947 additions and 526 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ go-admin
middleware/demo.go
config/settings.dev.b.yml
temp/logs
config/settings.dev.yml.log
config/settings.b.dev.yml
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

FROM golang:alpine as builder

MAINTAINER xxx

ENV GOPROXY https://goproxy.cn/

WORKDIR /go/release
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk update && apk add tzdata

COPY ./go.mod ./go.mod
RUN go mod download
COPY . .
RUN pwd && ls

RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -a -installsuffix cgo -o go-admin .

FROM alpine

COPY --from=builder /go/release/go-admin /
COPY --from=builder /go/release/config/ /config/

COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

EXPOSE 8000

CMD ["/go-admin","server","-c", "/config/settings.yml"]

15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


[English](https://github.com/wenjianzhang/go-admin/blob/master/README.en.md) | 简体中文


##### 基于Gin + Vue + Element UI的前后端分离权限管理系统

Expand Down Expand Up @@ -167,7 +167,20 @@ vi ./config/setting.yml
```

#### 使用docker 编译启动

```shell
# 编译镜像
docker build -t go-admin .

# 启动容器,第一个go-admin是容器名字,第二个go-admin是镜像名称
docker run --name go-admin -p 8000:8000 -d go-admin
```



#### 文档生成

```bash
swag init

Expand Down
12 changes: 12 additions & 0 deletions apis/monitor/server.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package monitor

import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/mem"
"go-admin/tools"
"go-admin/tools/app"
"runtime"
)
Expand All @@ -16,6 +18,11 @@ const (
GB = 1024 * MB
)

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

osDic := make(map[string]interface{}, 0)
Expand All @@ -25,6 +32,8 @@ func ServerInfo(c *gin.Context) {
osDic["compiler"] = runtime.Compiler
osDic["version"] = runtime.Version()
osDic["numGoroutine"] = runtime.NumGoroutine()
osDic["ip"] = tools.GetLocaHonst()
osDic["projectDir"] = tools.GetCurrentPath()

dis, _ := disk.Usage("/")
diskTotalGB := int(dis.Total) / GB
Expand All @@ -45,6 +54,9 @@ func ServerInfo(c *gin.Context) {
memDic["usage"] = memUsedPercent

cpuDic := make(map[string]interface{}, 0)
cpuDic["cpuInfo"],_ = cpu.Info()
percent,_ := cpu.Percent(0,false)
cpuDic["Percent"] = fmt.Sprintf("%.2f",percent[0])
cpuDic["cpuNum"], _ = cpu.Counts(false)

app.Custum(c, gin.H{
Expand Down
66 changes: 66 additions & 0 deletions apis/public/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package public

import (
"encoding/base64"
"errors"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"go-admin/pkg/utils"
"go-admin/tools/app"
"io/ioutil"
"fmt"
)

// @Summary 上传图片
// @Description 获取JSON
// @Tags 公共接口
// @Accept multipart/form-data
// @Param type query string true "type" (1:单图,2:多图, 3:base64图片)
// @Param file formData file true "file"
// @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) {
tag,_ := c.GetPostForm("type")
urlPerfix := fmt.Sprintf("http://%s/",c.Request.Host)
if tag == ""{
app.Error(c,200,errors.New(""),"缺少标识")
return
} else {
switch tag {
case "1": // 单图
files,err := c.FormFile("file")
if err != nil {
app.Error(c,200,errors.New(""),"图片不能为空")
return
}
// 上传文件至指定目录
guid := uuid.New().String()

singleFile := "static/uploadfile/" + guid + utils.GetExt(files.Filename)
_ = c.SaveUploadedFile(files, singleFile)
app.OK(c, urlPerfix + singleFile, "上传成功")
return
case "2": // 多图
files := c.Request.MultipartForm.File["file"]
multipartFile := make([]string, len(files))
for _, f := range files {
guid := uuid.New().String()
multipartFileName := "static/uploadfile/" + guid + utils.GetExt(f.Filename)
_ = c.SaveUploadedFile(f, multipartFileName)
multipartFile = append(multipartFile, urlPerfix + multipartFileName)
}
app.OK(c, multipartFile, "上传成功")
return
case "3": // base64
files,_ := c.GetPostForm("file")
ddd, _ := base64.StdEncoding.DecodeString(files)
guid := uuid.New().String()
_ = ioutil.WriteFile("static/uploadfile/" + guid+ ".jpg", ddd, 0666)
app.OK(c, urlPerfix + "static/uploadfile/" + guid+ ".jpg", "上传成功")
}
}
}
114 changes: 114 additions & 0 deletions apis/sysjob/sysjob.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package sysjob

import (
"github.com/gin-gonic/gin"
"go-admin/jobs"
"go-admin/models"
"go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/app/msg"
"time"
)

func GetSysJobList(c *gin.Context) {
var data models.SysJob
var err error
var pageSize = 10
var pageIndex = 1

if size := c.Request.FormValue("pageSize"); size != "" {
pageSize = tools.StrToInt(err, size)
}
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex = tools.StrToInt(err, index)
}

data.JobId, _ = tools.StringToInt(c.Request.FormValue("jobId"))
data.JobName = c.Request.FormValue("jobName")
data.JobGroup = c.Request.FormValue("jobGroup")
data.CronExpression = c.Request.FormValue("cronExpression")
data.InvokeTarget = c.Request.FormValue("invokeTarget")
data.Status, _ = tools.StringToInt(c.Request.FormValue("status"))

data.DataScope = tools.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex)
tools.HasError(err, "", -1)

app.PageOK(c, result, count, pageIndex, pageSize, "")
}

func GetSysJob(c *gin.Context) {
var data models.SysJob
data.JobId, _ = tools.StringToInt(c.Param("jobId"))
result, err := data.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)

app.OK(c, result, "")
}

func InsertSysJob(c *gin.Context) {
var data models.SysJob
err := c.ShouldBindJSON(&data)
data.CreateBy = tools.GetUserIdStr(c)
tools.HasError(err, "", 500)
result, err := data.Create()
tools.HasError(err, "", -1)
app.OK(c, result, "")
}

func UpdateSysJob(c *gin.Context) {
var data models.SysJob
err := c.ShouldBindJSON(&data)
tools.HasError(err, "数据解析失败", -1)
data.UpdateBy = tools.GetUserIdStr(c)
result, err := data.Update(data.JobId)
tools.HasError(err, "", -1)

app.OK(c, result, "")
}

func DeleteSysJob(c *gin.Context) {
var data models.SysJob
data.UpdateBy = tools.GetUserIdStr(c)

IDS := tools.IdsStrToIdsIntGroup("jobId", c)
_, err := data.BatchDelete(IDS)
tools.HasError(err, msg.DeletedFail, 500)
app.OK(c, nil, msg.DeletedSuccess)
}

func RemoveJob(c *gin.Context) {
var data models.SysJob
data.JobId, _ = tools.StringToInt(c.Param("jobId"))
result, err := data.Get()
tools.HasError(err, "", 500)
cn := jobs.Remove(result.EntryId)

select {
case res := <-cn:
if res {
_, _ = data.RemoveEntryID(result.EntryId)
app.OK(c, nil, msg.DeletedSuccess)
}
case <-time.After(time.Second * 1):
app.OK(c, nil, msg.TimeOut)
}

}

func StartJob(c *gin.Context) {
var data models.SysJob
data.JobId, _ = tools.StringToInt(c.Param("jobId"))
result, err := data.Get()
tools.HasError(err, "", 500)
j := &jobs.ExecJob{}
j.InvokeTarget = result.InvokeTarget
j.CronExpression = result.CronExpression
j.JobId = result.JobId
j.Name = result.JobName
data.EntryId, err = jobs.AddJob(j)
tools.HasError(err, "", 500)
_, err = data.Update(data.JobId)
tools.HasError(err, "", 500)
app.OK(c, nil, msg.DeletedSuccess)
}
65 changes: 65 additions & 0 deletions apis/system/settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package system

import (
"errors"
"fmt"
"github.com/gin-gonic/gin"
"go-admin/models"
"go-admin/tools"
"go-admin/tools/app"
"strings"
)

// @Summary 查询系统信息
// @Description 获取JSON
// @Tags 系统信息
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/setting [get]
func GetSetting(c *gin.Context) {
var s models.SysSetting
r, e := s.Get()

if r.Logo != "" {
if !strings.HasPrefix(r.Logo, "http") {
r.Logo = fmt.Sprintf("http://%s/%s", c.Request.Host, r.Logo)
}
}

tools.HasError(e, "查询失败", 500)
app.OK(c, r, "查询成功")
}

// @Summary 更新或提交系统信息
// @Description 获取JSON
// @Tags 系统信息
// @Param data body models.SysUser true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/system/setting [post]
func CreateSetting(c *gin.Context) {
var s models.ResponseSystemConfig
if err := c.ShouldBind(&s); err != nil {
app.Error(c, 200, errors.New("缺少必要参数"), "")
return
}

var sModel models.SysSetting
sModel.Logo = s.Logo
sModel.Name = s.Name

a, e := sModel.Update()
if e != nil {
app.Error(c, 200, e, "")
return
}

if a.Logo != "" {
if !strings.HasPrefix(a.Logo, "http") {
a.Logo = fmt.Sprintf("http://%s/%s", c.Request.Host, a.Logo)
}
}

app.OK(c, a, "提交成功")

}
Loading

0 comments on commit ed238f0

Please sign in to comment.