feat: delete useless
This commit is contained in:
@@ -2,35 +2,13 @@ package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/astaxie/beego/validation"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"message-nest/pkg/e"
|
||||
"message-nest/pkg/util"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// BindAndValid binds and validates data
|
||||
func BindAndValid(c *gin.Context, form interface{}) (int, int) {
|
||||
err := c.Bind(form)
|
||||
if err != nil {
|
||||
return http.StatusBadRequest, e.INVALID_PARAMS
|
||||
}
|
||||
|
||||
valid := validation.Validation{}
|
||||
check, err := valid.Valid(form)
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, e.ERROR
|
||||
}
|
||||
if !check {
|
||||
MarkErrors(valid.Errors)
|
||||
return http.StatusBadRequest, e.INVALID_PARAMS
|
||||
}
|
||||
|
||||
return http.StatusOK, e.SUCCESS
|
||||
}
|
||||
|
||||
func CommonPlaygroundValid(obj interface{}) (int, string) {
|
||||
if err := util.CustomerValidate.Struct(obj); err != nil {
|
||||
errs := err.(validator.ValidationErrors)
|
||||
|
||||
@@ -2,20 +2,9 @@ package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/astaxie/beego/validation"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"message-nest/pkg/logging"
|
||||
)
|
||||
|
||||
// MarkErrors logs error logs
|
||||
func MarkErrors(errors []*validation.Error) {
|
||||
for _, err := range errors {
|
||||
logging.Logger.Error(err.Key, err.Message)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 从请求中获取当前用户
|
||||
func GetCurrentUserName(c *gin.Context) string {
|
||||
userName, ok := c.Get("currentUserName")
|
||||
|
||||
@@ -3,8 +3,6 @@ package app
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
|
||||
"message-nest/pkg/e"
|
||||
)
|
||||
|
||||
type Gin struct {
|
||||
@@ -17,16 +15,6 @@ type Response struct {
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
// Response setting gin.JSON
|
||||
func (g *Gin) Response(httpCode, errCode int, data interface{}) {
|
||||
g.C.JSON(httpCode, Response{
|
||||
Code: errCode,
|
||||
Msg: e.GetMsg(errCode),
|
||||
Data: data,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (g *Gin) CResponse(errCode int, Msg string, data interface{}) {
|
||||
g.C.JSON(http.StatusOK, Response{
|
||||
Code: errCode,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package constant
|
||||
|
||||
var CleanLogsTaskId = "00000000-0000-0000-0000-000000000001"
|
||||
var SiteSettingSectionName = "site_config"
|
||||
const CleanLogsTaskId = "00000000-0000-0000-0000-000000000001"
|
||||
const SiteSettingSectionName = "site_config"
|
||||
|
||||
//var SiteSettingTitleKeyName = "title"
|
||||
//var SiteSettingSloganKeyName = "slogan"
|
||||
//var SiteSettingLogoKeyName = "logo"
|
||||
//const SiteSettingTitleKeyName = "title"
|
||||
//const SiteSettingSloganKeyName = "slogan"
|
||||
//const SiteSettingLogoKeyName = "logo"
|
||||
|
||||
// 站点信息默认值
|
||||
var SiteSiteDefaultValueMap = map[string]string{
|
||||
@@ -15,9 +15,9 @@ var SiteSiteDefaultValueMap = map[string]string{
|
||||
}
|
||||
|
||||
// 日志清理自定义
|
||||
var LogsCleanSectionName = "log_config"
|
||||
var LogsCleanCronKeyName = "cron"
|
||||
var LogsCleanKeepKeyName = "keep_num"
|
||||
const LogsCleanSectionName = "log_config"
|
||||
const LogsCleanCronKeyName = "cron"
|
||||
const LogsCleanKeepKeyName = "keep_num"
|
||||
|
||||
// 日志清理默认值
|
||||
var LogsCleanDefaultValueMap = map[string]string{
|
||||
@@ -25,4 +25,4 @@ var LogsCleanDefaultValueMap = map[string]string{
|
||||
"keep_num": "1000",
|
||||
}
|
||||
|
||||
var AboutSectionName = "about"
|
||||
const AboutSectionName = "about"
|
||||
|
||||
@@ -2,8 +2,6 @@ package constant
|
||||
|
||||
var LatestVersion = map[string]string{}
|
||||
|
||||
//var info map[string]string
|
||||
|
||||
var V1Version = "v1.0.0"
|
||||
var V1VersionDesc = `1. 支持邮件消息发送
|
||||
2. 支持日志定时删除
|
||||
|
||||
@@ -5,34 +5,9 @@ const (
|
||||
ERROR = 500
|
||||
INVALID_PARAMS = 400
|
||||
|
||||
ERROR_EXIST_TAG = 10001
|
||||
ERROR_EXIST_TAG_FAIL = 10002
|
||||
ERROR_NOT_EXIST_TAG = 10003
|
||||
ERROR_GET_TAGS_FAIL = 10004
|
||||
ERROR_COUNT_TAG_FAIL = 10005
|
||||
ERROR_ADD_TAG_FAIL = 10006
|
||||
ERROR_EDIT_TAG_FAIL = 10007
|
||||
ERROR_DELETE_TAG_FAIL = 10008
|
||||
ERROR_EXPORT_TAG_FAIL = 10009
|
||||
ERROR_IMPORT_TAG_FAIL = 10010
|
||||
|
||||
ERROR_NOT_EXIST_ARTICLE = 10011
|
||||
ERROR_CHECK_EXIST_ARTICLE_FAIL = 10012
|
||||
ERROR_ADD_ARTICLE_FAIL = 10013
|
||||
ERROR_DELETE_ARTICLE_FAIL = 10014
|
||||
ERROR_EDIT_ARTICLE_FAIL = 10015
|
||||
ERROR_COUNT_ARTICLE_FAIL = 10016
|
||||
ERROR_GET_ARTICLES_FAIL = 10017
|
||||
ERROR_GET_ARTICLE_FAIL = 10018
|
||||
ERROR_GEN_ARTICLE_POSTER_FAIL = 10019
|
||||
|
||||
ERROR_AUTH_CHECK_TOKEN_FAIL = 20001
|
||||
ERROR_AUTH_CHECK_TOKEN_TIMEOUT = 20002
|
||||
ERROR_AUTH_TOKEN = 20003
|
||||
ERROR_AUTH = 20004
|
||||
ERROR_AUTH_NO_TOKEN = 20005
|
||||
|
||||
ERROR_UPLOAD_SAVE_IMAGE_FAIL = 30001
|
||||
ERROR_UPLOAD_CHECK_IMAGE_FAIL = 30002
|
||||
ERROR_UPLOAD_CHECK_IMAGE_FORMAT = 30003
|
||||
)
|
||||
|
||||
+8
-30
@@ -1,36 +1,14 @@
|
||||
package e
|
||||
|
||||
var MsgFlags = map[int]string{
|
||||
SUCCESS: "ok",
|
||||
ERROR: "fail",
|
||||
INVALID_PARAMS: "请求参数错误",
|
||||
ERROR_EXIST_TAG: "已存在该标签名称",
|
||||
ERROR_EXIST_TAG_FAIL: "获取已存在标签失败",
|
||||
ERROR_NOT_EXIST_TAG: "该标签不存在",
|
||||
ERROR_GET_TAGS_FAIL: "获取所有标签失败",
|
||||
ERROR_COUNT_TAG_FAIL: "统计标签失败",
|
||||
ERROR_ADD_TAG_FAIL: "新增标签失败",
|
||||
ERROR_EDIT_TAG_FAIL: "修改标签失败",
|
||||
ERROR_DELETE_TAG_FAIL: "删除标签失败",
|
||||
ERROR_EXPORT_TAG_FAIL: "导出标签失败",
|
||||
ERROR_IMPORT_TAG_FAIL: "导入标签失败",
|
||||
ERROR_NOT_EXIST_ARTICLE: "该文章不存在",
|
||||
ERROR_ADD_ARTICLE_FAIL: "新增文章失败",
|
||||
ERROR_DELETE_ARTICLE_FAIL: "删除文章失败",
|
||||
ERROR_CHECK_EXIST_ARTICLE_FAIL: "检查文章是否存在失败",
|
||||
ERROR_EDIT_ARTICLE_FAIL: "修改文章失败",
|
||||
ERROR_COUNT_ARTICLE_FAIL: "统计文章失败",
|
||||
ERROR_GET_ARTICLES_FAIL: "获取多个文章失败",
|
||||
ERROR_GET_ARTICLE_FAIL: "获取单个文章失败",
|
||||
ERROR_GEN_ARTICLE_POSTER_FAIL: "生成文章海报失败",
|
||||
ERROR_AUTH_CHECK_TOKEN_FAIL: "Token鉴权失败",
|
||||
ERROR_AUTH_CHECK_TOKEN_TIMEOUT: "Token已超时",
|
||||
ERROR_AUTH_TOKEN: "Token生成失败",
|
||||
ERROR_AUTH_NO_TOKEN: "Token缺失",
|
||||
ERROR_AUTH: "Token错误",
|
||||
ERROR_UPLOAD_SAVE_IMAGE_FAIL: "保存图片失败",
|
||||
ERROR_UPLOAD_CHECK_IMAGE_FAIL: "检查图片失败",
|
||||
ERROR_UPLOAD_CHECK_IMAGE_FORMAT: "校验图片错误,图片格式或大小有问题",
|
||||
SUCCESS: "ok",
|
||||
ERROR: "fail",
|
||||
INVALID_PARAMS: "请求参数错误",
|
||||
ERROR_AUTH_CHECK_TOKEN_FAIL: "Token鉴权失败",
|
||||
ERROR_AUTH_CHECK_TOKEN_TIMEOUT: "Token已超时",
|
||||
ERROR_AUTH_TOKEN: "Token生成失败",
|
||||
ERROR_AUTH_NO_TOKEN: "Token缺失",
|
||||
ERROR_AUTH: "Token错误",
|
||||
}
|
||||
|
||||
// GetMsg get error information based on Code
|
||||
|
||||
@@ -9,26 +9,9 @@ import (
|
||||
|
||||
type App struct {
|
||||
JwtSecret string
|
||||
PageSize int
|
||||
PrefixUrl string
|
||||
|
||||
RuntimeRootPath string
|
||||
|
||||
ImageSavePath string
|
||||
ImageMaxSize int
|
||||
ImageAllowExts []string
|
||||
|
||||
ExportSavePath string
|
||||
QrCodeSavePath string
|
||||
FontSavePath string
|
||||
|
||||
LogSavePath string
|
||||
LogSaveName string
|
||||
LogFileExt string
|
||||
TimeFormat string
|
||||
|
||||
//LogKeepNum int
|
||||
//CleanTaskLogID string
|
||||
}
|
||||
|
||||
var AppSetting = &App{}
|
||||
@@ -53,16 +36,6 @@ type Database struct {
|
||||
|
||||
var DatabaseSetting = &Database{}
|
||||
|
||||
type Redis struct {
|
||||
Host string
|
||||
Password string
|
||||
MaxIdle int
|
||||
MaxActive int
|
||||
IdleTimeout time.Duration
|
||||
}
|
||||
|
||||
var RedisSetting = &Redis{}
|
||||
|
||||
var cfg *ini.File
|
||||
|
||||
// Setup initialize the configuration instance
|
||||
@@ -76,16 +49,9 @@ func Setup() {
|
||||
mapTo("app", AppSetting)
|
||||
mapTo("server", ServerSetting)
|
||||
mapTo("database", DatabaseSetting)
|
||||
mapTo("redis", RedisSetting)
|
||||
|
||||
AppSetting.ImageMaxSize = AppSetting.ImageMaxSize * 1024 * 1024
|
||||
ServerSetting.ReadTimeout = ServerSetting.ReadTimeout * time.Second
|
||||
ServerSetting.WriteTimeout = ServerSetting.WriteTimeout * time.Second
|
||||
RedisSetting.IdleTimeout = RedisSetting.IdleTimeout * time.Second
|
||||
|
||||
//// 默认值
|
||||
//AppSetting.LogKeepNum = 1000
|
||||
//AppSetting.CleanTaskLogID = "00000000-0000-0000-0000-000000000001"
|
||||
}
|
||||
|
||||
// mapTo map section
|
||||
|
||||
@@ -3,21 +3,8 @@ package util
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/unknwon/com"
|
||||
|
||||
"message-nest/pkg/setting"
|
||||
)
|
||||
|
||||
// GetPage get page parameters
|
||||
func GetPage(c *gin.Context) int {
|
||||
result := 0
|
||||
page := com.StrTo(c.Query("page")).MustInt()
|
||||
if page > 0 {
|
||||
result = (page - 1) * setting.AppSetting.PageSize
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func GetPageSize(c *gin.Context) (int, int) {
|
||||
result := 0
|
||||
page := com.StrTo(c.Query("page")).MustInt()
|
||||
|
||||
Reference in New Issue
Block a user