diff --git a/.vscode/launch.json b/.vscode/launch.json index 841f537c..5bbd7638 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,7 @@ // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { "name": "mayfly-go", "type": "go", @@ -12,6 +13,6 @@ "program": "${fileDirname}/main.go", "env": {}, "args": [] - } + }, ] } \ No newline at end of file diff --git a/base/biz/bizerror.go b/base/biz/bizerror.go index 07ab5f7e..56cc0184 100644 --- a/base/biz/bizerror.go +++ b/base/biz/bizerror.go @@ -6,18 +6,11 @@ type BizError struct { err string } -const ( - SuccessCode = 200 - SuccessMsg = "success" - - BizErrorCode = 400 - BizErrorMsg = "error" - - ServerErrorCode = 500 - ServerErrorMsg = "server error" - - TokenErrorCode = 501 - TokenErrorMsg = "token error" +var ( + Success *BizError = NewBizErrCode(200, "success") + BizErr *BizError = NewBizErrCode(400, "biz error") + ServerError *BizError = NewBizErrCode(500, "server error") + PermissionErr *BizError = NewBizErrCode(501, "token error") ) // 错误消息 @@ -32,7 +25,7 @@ func (e *BizError) Code() int16 { // 创建业务逻辑错误结构体,默认为业务逻辑错误 func NewBizErr(msg string) *BizError { - return &BizError{code: BizErrorCode, err: msg} + return &BizError{code: BizErr.code, err: msg} } // 创建业务逻辑错误结构体,可设置指定错误code diff --git a/base/captcha/captcha.go b/base/captcha/captcha.go new file mode 100644 index 00000000..3dd9f51d --- /dev/null +++ b/base/captcha/captcha.go @@ -0,0 +1,28 @@ +package captcha + +import ( + "mayfly-go/base/biz" + + "github.com/mojocn/base64Captcha" +) + +var store = base64Captcha.DefaultMemStore +var driver base64Captcha.Driver = base64Captcha.DefaultDriverDigit + +// 生成验证码 +func Generate() (string, string) { + c := base64Captcha.NewCaptcha(driver, store) + // 获取 + id, b64s, err := c.Generate() + biz.ErrIsNilAppendErr(err, "获取验证码错误: %s") + return id, b64s +} + +// 验证验证码 +func Verify(id string, val string) bool { + if id == "" || val == "" { + return false + } + // 同时清理掉这个图片 + return store.Verify(id, val, true) +} diff --git a/base/config/config.go b/base/config/config.go index 43a4f807..865792a4 100644 --- a/base/config/config.go +++ b/base/config/config.go @@ -4,9 +4,13 @@ import ( "flag" "fmt" "mayfly-go/base/utils" + "mayfly-go/base/utils/assert" "path/filepath" ) +// 配置文件映射对象 +var Conf *Config + func init() { configFilePath := flag.String("e", "./config.yml", "配置文件路径,默认为可执行文件目录") flag.Parse() @@ -18,6 +22,8 @@ func init() { if err := utils.LoadYml(startConfigParam.ConfigFilePath, yc); err != nil { panic(fmt.Sprintf("读取配置文件[%s]失败: %s", startConfigParam.ConfigFilePath, err.Error())) } + // 校验配置文件内容信息 + yc.Valid() Conf = yc } @@ -33,12 +39,17 @@ var startConfigParam *CmdConfigParam type Config struct { App *App `yaml:"app"` Server *Server `yaml:"server"` + Jwt *Jwt `yaml:"jwt"` Redis *Redis `yaml:"redis"` Mysql *Mysql `yaml:"mysql"` + Log *Log `yaml:"log"` } -// 配置文件映射对象 -var Conf *Config +// 配置文件内容校验 +func (c *Config) Valid() { + assert.IsTrue(c.Jwt != nil, "配置文件的[jwt]信息不能为空") + c.Jwt.Valid() +} // 获取执行可执行文件时,指定的启动参数 func getStartConfig() *CmdConfigParam { diff --git a/base/config/jwt.go b/base/config/jwt.go new file mode 100644 index 00000000..a1492eb2 --- /dev/null +++ b/base/config/jwt.go @@ -0,0 +1,13 @@ +package config + +import "mayfly-go/base/utils/assert" + +type Jwt struct { + Key string `yaml:"key"` + ExpireTime uint64 `yaml:"expire-time"` // 过期时间,单位分钟 +} + +func (j *Jwt) Valid() { + assert.IsTrue(j.Key != "", "config.yml之 [jwt.key] 不能为空") + assert.IsTrue(j.ExpireTime != 0, "config.yml之 [jwt.expire-time] 不能为空") +} diff --git a/base/config/log.go b/base/config/log.go new file mode 100644 index 00000000..ac9815be --- /dev/null +++ b/base/config/log.go @@ -0,0 +1,30 @@ +package config + +import "path" + +type Log struct { + Level string `yaml:"level"` + File *LogFile `yaml:"file"` +} + +type LogFile struct { + Name string `yaml:"name"` + Path string `yaml:"path"` +} + +// 获取完整路径文件名 +func (l *LogFile) GetFilename() string { + var filepath, filename string + if fp := l.Path; fp == "" { + filepath = "./" + } else { + filepath = fp + } + if fn := l.Name; fn == "" { + filename = "default.log" + } else { + filename = fn + } + + return path.Join(filepath, filename) +} diff --git a/base/config/server.go b/base/config/server.go index bbced4be..381dcf32 100644 --- a/base/config/server.go +++ b/base/config/server.go @@ -6,6 +6,7 @@ type Server struct { Port int `yaml:"port"` Model string `yaml:"model"` Cors bool `yaml:"cors"` + Tls *Tls `yaml:"tls"` Static *[]*Static `yaml:"static"` StaticFile *[]*StaticFile `yaml:"static-file"` } @@ -23,3 +24,9 @@ type StaticFile struct { RelativePath string `yaml:"relative-path"` Filepath string `yaml:"filepath"` } + +type Tls struct { + Enable bool `yaml:"enable"` // 是否启用tls + KeyFile string `yaml:"key-file"` // 私钥文件路径 + CertFile string `yaml:"cert-file"` // 证书文件路径 +} diff --git a/base/ctx/log_handler.go b/base/ctx/log_handler.go index 7335a284..f1e3309e 100644 --- a/base/ctx/log_handler.go +++ b/base/ctx/log_handler.go @@ -9,14 +9,9 @@ import ( "reflect" "runtime/debug" - log "github.com/sirupsen/logrus" + "github.com/sirupsen/logrus" ) -func init() { - log.SetFormatter(new(logger.LogFormatter)) - log.SetReportCaller(true) -} - type LogInfo struct { LogResp bool // 是否记录返回结果 Description string // 请求描述 @@ -37,7 +32,7 @@ func LogHandler(rc *ReqCtx) error { return nil } - lfs := log.Fields{} + lfs := logrus.Fields{} if la := rc.LoginAccount; la != nil { lfs["uid"] = la.Id lfs["uname"] = la.Username @@ -47,10 +42,10 @@ func LogHandler(rc *ReqCtx) error { lfs[req.Method] = req.URL.Path if err := rc.Err; err != nil { - log.WithFields(lfs).Error(getErrMsg(rc, err)) + logger.Log.WithFields(lfs).Error(getErrMsg(rc, err)) return nil } - log.WithFields(lfs).Info(getLogMsg(rc)) + logger.Log.WithFields(lfs).Info(getLogMsg(rc)) return nil } diff --git a/base/ctx/permission_handler.go b/base/ctx/permission_handler.go index bcc97ec1..addc3ed4 100644 --- a/base/ctx/permission_handler.go +++ b/base/ctx/permission_handler.go @@ -4,6 +4,7 @@ import ( "fmt" "mayfly-go/base/biz" "mayfly-go/base/cache" + "mayfly-go/base/config" "time" ) @@ -37,7 +38,7 @@ type DefaultPermissionCodeRegistry struct { func (r *DefaultPermissionCodeRegistry) SaveCodes(userId uint64, codes []string) { if r.cache == nil { - r.cache = cache.NewTimedCache(30*time.Minute, 5*time.Second).WithUpdateAccessTime(true) + r.cache = cache.NewTimedCache(time.Minute*time.Duration(config.Conf.Jwt.ExpireTime), 5*time.Second) } r.cache.Put(fmt.Sprintf("%v", userId), codes) } @@ -79,7 +80,7 @@ func SetPermissionCodeRegistery(pcr PermissionCodeRegistry) { var ( permissionCodeRegistry PermissionCodeRegistry = &DefaultPermissionCodeRegistry{} - permissionError = biz.NewBizErrCode(biz.TokenErrorCode, biz.TokenErrorMsg) + // permissionError = biz.NewBizErrCode(biz.TokenErrorCode, biz.TokenErrorMsg) ) func PermissionHandler(rc *ReqCtx) error { @@ -94,16 +95,16 @@ func PermissionHandler(rc *ReqCtx) error { tokenStr = rc.GinCtx.Query("token") } if tokenStr == "" { - return permissionError + return biz.PermissionErr } loginAccount, err := ParseToken(tokenStr) if err != nil || loginAccount == nil { - return permissionError + return biz.PermissionErr } // 权限不为nil,并且permission code不为空,则校验是否有权限code if permission != nil && permission.Code != "" { if !permissionCodeRegistry.HasCode(loginAccount.Id, permission.Code) { - return permissionError + return biz.PermissionErr } } diff --git a/base/ctx/req_ctx.go b/base/ctx/req_ctx.go index 5b1fb221..8e9ff114 100644 --- a/base/ctx/req_ctx.go +++ b/base/ctx/req_ctx.go @@ -3,6 +3,7 @@ package ctx import ( "mayfly-go/base/ginx" "mayfly-go/base/model" + "mayfly-go/base/utils/assert" "time" "github.com/gin-gonic/gin" @@ -37,9 +38,7 @@ func (rc *ReqCtx) Handle(handler HandlerFunc) { // 应用所有请求后置处理器 ApplyHandlerInterceptor(afterHandlers, rc) }() - if ginCtx == nil { - panic("ginContext == nil") - } + assert.IsTrue(ginCtx != nil, "ginContext == nil") // 默认为不记录请求参数,可在handler回调函数中覆盖赋值 rc.ReqParam = 0 diff --git a/base/ctx/token.go b/base/ctx/token.go index d4993f71..db6176f1 100644 --- a/base/ctx/token.go +++ b/base/ctx/token.go @@ -4,15 +4,16 @@ import ( "errors" "mayfly-go/base/biz" + "mayfly-go/base/config" "mayfly-go/base/model" "time" "github.com/dgrijalva/jwt-go" ) -const ( - JwtKey = "mykey" - ExpTime = time.Hour * 24 * 7 +var ( + JwtKey = config.Conf.Jwt.Key + ExpTime = config.Conf.Jwt.ExpireTime ) // 创建用户token @@ -22,7 +23,7 @@ func CreateToken(userId uint64, username string) string { token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{ "id": userId, "username": username, - "exp": time.Now().Add(ExpTime).Unix(), + "exp": time.Now().Add(time.Minute * time.Duration(ExpTime)).Unix(), }) // 使用自定义字符串加密 and get the complete encoded token as a string diff --git a/base/ginx/ginx.go b/base/ginx/ginx.go index 98e6e3af..1b3c665f 100644 --- a/base/ginx/ginx.go +++ b/base/ginx/ginx.go @@ -1,7 +1,6 @@ package ginx import ( - "fmt" "mayfly-go/base/biz" "mayfly-go/base/global" "mayfly-go/base/model" @@ -13,14 +12,14 @@ import ( // 绑定并校验请求结构体参数 func BindJsonAndValid(g *gin.Context, data interface{}) { - if err := g.BindJSON(data); err != nil { + if err := g.ShouldBindJSON(data); err != nil { panic(biz.NewBizErr(err.Error())) } } // 绑定查询字符串到 func BindQuery(g *gin.Context, data interface{}) { - if err := g.BindQuery(data); err != nil { + if err := g.ShouldBindQuery(data); err != nil { panic(biz.NewBizErr(err.Error())) } } @@ -44,7 +43,6 @@ func QueryInt(g *gin.Context, qm string, defaultInt int) int { // 获取路径参数 func PathParamInt(g *gin.Context, pm string) int { value, _ := strconv.Atoi(g.Param(pm)) - biz.IsTrue(value != 0, fmt.Sprintf("%s不存在", pm)) return value } @@ -64,7 +62,7 @@ func SuccessRes(g *gin.Context, data interface{}) { func ErrorRes(g *gin.Context, err interface{}) { switch t := err.(type) { case *biz.BizError: - g.JSON(http.StatusOK, model.Error(t.Code(), t.Error())) + g.JSON(http.StatusOK, model.Error(t)) break case error: g.JSON(http.StatusOK, model.ServerError()) diff --git a/base/global/global.go b/base/global/global.go index ee6bd001..3eb6cf3e 100644 --- a/base/global/global.go +++ b/base/global/global.go @@ -1,17 +1,11 @@ package global import ( - "mayfly-go/base/config" - "mayfly-go/base/logger" - + "github.com/sirupsen/logrus" "gorm.io/gorm" ) -// 日志 -var Log = logger.Log - -// config.yml配置文件映射对象 -var Config = config.Conf - -// gorm -var Db *gorm.DB +var ( + Log *logrus.Logger // 日志 + Db *gorm.DB // gorm +) diff --git a/base/httpclient/httpclient.go b/base/httpclient/httpclient.go index 6792e1b1..a52735fe 100644 --- a/base/httpclient/httpclient.go +++ b/base/httpclient/httpclient.go @@ -7,10 +7,14 @@ import ( "fmt" "io" "io/ioutil" + "mime/multipart" "net/http" + "os" "time" ) +var client = &http.Client{} + // 默认超时 const DefTimeout = 60 @@ -22,6 +26,13 @@ type RequestWrapper struct { header map[string]string } +type MultipartFile struct { + FieldName string // 字段名 + FileName string // 文件名 + FilePath string // 文件路径,文件路径不为空,则优先读取文件路径的内容 + Bytes []byte // 文件内容 +} + // 创建一个请求 func NewRequest(url string) *RequestWrapper { return &RequestWrapper{url: url} @@ -31,12 +42,21 @@ func (r *RequestWrapper) Url(url string) *RequestWrapper { r.url = url return r } + +func (r *RequestWrapper) Header(name, value string) *RequestWrapper { + if r.header == nil { + r.header = make(map[string]string) + } + r.header[name] = value + return r +} + func (r *RequestWrapper) Timeout(timeout int) *RequestWrapper { r.timeout = timeout return r } -func (r *RequestWrapper) GetByParam(paramMap map[string]string) ResponseWrapper { +func (r *RequestWrapper) GetByParam(paramMap map[string]string) *ResponseWrapper { var params string for k, v := range paramMap { if params != "" { @@ -50,13 +70,13 @@ func (r *RequestWrapper) GetByParam(paramMap map[string]string) ResponseWrapper return r.Get() } -func (r *RequestWrapper) Get() ResponseWrapper { +func (r *RequestWrapper) Get() *ResponseWrapper { r.method = "GET" r.body = nil return request(r) } -func (r *RequestWrapper) PostJson(body string) ResponseWrapper { +func (r *RequestWrapper) PostJson(body string) *ResponseWrapper { buf := bytes.NewBufferString(body) r.method = "POST" r.body = buf @@ -67,7 +87,7 @@ func (r *RequestWrapper) PostJson(body string) ResponseWrapper { return request(r) } -func (r *RequestWrapper) PostObj(body interface{}) ResponseWrapper { +func (r *RequestWrapper) PostObj(body interface{}) *ResponseWrapper { marshal, err := json.Marshal(body) if err != nil { return createRequestError(errors.New("解析json obj错误")) @@ -75,7 +95,7 @@ func (r *RequestWrapper) PostObj(body interface{}) ResponseWrapper { return r.PostJson(string(marshal)) } -func (r *RequestWrapper) PostParams(params string) ResponseWrapper { +func (r *RequestWrapper) PostParams(params string) *ResponseWrapper { buf := bytes.NewBufferString(params) r.method = "POST" r.body = buf @@ -86,9 +106,54 @@ func (r *RequestWrapper) PostParams(params string) ResponseWrapper { return request(r) } +func (r *RequestWrapper) PostMulipart(files []MultipartFile, reqParams map[string]string) *ResponseWrapper { + buf := &bytes.Buffer{} + // 文件写入 buf + writer := multipart.NewWriter(buf) + for _, uploadFile := range files { + var reader io.Reader + // 如果文件路径不为空,则读取该路径文件,否则使用bytes + if uploadFile.FilePath != "" { + file, err := os.Open(uploadFile.FilePath) + if err != nil { + return createRequestError(err) + } + defer file.Close() + reader = file + } else { + reader = bytes.NewBuffer(uploadFile.Bytes) + } + + part, err := writer.CreateFormFile(uploadFile.FieldName, uploadFile.FileName) + if err != nil { + return createRequestError(err) + } + _, err = io.Copy(part, reader) + } + // 如果有其他参数,则写入body + if reqParams != nil { + for k, v := range reqParams { + if err := writer.WriteField(k, v); err != nil { + return createRequestError(err) + } + } + } + if err := writer.Close(); err != nil { + return createRequestError(err) + } + + r.method = "POST" + r.body = buf + if r.header == nil { + r.header = make(map[string]string) + } + r.header["Content-type"] = writer.FormDataContentType() + return request(r) +} + type ResponseWrapper struct { StatusCode int - Body string + Body []byte Header http.Header } @@ -96,28 +161,33 @@ func (r *ResponseWrapper) IsSuccess() bool { return r.StatusCode == 200 } -func (r *ResponseWrapper) ToObj(obj interface{}) { - if !r.IsSuccess() { - return - } - _ = json.Unmarshal([]byte(r.Body), &obj) +func (r *ResponseWrapper) BodyToObj(objPtr interface{}) error { + _ = json.Unmarshal(r.Body, &objPtr) + return r.getError() } -func (r *ResponseWrapper) ToMap() map[string]interface{} { - if !r.IsSuccess() { - return nil - } +func (r *ResponseWrapper) BodyToString() (string, error) { + return string(r.Body), r.getError() +} + +func (r *ResponseWrapper) BodyToMap() (map[string]interface{}, error) { var res map[string]interface{} - err := json.Unmarshal([]byte(r.Body), &res) + err := json.Unmarshal(r.Body, &res) if err != nil { - return nil + return nil, err } - return res + return res, r.getError() } -func request(rw *RequestWrapper) ResponseWrapper { - wrapper := ResponseWrapper{StatusCode: 0, Body: "", Header: make(http.Header)} - client := &http.Client{} +func (r *ResponseWrapper) getError() error { + if !r.IsSuccess() { + return errors.New(string(r.Body)) + } + return nil +} + +func request(rw *RequestWrapper) *ResponseWrapper { + wrapper := &ResponseWrapper{StatusCode: 0, Header: make(http.Header)} timeout := rw.timeout if timeout > 0 { client.Timeout = time.Duration(timeout) * time.Second @@ -132,17 +202,17 @@ func request(rw *RequestWrapper) ResponseWrapper { setRequestHeader(req, rw.header) resp, err := client.Do(req) if err != nil { - wrapper.Body = fmt.Sprintf("执行HTTP请求错误-%s", err.Error()) + wrapper.Body = []byte(fmt.Sprintf("执行HTTP请求错误-%s", err.Error())) return wrapper } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { - wrapper.Body = fmt.Sprintf("读取HTTP请求返回值失败-%s", err.Error()) + wrapper.Body = []byte(fmt.Sprintf("读取HTTP请求返回值失败-%s", err.Error())) return wrapper } wrapper.StatusCode = resp.StatusCode - wrapper.Body = string(body) + wrapper.Body = body wrapper.Header = resp.Header return wrapper @@ -155,7 +225,6 @@ func setRequestHeader(req *http.Request, header map[string]string) { } } -func createRequestError(err error) ResponseWrapper { - errorMessage := fmt.Sprintf("创建HTTP请求错误-%s", err.Error()) - return ResponseWrapper{0, errorMessage, make(http.Header)} +func createRequestError(err error) *ResponseWrapper { + return &ResponseWrapper{0, []byte(fmt.Sprintf("创建HTTP请求错误-%s", err.Error())), make(http.Header)} } diff --git a/base/logger/logger.go b/base/logger/logger.go index a123c1b7..c844bad0 100644 --- a/base/logger/logger.go +++ b/base/logger/logger.go @@ -2,6 +2,9 @@ package logger import ( "fmt" + "mayfly-go/base/config" + "mayfly-go/base/global" + "os" "strings" "time" @@ -11,12 +14,38 @@ import ( var Log = logrus.New() func init() { - // customFormatter := new(logrus.TextFormatter) - // customFormatter.TimestampFormat = "2006-01-02 15:04:05.000" - // customFormatter.FullTimestamp = true Log.SetFormatter(new(LogFormatter)) Log.SetReportCaller(true) - Log.SetLevel(logrus.DebugLevel) + + logConf := config.Conf.Log + // 如果不存在日志配置信息,则默认debug级别 + if logConf == nil { + Log.SetLevel(logrus.DebugLevel) + return + } + + // 根据配置文件设置日志级别 + if level := logConf.Level; level != "" { + l, err := logrus.ParseLevel(level) + if err != nil { + panic(fmt.Sprintf("日志级别不存在: %s", level)) + } + Log.SetLevel(l) + } else { + Log.SetLevel(logrus.DebugLevel) + } + + if logFile := logConf.File; logFile != nil { + //写入文件 + file, err := os.OpenFile(logFile.GetFilename(), os.O_CREATE|os.O_APPEND|os.O_WRONLY, os.ModeAppend|0666) + if err != nil { + panic(fmt.Sprintf("创建日志文件失败: %s", err.Error())) + } + + Log.Out = file + } + + global.Log = Log } type LogFormatter struct{} diff --git a/base/model/model.go b/base/model/model.go index 3e410729..3b108f05 100644 --- a/base/model/model.go +++ b/base/model/model.go @@ -2,6 +2,7 @@ package model import ( "fmt" + "mayfly-go/base/biz" "mayfly-go/base/global" "strconv" @@ -71,22 +72,13 @@ func GetById(model interface{}, id uint64, cols ...string) error { // 根据id列表查询 func GetByIdIn(model interface{}, list interface{}, ids []uint64, orderBy ...string) { - var idsStr string - for i, v := range ids { - idStr := strconv.Itoa(int(v)) - if i == 0 { - idsStr += idStr - } else { - idsStr += ("," + idStr) - } - } var orderByStr string if orderBy == nil { orderByStr = "id desc" } else { orderByStr = strings.Join(orderBy, ",") } - global.Db.Model(model).Where("id in (?)", idsStr).Order(orderByStr).Find(list) + global.Db.Model(model).Where("id in (?)", ids).Order(orderByStr).Find(list) } // 根据id列表查询 @@ -151,11 +143,11 @@ func GetByConditionTo(conditionModel interface{}, toModel interface{}) error { } // 获取分页结果 -func GetPage(pageParam *PageParam, conditionModel interface{}, toModels interface{}, orderBy ...string) PageResult { +func GetPage(pageParam *PageParam, conditionModel interface{}, toModels interface{}, orderBy ...string) *PageResult { var count int64 global.Db.Model(conditionModel).Where(conditionModel).Count(&count) if count == 0 { - return PageResult{Total: 0, List: []string{}} + return &PageResult{Total: 0, List: []string{}} } page := pageParam.PageNum pageSize := pageParam.PageSize @@ -165,12 +157,13 @@ func GetPage(pageParam *PageParam, conditionModel interface{}, toModels interfac } else { orderByStr = strings.Join(orderBy, ",") } - global.Db.Model(conditionModel).Where(conditionModel).Order(orderByStr).Limit(pageSize).Offset((page - 1) * pageSize).Find(toModels) - return PageResult{Total: count, List: toModels} + err := global.Db.Model(conditionModel).Where(conditionModel).Order(orderByStr).Limit(pageSize).Offset((page - 1) * pageSize).Find(toModels).Error + biz.ErrIsNil(err, "查询失败") + return &PageResult{Total: count, List: toModels} } // 根据sql获取分页对象 -func GetPageBySql(sql string, param *PageParam, toModel interface{}, args ...interface{}) PageResult { +func GetPageBySql(sql string, param *PageParam, toModel interface{}, args ...interface{}) *PageResult { db := global.Db selectIndex := strings.Index(sql, "SELECT ") + 7 fromIndex := strings.Index(sql, " FROM") @@ -180,12 +173,13 @@ func GetPageBySql(sql string, param *PageParam, toModel interface{}, args ...int var count int db.Raw(countSql, args...).Scan(&count) if count == 0 { - return PageResult{Total: 0, List: []string{}} + return &PageResult{Total: 0, List: []string{}} } // 分页查询 limitSql := sql + " LIMIT " + strconv.Itoa(param.PageNum-1) + ", " + strconv.Itoa(param.PageSize) - db.Raw(limitSql).Scan(toModel) - return PageResult{Total: int64(count), List: toModel} + err := db.Raw(limitSql).Scan(toModel).Error + biz.ErrIsNil(err, "查询失败") + return &PageResult{Total: int64(count), List: toModel} } func GetListBySql(sql string, params ...interface{}) []map[string]interface{} { @@ -194,6 +188,6 @@ func GetListBySql(sql string, params ...interface{}) []map[string]interface{} { return maps } -func GetListBySql2Model(sql string, toEntity interface{}, params ...interface{}) { - global.Db.Raw(sql, params).Find(toEntity) +func GetListBySql2Model(sql string, toEntity interface{}, params ...interface{}) error { + return global.Db.Raw(sql, params).Find(toEntity).Error } diff --git a/base/model/result.go b/base/model/result.go index 442503cf..93c340dc 100644 --- a/base/model/result.go +++ b/base/model/result.go @@ -3,20 +3,12 @@ package model import ( "encoding/json" "fmt" + "mayfly-go/base/biz" ) const ( SuccessCode = 200 SuccessMsg = "success" - - BizErrorCode = 400 - BizErrorMsg = "error" - - ServerErrorCode = 500 - ServerErrorMsg = "server error" - - TokenErrorCode = 501 - TokenErrorMsg = "token error" ) // 统一返回结果结构体 @@ -52,15 +44,19 @@ func SuccessNoData() *Result { return &Result{Code: SuccessCode, Msg: SuccessMsg} } -// 返回服务器错误Result -func ServerError() *Result { - return &Result{Code: ServerErrorCode, Msg: ServerErrorMsg} +func Error(bizerr *biz.BizError) *Result { + return &Result{Code: bizerr.Code(), Msg: bizerr.Error()} } -func Error(code int16, msg string) *Result { - return &Result{Code: code, Msg: msg} +// 返回服务器错误Result +func ServerError() *Result { + return Error(biz.ServerError) } func TokenError() *Result { - return &Result{Code: TokenErrorCode, Msg: TokenErrorMsg} + return Error(biz.PermissionErr) +} + +func ErrorBy(code int16, msg string) *Result { + return &Result{Code: code, Msg: msg} } diff --git a/base/starter/gorm.go b/base/starter/gorm.go index 3d0b2dc5..0a69bd2d 100644 --- a/base/starter/gorm.go +++ b/base/starter/gorm.go @@ -1,6 +1,7 @@ package starter import ( + "mayfly-go/base/config" "mayfly-go/base/global" "gorm.io/driver/mysql" @@ -10,7 +11,7 @@ import ( ) func GormMysql() *gorm.DB { - m := global.Config.Mysql + m := config.Conf.Mysql if m == nil || m.Dbname == "" { global.Log.Panic("未找到数据库配置信息") return nil diff --git a/base/starter/redis.go b/base/starter/redis.go index 578099bb..000ae31b 100644 --- a/base/starter/redis.go +++ b/base/starter/redis.go @@ -2,6 +2,7 @@ package starter import ( "fmt" + "mayfly-go/base/config" "mayfly-go/base/global" "github.com/go-redis/redis" @@ -9,7 +10,7 @@ import ( func ConnRedis() *redis.Client { // 设置redis客户端 - redisConf := global.Config.Redis + redisConf := config.Conf.Redis if redisConf == nil { global.Log.Panic("未找到redis配置信息") } diff --git a/base/starter/web-server.go b/base/starter/web-server.go index 3616eddb..7dfb250a 100644 --- a/base/starter/web-server.go +++ b/base/starter/web-server.go @@ -1,17 +1,24 @@ package starter import ( + "mayfly-go/base/config" "mayfly-go/base/global" "github.com/gin-gonic/gin" ) func RunWebServer(web *gin.Engine) { - port := global.Config.Server.GetPort() - if app := global.Config.App; app != nil { + server := config.Conf.Server + port := server.GetPort() + if app := config.Conf.App; app != nil { global.Log.Infof("%s- Listening and serving HTTP on %s", app.GetAppInfo(), port) } else { global.Log.Infof("Listening and serving HTTP on %s", port) } - web.Run(port) + + if server.Tls != nil && server.Tls.Enable { + web.RunTLS(port, server.Tls.CertFile, server.Tls.KeyFile) + } else { + web.Run(port) + } } diff --git a/base/utils/assert/assert.go b/base/utils/assert/assert.go new file mode 100644 index 00000000..28855a14 --- /dev/null +++ b/base/utils/assert/assert.go @@ -0,0 +1,21 @@ +package assert + +import "fmt" + +// 断言条件为真,不满足的panic +func IsTrue(condition bool, panicMsg string, params ...interface{}) { + if !condition { + if len(params) != 0 { + panic(fmt.Sprintf(panicMsg, params...)) + } + panic(panicMsg) + } +} + +func State(condition bool, panicMsg string, params ...interface{}) { + IsTrue(condition, panicMsg, params...) +} + +func NotEmpty(str string, panicMsg string, params ...interface{}) { + IsTrue(str != "", panicMsg, params...) +} diff --git a/base/utils/jsonschemal_util.go b/base/utils/jsonschemal_util.go new file mode 100644 index 00000000..6a7396f5 --- /dev/null +++ b/base/utils/jsonschemal_util.go @@ -0,0 +1,26 @@ +package utils + +import ( + "errors" + "strings" + + "github.com/xeipuuv/gojsonschema" +) + +func ValidJsonString(schemal, json string) error { + scheme, jsonLoader := gojsonschema.NewStringLoader(schemal), gojsonschema.NewStringLoader(json) + + result, err := gojsonschema.Validate(scheme, jsonLoader) + if err != nil { + return err + } + if result.Valid() { + return nil + } + errs := make([]string, 0) + for _, desc := range result.Errors() { + errs = append(errs, desc.String()) + } + + return errors.New(strings.Join(errs, "|")) +} diff --git a/base/utils/jsonschemal_util_test.go b/base/utils/jsonschemal_util_test.go new file mode 100644 index 00000000..22df2c25 --- /dev/null +++ b/base/utils/jsonschemal_util_test.go @@ -0,0 +1,58 @@ +package utils + +import ( + "fmt" + "testing" + + "github.com/xeipuuv/gojsonschema" +) + +func TestJsonSchemal(t *testing.T) { + schema := `{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Product", + "description": "A product from Acme's catalog", + "type": "object", + "properties": { + "id": { + "description": "The unique identifier for a product", + "type": "integer" + }, + "name": { + "description": "Name of the product", + "type": "string" + }, + "price": { + "type": "number", + "minimum": 0, + "exclusiveMinimum": true + } + }, + "required": ["id", "name", "price"] + } + ` + + json := `{"id": 1, "name": "test", "price": -21}` + + err := ValidJsonString(schema, json) + fmt.Print(err) +} + +func TestJs(t *testing.T) { + schemaLoader := gojsonschema.NewStringLoader(`{"type": "object","properties":{"a":{"type":"object"}},"required":["a"]}`) // json格式 + documentLoader := gojsonschema.NewStringLoader(`{"a":"b"}`) // 待校验的json数据 + + result, err := gojsonschema.Validate(schemaLoader, documentLoader) + if err != nil { + panic(err.Error()) + } + + if result.Valid() { + fmt.Printf("The document is valid\n") + } else { + fmt.Printf("The document is not valid. see errors :\n") + for _, desc := range result.Errors() { + fmt.Printf("- %s\n", desc) + } + } +} diff --git a/base/utils/yml.go b/base/utils/yml.go index 4f0277d4..280e6ff2 100644 --- a/base/utils/yml.go +++ b/base/utils/yml.go @@ -20,3 +20,8 @@ func LoadYml(path string, out interface{}) error { } return nil } + +func LoadYmlByString(yamlStr string, out interface{}) error { + // yaml解析 + return yaml.Unmarshal([]byte(yamlStr), out) +} diff --git a/go.mod b/go.mod index 9912f0ed..2c3e3e81 100644 --- a/go.mod +++ b/go.mod @@ -5,20 +5,23 @@ go 1.16 require ( // jwt github.com/dgrijalva/jwt-go v3.2.0+incompatible - github.com/gin-gonic/gin v1.6.2 - github.com/go-redis/redis v6.14.2+incompatible - github.com/go-sql-driver/mysql v1.5.0 + github.com/gin-gonic/gin v1.7.2 + github.com/go-redis/redis v6.15.9+incompatible github.com/gorilla/websocket v1.4.2 - github.com/onsi/ginkgo v1.16.1 // indirect - github.com/onsi/gomega v1.11.0 // indirect - github.com/pkg/sftp v1.12.0 + // 验证码 + github.com/mojocn/base64Captcha v1.3.4 + github.com/onsi/ginkgo v1.16.4 // indirect + github.com/onsi/gomega v1.13.0 // indirect + github.com/pkg/sftp v1.13.1 // 定时任务 github.com/robfig/cron/v3 v3.0.1 - github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0 - github.com/sirupsen/logrus v1.6.0 + github.com/sirupsen/logrus v1.8.1 + // jsonschemal校验 + github.com/xeipuuv/gojsonschema v1.2.0 // ssh - golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a + golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c + // gorm gorm.io/driver/mysql v1.0.5 - gorm.io/gorm v1.21.6 + gorm.io/gorm v1.21.11 ) diff --git a/go.sum b/go.sum index 36abd997..5c6b7b67 100644 --- a/go.sum +++ b/go.sum @@ -8,21 +8,23 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.6.2 h1:88crIK23zO6TqlQBt+f9FrPJNKm9ZEr7qjp9vl/d5TM= -github.com/gin-gonic/gin v1.6.2/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= +github.com/gin-gonic/gin v1.7.2 h1:Tg03T9yM2xa8j6I3Z3oqLaQRSmKvxPd6g/2HJ6zICFA= +github.com/gin-gonic/gin v1.7.2/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY= github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= -github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= -github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= -github.com/go-redis/redis v6.14.2+incompatible h1:UE9pLhzmWf+xHNmZsoccjXosPicuiNaInPgym8nzfg0= -github.com/go-redis/redis v6.14.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= +github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= +github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= +github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg= +github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= @@ -31,12 +33,14 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= @@ -48,8 +52,6 @@ github.com/jinzhu/now v1.1.2 h1:eVKgfIdy9b6zbWBMgFpfDPoAMifwSZagU9HmEU6zgiI= github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= -github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= @@ -60,73 +62,91 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OH github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mojocn/base64Captcha v1.3.4 h1:9+MZzjNSfBHniYOIpoP4xyDDPCXy14JIjsEFf89PlNw= +github.com/mojocn/base64Captcha v1.3.4/go.mod h1:wAQCKEc5bDujxKRmbT6/vTnTt5CjStQ8bRfPWUuz/iY= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.16.1 h1:foqVmeWDD6yYpK+Yz3fHyNIxFYNxswxqNFjSKe+vI54= -github.com/onsi/ginkgo v1.16.1/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E= +github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E= +github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= +github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.11.0 h1:+CqWgvj0OZycCaqclBD1pxKHAU+tOkHmQIWvDHq2aug= -github.com/onsi/gomega v1.11.0/go.mod h1:azGKhqFUon9Vuj0YmTfLSmx0FUwqXYSTl5re8lQLTUg= +github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak= +github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/sftp v1.12.0 h1:/f3b24xrDhkhddlaobPe2JgBqfdt+gC/NYl0QY9IOuI= -github.com/pkg/sftp v1.12.0/go.mod h1:fUqqXB5vEgVCZ131L+9say31RAri6aF6KDViawhxKK8= +github.com/pkg/sftp v1.13.1 h1:I2qBYMChEhIjOgazfJmV3/mZM256btk6wkCDRmW7JYs= +github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= -github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0 h1:QIF48X1cihydXibm+4wfAc0r/qyPyuFiPFRNphdMpEE= -github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw= -github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= -github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= +github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c= +github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= +github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= +github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM= -golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI= +golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/image v0.0.0-20190501045829-6d32002ffd75 h1:TbGuee8sSq15Iguxu4deQ7+Bqq/d2rsQejGcEtADAMQ= +golang.org/x/image v0.0.0-20190501045829-6d32002ffd75/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U= -golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210112080510-489259a85091 h1:DMyOG0U+gKfu8JZzg2UQe9MeaC1X+xQWlAKcRnjxjCw= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= @@ -140,8 +160,10 @@ google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= @@ -158,5 +180,5 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gorm.io/driver/mysql v1.0.5 h1:WAAmvLK2rG0tCOqrf5XcLi2QUwugd4rcVJ/W3aoon9o= gorm.io/driver/mysql v1.0.5/go.mod h1:N1OIhHAIhx5SunkMGqWbGFVeh4yTNWKmMo1GOAsohLI= gorm.io/gorm v1.21.3/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw= -gorm.io/gorm v1.21.6 h1:xEFbH7WShsnAM+HeRNv7lOeyqmDAK+dDnf1AMf/cVPQ= -gorm.io/gorm v1.21.6/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0= +gorm.io/gorm v1.21.11 h1:CxkXW6Cc+VIBlL8yJEHq+Co4RYXdSLiMKNvgoZPjLK4= +gorm.io/gorm v1.21.11/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0= diff --git a/mayfly_go_web/.env.production b/mayfly_go_web/.env.production index 4f6692c6..e038d163 100644 --- a/mayfly_go_web/.env.production +++ b/mayfly_go_web/.env.production @@ -2,4 +2,4 @@ ENV = 'production' # 线上环境接口地址 -VITE_API_URL = 'http://localhost:8888/api' \ No newline at end of file +VITE_API_URL = 'http://api.mayflygo.1yue.net/api' \ No newline at end of file diff --git a/mayfly_go_web/index.html b/mayfly_go_web/index.html index 04d827ab..24eb58f5 100644 --- a/mayfly_go_web/index.html +++ b/mayfly_go_web/index.html @@ -18,6 +18,7 @@
+ diff --git a/mayfly_go_web/package.json b/mayfly_go_web/package.json index 84ce3352..0f7c81eb 100644 --- a/mayfly_go_web/package.json +++ b/mayfly_go_web/package.json @@ -7,9 +7,9 @@ "lint-fix": "eslint --fix --ext .js --ext .jsx --ext .vue src/" }, "dependencies": { - "core-js": "^3.6.5", "axios": "^0.21.1", "codemirror": "^5.61.0", + "core-js": "^3.6.5", "countup.js": "^2.0.7", "cropperjs": "^1.5.11", "echarts": "^5.1.1", diff --git a/mayfly_go_web/public/config.js b/mayfly_go_web/public/config.js new file mode 100644 index 00000000..40d33388 --- /dev/null +++ b/mayfly_go_web/public/config.js @@ -0,0 +1,3 @@ +window.globalConfig = { + "BaseApiUrl": "http://localhost:8888/api" +} \ No newline at end of file diff --git a/mayfly_go_web/src/common/Api.ts b/mayfly_go_web/src/common/Api.ts index 6b4d3e03..3a7fc83e 100644 --- a/mayfly_go_web/src/common/Api.ts +++ b/mayfly_go_web/src/common/Api.ts @@ -48,7 +48,7 @@ class Api { * 操作该权限,即请求对应的url * @param {Object} param 请求该权限的参数 */ - request(param: any): Promise { + request(param: any = null): Promise { return request.send(this, param); } diff --git a/mayfly_go_web/src/common/assert.ts b/mayfly_go_web/src/common/assert.ts index 65cb5854..6af5872c 100644 --- a/mayfly_go_web/src/common/assert.ts +++ b/mayfly_go_web/src/common/assert.ts @@ -3,7 +3,7 @@ */ class AssertError extends Error { constructor(message: string) { - super(message); // (1) + super(message); // 错误类名 this.name = "AssertError"; } diff --git a/mayfly_go_web/src/common/config.ts b/mayfly_go_web/src/common/config.ts index 72993fb7..aae770dd 100644 --- a/mayfly_go_web/src/common/config.ts +++ b/mayfly_go_web/src/common/config.ts @@ -1,5 +1,5 @@ const config = { - baseApiUrl: import.meta.env.VITE_API_URL + baseApiUrl: (window as any).globalConfig.BaseApiUrl } export default config \ No newline at end of file diff --git a/mayfly_go_web/src/common/openApi.ts b/mayfly_go_web/src/common/openApi.ts index 2afdb21f..2bd17f60 100644 --- a/mayfly_go_web/src/common/openApi.ts +++ b/mayfly_go_web/src/common/openApi.ts @@ -2,7 +2,7 @@ import request from './request' export default { login: (param: any) => request.request('POST', '/sys/accounts/login', param, null), - captcha: () => request.request('GET', '/open/captcha', null, null), + captcha: () => request.request('GET', '/sys/captcha', null, null), logout: (param: any) => request.request('POST', '/sys/accounts/logout/{token}', param, null), getMenuRoute: (param: any) => request.request('Get', '/sys/resources/account', param, null) } \ No newline at end of file diff --git a/mayfly_go_web/src/components/codemirror/codemirror.vue b/mayfly_go_web/src/components/codemirror/codemirror.vue index 729af4fe..8a2c6087 100644 --- a/mayfly_go_web/src/components/codemirror/codemirror.vue +++ b/mayfly_go_web/src/components/codemirror/codemirror.vue @@ -53,6 +53,14 @@ export default defineComponent({ type: String, default: null, }, + height: { + type: String, + default: "500px", + }, + width: { + type: String, + default: "auto", + }, canChangeMode: { type: Boolean, default: false, @@ -165,15 +173,14 @@ export default defineComponent({ } ); - watch( - () => props.options, - (newValue, oldValue) => { - console.log('options change', newValue); - for (const key in newValue) { - coder.setOption(key, newValue[key]); - } - } - ); + // watch( + // () => props.options, + // (newValue, oldValue) => { + // for (const key in newValue) { + // coder.setOption(key, newValue[key]); + // } + // } + // ); const init = () => { if (props.options) { @@ -195,6 +202,9 @@ export default defineComponent({ } }); + coder.setSize(props.width, props.height); + // editor.setSize('width','height'); + // 修改编辑器的语法配置 setMode(language.value); @@ -285,6 +295,7 @@ export default defineComponent({ coder.setValue(newVal); state.content = newVal; coder.scrollTo(scrollInfo.left, scrollInfo.top); + refresh() } }; @@ -292,6 +303,7 @@ export default defineComponent({ ...toRefs(state), textarea, changeMode, + refresh, }; }, }); diff --git a/mayfly_go_web/src/components/dynamic-form/DynamicForm.vue b/mayfly_go_web/src/components/dynamic-form/DynamicForm.vue index 04c2c7f8..382df614 100755 --- a/mayfly_go_web/src/components/dynamic-form/DynamicForm.vue +++ b/mayfly_go_web/src/components/dynamic-form/DynamicForm.vue @@ -85,7 +85,7 @@ export default defineComponent({ }); const submit = () => { - dynamicForm.validate((valid: boolean) => { + dynamicForm.value.validate((valid: boolean) => { if (valid) { // 提交的表单数据 const subform = { ...state.form }; diff --git a/mayfly_go_web/src/router/imports.ts b/mayfly_go_web/src/router/imports.ts index bcc3a100..3c7eabd9 100644 --- a/mayfly_go_web/src/router/imports.ts +++ b/mayfly_go_web/src/router/imports.ts @@ -8,5 +8,9 @@ export const imports = { "ResourceList": () => import('@/views/system/resource'), "RoleList": () => import('@/views/system/role'), "AccountList": () => import('@/views/system/account'), - "SelectData": () => import('@/views/ops/db'), + "ProjectList": () => import('@/views/ops/project/ProjectList.vue'), + "DbList": () => import('@/views/ops/db/DbList.vue'), + "SqlExec": () => import('@/views/ops/db'), + "RedisList": () => import('@/views/ops/redis'), + "DataOperation": () => import('@/views/ops/redis/DataOperation.vue'), } \ No newline at end of file diff --git a/mayfly_go_web/src/theme/app.scss b/mayfly_go_web/src/theme/app.scss index c9cefdbe..b75076ef 100644 --- a/mayfly_go_web/src/theme/app.scss +++ b/mayfly_go_web/src/theme/app.scss @@ -14,8 +14,8 @@ body, padding: 0; width: 100%; height: 100%; - font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, SimSun, sans-serif; - font-weight: 500; + font-family: Microsoft YaHei, Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, SimSun, sans-serif; + font-weight: 450; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; background-color: #f8f8f8; @@ -274,7 +274,7 @@ body, .toolbar { width: 100%; - padding: 8px; + padding: 6px; background-color: #ffffff; overflow: hidden; line-height: 32px; @@ -283,4 +283,10 @@ body, .fl { float: left; +} + +.search-form { + .el-form-item { + margin-bottom: 3px; + } } \ No newline at end of file diff --git a/mayfly_go_web/src/views/error/401.vue b/mayfly_go_web/src/views/error/401.vue index 902e0262..05ec891d 100644 --- a/mayfly_go_web/src/views/error/401.vue +++ b/mayfly_go_web/src/views/error/401.vue @@ -4,10 +4,10 @@
401
-
您未被授权,没有操作权限
+
您未被授权或登录超时,没有操作权限
- 重新授权 + 重新登录
diff --git a/mayfly_go_web/src/views/home/index.vue b/mayfly_go_web/src/views/home/index.vue index 5712a5ac..e11caeb0 100644 --- a/mayfly_go_web/src/views/home/index.vue +++ b/mayfly_go_web/src/views/home/index.vue @@ -7,8 +7,8 @@
-
{{ currentTime }},admin!
-
超级管理
+
{{ `${currentTime}, ${getUserInfos.username}` }}
+
diff --git a/mayfly_go_web/src/views/login/component/Account.vue b/mayfly_go_web/src/views/login/component/Account.vue index 7cb8b0f0..cb7db49e 100644 --- a/mayfly_go_web/src/views/login/component/Account.vue +++ b/mayfly_go_web/src/views/login/component/Account.vue @@ -1,10 +1,10 @@ + diff --git a/mayfly_go_web/src/views/ops/db/DbEdit.vue b/mayfly_go_web/src/views/ops/db/DbEdit.vue new file mode 100644 index 00000000..8979bef2 --- /dev/null +++ b/mayfly_go_web/src/views/ops/db/DbEdit.vue @@ -0,0 +1,240 @@ + + + + diff --git a/mayfly_go_web/src/views/ops/db/DbList.vue b/mayfly_go_web/src/views/ops/db/DbList.vue new file mode 100644 index 00000000..8aac35f2 --- /dev/null +++ b/mayfly_go_web/src/views/ops/db/DbList.vue @@ -0,0 +1,196 @@ + + + + diff --git a/mayfly_go_web/src/views/ops/db/SelectData.vue b/mayfly_go_web/src/views/ops/db/SqlExec.vue similarity index 52% rename from mayfly_go_web/src/views/ops/db/SelectData.vue rename to mayfly_go_web/src/views/ops/db/SqlExec.vue index 51cf12ce..08f3f292 100644 --- a/mayfly_go_web/src/views/ops/db/SelectData.vue +++ b/mayfly_go_web/src/views/ops/db/SqlExec.vue @@ -1,15 +1,28 @@ + diff --git a/mayfly_go_web/src/views/ops/machine/MachineList.vue b/mayfly_go_web/src/views/ops/machine/MachineList.vue index bccf8c9b..8dc0b169 100644 --- a/mayfly_go_web/src/views/ops/machine/MachineList.vue +++ b/mayfly_go_web/src/views/ops/machine/MachineList.vue @@ -42,16 +42,19 @@ - - - - + + + + + - - + + @@ -59,7 +62,7 @@ @@ -75,6 +78,12 @@ :page-size="params.pageSize" /> + + @@ -82,40 +91,32 @@ - - + diff --git a/mayfly_go_web/src/views/ops/project/api.ts b/mayfly_go_web/src/views/ops/project/api.ts new file mode 100644 index 00000000..9603fe2a --- /dev/null +++ b/mayfly_go_web/src/views/ops/project/api.ts @@ -0,0 +1,15 @@ +import Api from '@/common/Api'; + +export const projectApi = { + // 获取账号可访问的项目列表 + accountProjects: Api.create("/accounts/projects", 'get'), + projects: Api.create("/projects", 'get'), + saveProject: Api.create("/projects", 'post'), + // 获取项目下的环境信息 + projectEnvs: Api.create("/projects/{projectId}/envs", 'get'), + saveProjectEnv: Api.create("/projects/{projectId}/envs", 'post'), + // 获取项目下的成员信息 + projectMems: Api.create("/projects/{projectId}/members", 'get'), + saveProjectMem: Api.create("/projects/{projectId}/members", 'post'), + deleteProjectMem: Api.create("/projects/{projectId}/members/{accountId}", 'delete'), +} \ No newline at end of file diff --git a/mayfly_go_web/src/views/ops/redis/DataOperation.vue b/mayfly_go_web/src/views/ops/redis/DataOperation.vue new file mode 100644 index 00000000..94d871e7 --- /dev/null +++ b/mayfly_go_web/src/views/ops/redis/DataOperation.vue @@ -0,0 +1,281 @@ + + + + + diff --git a/mayfly_go_web/src/views/ops/redis/Info.vue b/mayfly_go_web/src/views/ops/redis/Info.vue new file mode 100644 index 00000000..1404919e --- /dev/null +++ b/mayfly_go_web/src/views/ops/redis/Info.vue @@ -0,0 +1,200 @@ + + + + + diff --git a/mayfly_go_web/src/views/ops/redis/RedisEdit.vue b/mayfly_go_web/src/views/ops/redis/RedisEdit.vue new file mode 100644 index 00000000..5c194435 --- /dev/null +++ b/mayfly_go_web/src/views/ops/redis/RedisEdit.vue @@ -0,0 +1,190 @@ + + + + diff --git a/mayfly_go_web/src/views/ops/redis/RedisList.vue b/mayfly_go_web/src/views/ops/redis/RedisList.vue new file mode 100644 index 00000000..42bd3583 --- /dev/null +++ b/mayfly_go_web/src/views/ops/redis/RedisList.vue @@ -0,0 +1,369 @@ + + + + + diff --git a/mayfly_go_web/src/views/ops/redis/ValueDialog.vue b/mayfly_go_web/src/views/ops/redis/ValueDialog.vue new file mode 100644 index 00000000..854b17e5 --- /dev/null +++ b/mayfly_go_web/src/views/ops/redis/ValueDialog.vue @@ -0,0 +1,76 @@ + + \ No newline at end of file diff --git a/mayfly_go_web/src/views/ops/redis/api.ts b/mayfly_go_web/src/views/ops/redis/api.ts new file mode 100644 index 00000000..ecbd3a85 --- /dev/null +++ b/mayfly_go_web/src/views/ops/redis/api.ts @@ -0,0 +1,17 @@ +import Api from '@/common/Api'; + +export const redisApi = { + redisList : Api.create("/redis", 'get'), + redisInfo: Api.create("/redis/{id}/info", 'get'), + saveRedis: Api.create("/redis", 'post'), + delRedis: Api.create("/redis/{id}", 'delete'), + // 获取权限列表 + scan: Api.create("/redis/{id}/scan/{cursor}/{count}", 'get'), + getStringValue: Api.create("/redis/{id}/string-value", 'get'), + saveStringValue: Api.create("/redis/{id}/string-value", 'post'), + getHashValue: Api.create("/redis/{id}/hash-value", 'get'), + getSetValue: Api.create("/redis/{id}/set-value", 'get'), + saveHashValue: Api.create("/redis/{id}/hash-value", 'post'), + del: Api.create("/redis/{id}/scan/{cursor}/{count}", 'delete'), + delKey: Api.create("/redis/{id}/key", 'delete'), +} \ No newline at end of file diff --git a/mayfly_go_web/src/views/ops/redis/index.ts b/mayfly_go_web/src/views/ops/redis/index.ts new file mode 100644 index 00000000..bb536523 --- /dev/null +++ b/mayfly_go_web/src/views/ops/redis/index.ts @@ -0,0 +1 @@ +export { default } from './RedisList.vue'; \ No newline at end of file diff --git a/mayfly_go_web/src/views/system/account/AccountEdit.vue b/mayfly_go_web/src/views/system/account/AccountEdit.vue index 6acdccad..e094c511 100755 --- a/mayfly_go_web/src/views/system/account/AccountEdit.vue +++ b/mayfly_go_web/src/views/system/account/AccountEdit.vue @@ -3,14 +3,14 @@ - + - + + + + - + --> - - + +