🎨 更新环境配置,添加 Dockerfile,优化代码结构
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
FROM golang:alpine as builder
|
||||
|
||||
WORKDIR /go/src/git.echol.cn/loser/Go-Web-Template/server
|
||||
WORKDIR /go/src/git.echol.cn/loser/Go-Web-Template/server/server
|
||||
COPY . .
|
||||
|
||||
RUN go env -w GO111MODULE=on \
|
||||
@@ -18,14 +18,14 @@ ENV TZ=Asia/Shanghai
|
||||
RUN apk update && apk add --no-cache tzdata openntpd \
|
||||
&& ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
WORKDIR /go/src/git.echol.cn/loser/Go-Web-Template/server
|
||||
WORKDIR /go/src/git.echol.cn/loser/Go-Web-Template/server/server
|
||||
|
||||
COPY --from=0 /go/src/git.echol.cn/loser/Go-Web-Template/server/server ./
|
||||
COPY --from=0 /go/src/git.echol.cn/loser/Go-Web-Template/server/resource ./resource/
|
||||
COPY --from=0 /go/src/git.echol.cn/loser/Go-Web-Template/server/config.docker.yaml ./
|
||||
COPY --from=0 /go/src/git.echol.cn/loser/Go-Web-Template/server/server/server ./server
|
||||
COPY --from=0 /go/src/git.echol.cn/loser/Go-Web-Template/server/server/resource ./resource/
|
||||
COPY --from=0 /go/src/git.echol.cn/loser/Go-Web-Template/server/server/config.docker.yaml ./
|
||||
|
||||
# 挂载目录:如果使用了sqlite数据库,容器命令示例:docker run -d -v /宿主机路径/gva.db:/go/src/git.echol.cn/loser/Go-Web-Template/server/gva.db -p 8888:8888 --name gva-server-v1 gva-server:1.0
|
||||
# VOLUME ["/go/src/git.echol.cn/loser/Go-Web-Template/server"]
|
||||
# 挂载目录:如果使用了sqlite数据库,容器命令示例:docker run -d -v /宿主机路径/gva.db:/go/src/git.echol.cn/loser/Go-Web-Template/servergva.db -p 8888:8888 --name gva-server-v1 gva-server:1.0
|
||||
# VOLUME ["/go/src/git.echol.cn/loser/Go-Web-Template/server/server"]
|
||||
|
||||
EXPOSE 8888
|
||||
ENTRYPOINT ./server -c config.docker.yaml
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
│ └── response
|
||||
├── packfile
|
||||
├── resource
|
||||
│ ├── excel
|
||||
│ ├── page
|
||||
│ └── template
|
||||
├── router
|
||||
@@ -41,6 +42,7 @@
|
||||
| `--response` | 出参结构体 | 返回给前端的数据结构体 |
|
||||
| `packfile` | 静态文件打包 | 静态文件打包 |
|
||||
| `resource` | 静态资源文件夹 | 负责存放静态文件 |
|
||||
| `--excel` | excel导入导出默认路径 | excel导入导出默认路径 |
|
||||
| `--page` | 页面静态资源目录 | 历史页面资源输出目录 |
|
||||
| `--template` | 模板 | 模板文件夹,存放的是代码生成器的模板 |
|
||||
| `router` | 路由层 | 路由层 |
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
commonReq "git.echol.cn/loser/Go-Web-Template/server/model/common/request"
|
||||
"git.echol.cn/loser/Go-Web-Template/server/model/common/response"
|
||||
commonRes "git.echol.cn/loser/Go-Web-Template/server/model/common/response"
|
||||
"git.echol.cn/loser/Go-Web-Template/server/utils"
|
||||
"git.echol.cn/loser/Go-Web-Template/server/utils/upload"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"strconv"
|
||||
@@ -32,7 +34,13 @@ func (b *FileUploadAndDownloadApi) UploadFile(c *gin.Context) {
|
||||
response.FailWithMessage("接收文件失败", c)
|
||||
return
|
||||
}
|
||||
file, err = fileUploadAndDownloadService.UploadFile(header, noSave, classId) // 文件上传后拿到文件路径
|
||||
// 从系统 JWT 中获取管理员 ID
|
||||
var adminID uint
|
||||
if claims := utils.GetUserInfo(c); claims != nil {
|
||||
adminID = claims.BaseClaims.ID
|
||||
}
|
||||
uploadCtx := upload.UploadContext{Source: upload.SourceAdmin, UserID: adminID}
|
||||
file, err = fileUploadAndDownloadService.UploadFile(header, noSave, classId, uploadCtx)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("上传文件失败!", zap.Error(err))
|
||||
response.FailWithMessage("上传文件失败", c)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
type Local struct {
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"` // 本地文件访问路径
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"` // 本地文件访问路径(相对路径)
|
||||
StorePath string `mapstructure:"store-path" json:"store-path" yaml:"store-path"` // 本地文件存储路径
|
||||
BaseURL string `mapstructure:"base-url" json:"base-url" yaml:"base-url"` // 文件访问域名前缀,如 https://api.wanjia.ai
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@ package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.echol.cn/loser/Go-Web-Template/server/core/internal"
|
||||
"git.echol.cn/loser/Go-Web-Template/server/global"
|
||||
"git.echol.cn/loser/Go-Web-Template/server/utils"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Zap 获取 zap.Logger
|
||||
|
||||
@@ -5847,6 +5847,14 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"config.Excel": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"dir": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"config.HuaWeiObs": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -6373,6 +6381,9 @@ const docTemplate = `{
|
||||
"email": {
|
||||
"$ref": "#/definitions/config.Email"
|
||||
},
|
||||
"excel": {
|
||||
"$ref": "#/definitions/config.Excel"
|
||||
},
|
||||
"hua-wei-obs": {
|
||||
"$ref": "#/definitions/config.HuaWeiObs"
|
||||
},
|
||||
|
||||
@@ -5839,6 +5839,14 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"config.Excel": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"dir": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"config.HuaWeiObs": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -6365,6 +6373,9 @@
|
||||
"email": {
|
||||
"$ref": "#/definitions/config.Email"
|
||||
},
|
||||
"excel": {
|
||||
"$ref": "#/definitions/config.Excel"
|
||||
},
|
||||
"hua-wei-obs": {
|
||||
"$ref": "#/definitions/config.HuaWeiObs"
|
||||
},
|
||||
@@ -7962,4 +7973,4 @@
|
||||
"name": "SysUser"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -216,6 +216,11 @@ definitions:
|
||||
description: 收件人:多个以英文逗号分隔 例:a@qq.com b@qq.com 正式开发中请把此项目作为参数使用
|
||||
type: string
|
||||
type: object
|
||||
config.Excel:
|
||||
properties:
|
||||
dir:
|
||||
type: string
|
||||
type: object
|
||||
config.HuaWeiObs:
|
||||
properties:
|
||||
access-key:
|
||||
@@ -592,6 +597,8 @@ definitions:
|
||||
type: array
|
||||
email:
|
||||
$ref: '#/definitions/config.Email'
|
||||
excel:
|
||||
$ref: '#/definitions/config.Excel'
|
||||
hua-wei-obs:
|
||||
$ref: '#/definitions/config.HuaWeiObs'
|
||||
jwt:
|
||||
|
||||
@@ -2,10 +2,11 @@ package global
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mark3labs/mcp-go/server"
|
||||
|
||||
"sync"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mark3labs/mcp-go/server"
|
||||
"github.com/qiniu/qmgo"
|
||||
|
||||
"git.echol.cn/loser/Go-Web-Template/server/utils/timer"
|
||||
|
||||
@@ -10,5 +10,6 @@ func bizModel() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.echol.cn/loser/Go-Web-Template/server/config"
|
||||
"git.echol.cn/loser/Go-Web-Template/server/global"
|
||||
"git.echol.cn/loser/Go-Web-Template/server/initialize/internal"
|
||||
@@ -38,6 +40,8 @@ func initPgSqlDatabase(p config.Pgsql) *gorm.DB {
|
||||
sqlDB, _ := db.DB()
|
||||
sqlDB.SetMaxIdleConns(p.MaxIdleConns)
|
||||
sqlDB.SetMaxOpenConns(p.MaxOpenConns)
|
||||
sqlDB.SetConnMaxLifetime(30 * time.Minute)
|
||||
sqlDB.SetConnMaxIdleTime(10 * time.Minute)
|
||||
return db
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,10 +51,11 @@ func Routers() *gin.Engine {
|
||||
// Router.Static("/assets", "./dist/assets") // dist里面的静态资源
|
||||
// Router.StaticFile("/", "./dist/index.html") // 前端网页入口页面
|
||||
|
||||
// 跨域,如需跨域可以打开下面的注释
|
||||
Router.Use(middleware.Cors()) // 直接放行全部跨域请求(必须在 StaticFS 之前注册,否则静态文件不带 CORS 头)
|
||||
// Router.Use(middleware.CorsByRules()) // 按照配置的规则放行跨域请求
|
||||
Router.StaticFS(global.GVA_CONFIG.Local.StorePath, justFilesFilesystem{http.Dir(global.GVA_CONFIG.Local.StorePath)})
|
||||
// Router.Use(middleware.LoadTls()) // 如果需要使用https 请打开此中间件 然后前往 core/server.go 将启动模式 更变为 Router.RunTLS("端口","你的cre/pem文件","你的key文件")
|
||||
// 跨域,如需跨域可以打开下面的注释
|
||||
Router.Use(middleware.Cors()) // 直接放行全部跨域请求
|
||||
// Router.Use(middleware.CorsByRules()) // 按照配置的规则放行跨域请求
|
||||
// global.GVA_LOG.Info("use middleware cors")
|
||||
docs.SwaggerInfo.BasePath = global.GVA_CONFIG.System.RouterPrefix
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 占位方法,保证文件可以正确加载,避免go空变量检测报错,请勿删除。
|
||||
func holder(routers ...*gin.RouterGroup) {
|
||||
_ = routers
|
||||
_ = router.RouterGroupApp
|
||||
|
||||
@@ -2,6 +2,7 @@ package initialize
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.echol.cn/loser/Go-Web-Template/server/task"
|
||||
|
||||
"github.com/robfig/cron/v3"
|
||||
|
||||
@@ -38,7 +38,7 @@ func (a *ApiCreator) New() mcp.Tool {
|
||||
mcp.WithDescription(`创建后端API记录,用于AI编辑器自动添加API接口时自动创建对应的API权限记录。
|
||||
|
||||
**重要限制:**
|
||||
- 当使用模块自动生成功能且 needCreatedModules=true 时,模块创建会自动生成 API 权限,不应调用此工具
|
||||
- 当使用gva_auto_generate工具且needCreatedModules=true时,模块创建会自动生成API权限,不应调用此工具
|
||||
- 仅在以下情况使用:1) 单独创建API(不涉及模块创建);2) AI编辑器自动添加API;3) router下的文件产生路径变化时`),
|
||||
mcp.WithString("path",
|
||||
mcp.Required(),
|
||||
|
||||
@@ -57,7 +57,7 @@ func (m *MenuCreator) New() mcp.Tool {
|
||||
mcp.WithDescription(`创建前端菜单记录,用于AI编辑器自动添加前端页面时自动创建对应的菜单项。
|
||||
|
||||
**重要限制:**
|
||||
- 当使用模块自动生成功能且 needCreatedModules=true 时,模块创建会自动生成菜单项,不应调用此工具
|
||||
- 当使用gva_auto_generate工具且needCreatedModules=true时,模块创建会自动生成菜单项,不应调用此工具
|
||||
- 仅在以下情况使用:1) 单独创建菜单(不涉及模块创建);2) AI编辑器自动添加前端页面时`),
|
||||
mcp.WithNumber("parentId",
|
||||
mcp.Description("父菜单ID,0表示根菜单"),
|
||||
|
||||
@@ -103,6 +103,7 @@ func OperationRecord() gin.HandlerFunc {
|
||||
strings.Contains(c.Writer.Header().Get("Cache-Control"), "must-revalidate, post-check=0, pre-check=0") ||
|
||||
strings.Contains(c.Writer.Header().Get("Content-Type"), "application/force-download") ||
|
||||
strings.Contains(c.Writer.Header().Get("Content-Type"), "application/octet-stream") ||
|
||||
strings.Contains(c.Writer.Header().Get("Content-Type"), "application/vnd.ms-excel") ||
|
||||
strings.Contains(c.Writer.Header().Get("Content-Type"), "application/download") ||
|
||||
strings.Contains(c.Writer.Header().Get("Content-Disposition"), "attachment") ||
|
||||
strings.Contains(c.Writer.Header().Get("Content-Transfer-Encoding"), "binary") {
|
||||
|
||||
@@ -93,9 +93,9 @@ func (e *FileUploadAndDownloadService) GetFileRecordInfoList(info commonReq.ExaA
|
||||
//@param: header *multipart.FileHeader, noSave string
|
||||
//@return: file model.ExaFileUploadAndDownload, err error
|
||||
|
||||
func (e *FileUploadAndDownloadService) UploadFile(header *multipart.FileHeader, noSave string, classId int) (file common.ExaFileUploadAndDownload, err error) {
|
||||
func (e *FileUploadAndDownloadService) UploadFile(header *multipart.FileHeader, noSave string, classId int, uploadCtx upload.UploadContext) (file common.ExaFileUploadAndDownload, err error) {
|
||||
oss := upload.NewOss()
|
||||
filePath, key, uploadErr := oss.UploadFile(header)
|
||||
filePath, key, uploadErr := oss.UploadFile(header, uploadCtx)
|
||||
if uploadErr != nil {
|
||||
return file, uploadErr
|
||||
}
|
||||
|
||||
@@ -9,28 +9,24 @@ import (
|
||||
type SysParamsService struct{}
|
||||
|
||||
// CreateSysParams 创建参数记录
|
||||
// Author [Mr.奇淼](https://github.com/pixelmaxQm)
|
||||
func (sysParamsService *SysParamsService) CreateSysParams(sysParams *system.SysParams) (err error) {
|
||||
err = global.GVA_DB.Create(sysParams).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteSysParams 删除参数记录
|
||||
// Author [Mr.奇淼](https://github.com/pixelmaxQm)
|
||||
func (sysParamsService *SysParamsService) DeleteSysParams(ID string) (err error) {
|
||||
err = global.GVA_DB.Delete(&system.SysParams{}, "id = ?", ID).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteSysParamsByIds 批量删除参数记录
|
||||
// Author [Mr.奇淼](https://github.com/pixelmaxQm)
|
||||
func (sysParamsService *SysParamsService) DeleteSysParamsByIds(IDs []string) (err error) {
|
||||
err = global.GVA_DB.Delete(&[]system.SysParams{}, "id in ?", IDs).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateSysParams 更新参数记录
|
||||
// Author [Mr.奇淼](https://github.com/pixelmaxQm)
|
||||
func (sysParamsService *SysParamsService) UpdateSysParams(sysParams system.SysParams) (err error) {
|
||||
err = global.GVA_DB.Model(&system.SysParams{}).Where("id = ?", sysParams.ID).Updates(&sysParams).Error
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user