-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
releases 1.1.3
- Loading branch information
Showing
46 changed files
with
1,947 additions
and
526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", "上传成功") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "提交成功") | ||
|
||
} |
Oops, something went wrong.