Skip to content

Commit

Permalink
refactor: adjust new goctls
Browse files Browse the repository at this point in the history
feat: casbin support
  • Loading branch information
suyuan32 committed Oct 30, 2022
1 parent 0ffb0c1 commit 284eb33
Show file tree
Hide file tree
Showing 27 changed files with 455 additions and 368 deletions.
63 changes: 3 additions & 60 deletions api/api_desc/file.api
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
syntax = "v1"

info(
title: "uploader api management"
desc: "uploader api management"
title: "file management"
desc: "file management"
author: "Ryan SU"
email: "[email protected]"
version: "v1.0"
Expand Down Expand Up @@ -115,96 +115,39 @@ type (
)

service file {
// swagger:route GET /init/database file initDatabase
// Initialize database | 初始化数据库
// Responses:
// 200: SimpleMsg
// 500: SimpleMsg
@handler initDatabaseHandler
get /init/database returns (SimpleMsg)
}

@server(
jwt : Auth
group: file
middleware: Authority
)

service file {
// swagger:route POST /upload file upload
// Upload file | 上传文件
// Responses:
// 200: UploadResp
// 401: SimpleMsg
// 500: SimpleMsg
@handler upload
post /upload returns (UploadResp)

// swagger:route POST /file/list file fileList
// Get file list | 获取文件列表
// Parameters:
// + name: body
// require: true
// in: body
// type: FileListReq
// Responses:
// 200: FileListResp
// 401: SimpleMsg
// 500: SimpleMsg
@handler fileList
post /file/list (FileListReq) returns (FileListResp)

// swagger:route POST /file/list file updateFile
// Update file information | 更新文件信息
// Parameters:
// + name: body
// require: true
// in: body
// type: UpdateFileReq
// Responses:
// 200: SimpleMsg
// 401: SimpleMsg
// 500: SimpleMsg
@handler updateFile
post /file (UpdateFileReq) returns (SimpleMsg)

// swagger:route DELETE /file file deleteFile
// Delete file information | 删除文件信息
// Parameters:
// + name: body
// require: true
// in: body
// type: IDReq
// Responses:
// 200: SimpleMsg
// 401: SimpleMsg
// 500: SimpleMsg
@handler deleteFile
delete /file (IDReq) returns (SimpleMsg)

// swagger:route POST /file/status file changePublicStatus
// Change file public status | 改变文件公开状态
// Parameters:
// + name: body
// require: true
// in: body
// type: ChangeStatusReq
// Responses:
// 200: SimpleMsg
// 401: SimpleMsg
// 500: SimpleMsg
@handler changePublicStatus
post /file/status (ChangeStatusReq) returns (SimpleMsg)

// swagger:route GET /file/download/{id} file downloadFile
// Download file | 下载文件
// Parameters:
// + name: id
// require: true
// in: path
// Responses:
// 200: SimpleMsg
// 401: SimpleMsg
// 500: SimpleMsg
@handler downloadFile
get /file/download/:id (IDPathReq)
}
1 change: 1 addition & 0 deletions api/api_desc/gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
goctls api go -api file.api -dir ..
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@ import (
"github.com/zeromicro/go-zero/rest/httpx"
)

// swagger:route POST /file/status file changePublicStatus
// swagger:route post /file/status file ChangePublicStatus
//
// Change file public status | 改变文件公开状态
//
// Change file public status | 改变文件公开状态
//
// Parameters:
// + name: body
// require: true
// in: body
// type: ChangeStatusReq
//
// Responses:
// 200: SimpleMsg
// 401: SimpleMsg
// 500: SimpleMsg
// 200: SimpleMsg
// 401: SimpleMsg
// 500: SimpleMsg

func ChangePublicStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@ import (
"github.com/zeromicro/go-zero/rest/httpx"
)

// swagger:route DELETE /file file deleteFile
// swagger:route delete /file file DeleteFile
//
// Delete file information | 删除文件信息
//
// Delete file information | 删除文件信息
//
// Parameters:
// + name: body
// require: true
// in: body
// type: IDReq
//
// Responses:
// 200: SimpleMsg
// 401: SimpleMsg
// 500: SimpleMsg
// 200: SimpleMsg
// 401: SimpleMsg
// 500: SimpleMsg

func DeleteFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ import (
"net/http"
"os"

"github.com/zeromicro/go-zero/core/errorx"
"github.com/zeromicro/go-zero/rest/httpx"

"github.com/suyuan32/simple-admin-file/api/internal/logic/file"
"github.com/suyuan32/simple-admin-file/api/internal/svc"
"github.com/suyuan32/simple-admin-file/api/internal/types"

"github.com/zeromicro/go-zero/core/errorx"
"github.com/zeromicro/go-zero/rest/httpx"
)

// swagger:route GET /file/download/{id} file downloadFile
// swagger:route get /file/download/{id} file DownloadFile
//
// Download file | 下载文件
//
// Download file | 下载文件
//
// Parameters:
// + name: id
// require: true
// in: path
// Responses:
// 200: SimpleMsg
// 401: SimpleMsg
// 500: SimpleMsg
//

func DownloadFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
Expand Down
16 changes: 11 additions & 5 deletions api/internal/handler/file/filelisthandler.go → ...nternal/handler/file/file_list_handler.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@ package file
import (
"net/http"

"github.com/zeromicro/go-zero/rest/httpx"

"github.com/suyuan32/simple-admin-file/api/internal/logic/file"
"github.com/suyuan32/simple-admin-file/api/internal/svc"
"github.com/suyuan32/simple-admin-file/api/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)

// swagger:route POST /file/list file fileList
// swagger:route post /file/list file FileList
//
// Get file list | 获取文件列表
//
// Get file list | 获取文件列表
//
// Parameters:
// + name: body
// require: true
// in: body
// type: FileListReq
//
// Responses:
// 200: FileListResp
// 401: SimpleMsg
// 500: SimpleMsg
// 200: FileListResp
// 401: SimpleMsg
// 500: SimpleMsg

func FileListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ import (
"github.com/zeromicro/go-zero/rest/httpx"
)

// swagger:route GET /init/database file initDatabase
// swagger:route get /init/database file InitDatabase
//
// Initialize database | 初始化数据库
//
// Initialize database | 初始化数据库
//
// Responses:
// 200: SimpleMsg
// 500: SimpleMsg
// 200: SimpleMsg
// 401: SimpleMsg
// 500: SimpleMsg

func InitDatabaseHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@ import (
"github.com/zeromicro/go-zero/rest/httpx"
)

// swagger:route POST /file/list file updateFile
// swagger:route post /file file UpdateFile
//
// Update file information | 更新文件信息
//
// Update file information | 更新文件信息
//
// Parameters:
// + name: body
// require: true
// in: body
// type: UpdateFileReq
//
// Responses:
// 200: SimpleMsg
// 401: SimpleMsg
// 500: SimpleMsg
// 200: SimpleMsg
// 401: SimpleMsg
// 500: SimpleMsg

func UpdateFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
Expand Down
15 changes: 10 additions & 5 deletions api/internal/handler/file/uploadhandler.go → api/internal/handler/file/upload_handler.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ package file
import (
"net/http"

"github.com/zeromicro/go-zero/rest/httpx"

"github.com/suyuan32/simple-admin-file/api/internal/logic/file"
"github.com/suyuan32/simple-admin-file/api/internal/svc"
"github.com/zeromicro/go-zero/rest/httpx"
)

// swagger:route POST /upload file upload
// swagger:route post /upload file Upload
//
// Upload file | 上传文件
//
// Upload file | 上传文件
//
// Responses:
// 200: UploadResp
// 401: SimpleMsg
// 500: SimpleMsg
// 200: UploadResp
// 401: SimpleMsg
// 500: SimpleMsg

func UploadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
Expand Down
67 changes: 35 additions & 32 deletions api/internal/handler/routes.go
100755 → 100644

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 284eb33

Please sign in to comment.