diff --git a/common/middleware/captcha.go b/common/middleware/captcha.go index 427103c..4360196 100644 --- a/common/middleware/captcha.go +++ b/common/middleware/captcha.go @@ -13,6 +13,7 @@ import ( // @Tags 登陆 // @Success 200 {object} response.Response{data=string,id=string,msg=string} "{"code": 200, "data": [...]}" // @Router /api/v1/captcha [get] + func GenerateCaptchaHandler(c *gin.Context) { id, b64s, err := captcha.DriverDigitFunc() if err != nil { diff --git a/common/middleware/file.go b/common/middleware/file.go index 732b1ff..46d32e0 100644 --- a/common/middleware/file.go +++ b/common/middleware/file.go @@ -25,19 +25,19 @@ import ( const DownloadUrlPrefix = "/public/downloadFile/" var ( - failedInitFilePath = cerr.New(4500, "初始化路径失败", "failed to initialize upload path") - failedSavingFile = cerr.New(4501, "未能保存文件", "failed to save the uploaded file") - failedUploadToOss = cerr.New(4502, "上传OSS失败", "failed to upload to oss") - requiredFileErr = cerr.New(4503, "文件不能为空", "file cannot be empty") + failedInitFilePath = cerr.New(4500, "初始化路径失败", "failed to initialize upload path") + failedSavingFile = cerr.New(4501, "未能保存文件", "failed to save the uploaded file") + failedUploadToOss = cerr.New(4502, "上传OSS失败", "failed to upload to oss") + requiredFileErr = cerr.New(4503, "文件不能为空", "file cannot be empty") failedDownloadFromOss = cerr.New(4504, "OSS下载失败", "failed to download from oss") - failedUploadingfile = cerr.New(4505, "未能上传文件", "failed to upload") + failedUploadingfile = cerr.New(4505, "未能上传文件", "failed to upload") ) type FileResponse struct { Path string `json:"path"` FullPath string `json:"full_path"` Name string `json:"name"` - Size int64 `json:"size"` + Size int64 `json:"size"` } type File struct { @@ -55,6 +55,7 @@ type File struct { // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/public/uploadFile [post] // @Security Bearer + func (e File) UploadFile(c *gin.Context) { e.MakeContext(c) @@ -100,11 +101,12 @@ func (e File) UploadFile(c *gin.Context) { // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /public/downloadFile/{pathname}/{filename} [get] // @Security Bearer + func (e File) DownloadFile(c *gin.Context) { var req struct { Pathname string `uri:"pathname"` Filename string `uri:"filename"` - As string `form:"as"` + As string `form:"as"` } err := e.MakeContext(c). Bind(&req, nil, binding.Query). @@ -177,7 +179,7 @@ func (e File) baseImg(c *gin.Context) (*FileResponse, error) { ddd, _ := base64.StdEncoding.DecodeString(file2list[1]) // get ext name from file2list[0] - filename := e.filename(category,"*.jpg") + filename := e.filename(category, "*.jpg") err := e.saveFile(bytes.NewReader(ddd), filename) if err != nil { return nil, err @@ -187,7 +189,7 @@ func (e File) baseImg(c *gin.Context) (*FileResponse, error) { Path: filename, FullPath: urlPrefix + filename, Name: "", - Size: int64(len(ddd)), + Size: int64(len(ddd)), } return fileResponse, nil } @@ -287,7 +289,7 @@ func (e File) ImportTempFile(c *gin.Context) (*FileResponse, error) { Path: filename, FullPath: fullname, Name: file.Filename, - Size: file.Size, + Size: file.Size, } return fileResponse, nil } @@ -316,8 +318,7 @@ func (e File) singleFile(c *gin.Context) (*FileResponse, error) { Path: filename, FullPath: urlPrefix + filename, Name: file.Filename, - Size: file.Size, - + Size: file.Size, } return fileResponse, nil } diff --git a/common/middleware/jwtauth/auth.go b/common/middleware/jwtauth/auth.go index a5bb562..fd90c49 100644 --- a/common/middleware/jwtauth/auth.go +++ b/common/middleware/jwtauth/auth.go @@ -53,6 +53,7 @@ func PayloadFunc(data interface{}) jwt.MapClaims { // @Param account body Login true "account" // @Success 200 {string} string "{"code": 200, "expire": "2019-08-07T12:45:48+08:00", "token": ".eyJleHAiOjE1NjUxNTMxNDgsImlkIjoiYWRtaW4iLCJvcmlnX2lhdCI6MTU2NTE0OTU0OH0.-zvzHvbg0A" }" // @Router /api/v1/login [post] + func Authenticator(c *gin.Context) (interface{}, error) { log := api.MustGetLogger(c) db := api.MustGetOrm(c) diff --git a/common/middleware/oss_signed_token.go b/common/middleware/oss_signed_token.go index 6e4ea88..2727071 100644 --- a/common/middleware/oss_signed_token.go +++ b/common/middleware/oss_signed_token.go @@ -10,13 +10,13 @@ import ( type PresignTokenRequest struct { Directory string `json:"directory"` - Filename string `json:"filename"` - Duration int `json:"duration"` + Filename string `json:"filename"` + Duration int `json:"duration"` } type PresignTokenResponse struct { - Vendor string `json:"vendor"` - Token interface{} `json:"token"` + Vendor string `json:"vendor"` + Token interface{} `json:"token"` } type PresignToken struct { @@ -32,6 +32,7 @@ type PresignToken struct { // @Success 200 {object} PresignTokenResponse "{"code": 200, "data": [...]}" // @Router /presign-token [post] // @Security Bearer + func (e PresignToken) PresignToken(c *gin.Context) { var req PresignTokenRequest @@ -58,9 +59,9 @@ func (e PresignToken) PresignToken(c *gin.Context) { //c.Header("Access-Control-Allow-Methods", "POST") //c.Header("Access-Control-Allow-Origin", "*") - response := PresignTokenResponse { + response := PresignTokenResponse{ Vendor: oss.Name(), - Token: token, + Token: token, } e.OK(response, "成功") } diff --git a/common/middleware/server_monitor.go b/common/middleware/server_monitor.go index b4fffd6..fdf18c9 100644 --- a/common/middleware/server_monitor.go +++ b/common/middleware/server_monitor.go @@ -23,7 +23,7 @@ const ( GB = 1024 * MB ) -//获取相差时间 +// 获取相差时间 func GetHourDiffer(startTime, endTime string) int64 { var hour int64 t1, err := time.ParseInLocation("2006-01-02 15:04:05", startTime, time.Local) @@ -44,6 +44,7 @@ func GetHourDiffer(startTime, endTime string) int64 { // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /server-monitor [get] // @Security Bearer + func ServerInfo(c *gin.Context) { sysInfo, err := host.Info() osDic := make(map[string]interface{}, 0) @@ -103,13 +104,13 @@ func ServerInfo(c *gin.Context) { appVersion = "dev" } data := map[string]interface{}{ - "requestId": utils.GenerateMsgIDFromContext(c), - "code": 200, - "os": osDic, - "mem": memDic, - "cpu": cpuDic, - "disk": diskDic, - "diskList": disklist, + "requestId": utils.GenerateMsgIDFromContext(c), + "code": 200, + "os": osDic, + "mem": memDic, + "cpu": cpuDic, + "disk": diskDic, + "diskList": disklist, "appVersion": appVersion, } c.Set("result", data)