From 7b9c67d508b3e9b06f2bc7a43e2177d873eefcb3 Mon Sep 17 00:00:00 2001 From: Jakob Schrettenbrunner Date: Thu, 31 Aug 2017 23:57:33 +0200 Subject: [PATCH] api: improve routes --- api/routes.go | 8 -------- api/routes_server.go | 22 +++++++++++----------- api/routes_server_files.go | 24 ++++++++++++------------ 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/api/routes.go b/api/routes.go index 2ff7cda..a6451c4 100644 --- a/api/routes.go +++ b/api/routes.go @@ -1,9 +1,5 @@ package api -import ( - "github.com/gin-gonic/gin" -) - func (api *API) registerRoutes() { api.router.GET("/", AuthHandler(""), handleGetIndex) api.router.PATCH("/config", AuthHandler("c:config"), handlePatchConfig) @@ -11,7 +7,3 @@ func (api *API) registerRoutes() { api.registerServerRoutes() api.registerServerFileRoutes() } - -func handle(c *gin.Context) { - -} diff --git a/api/routes_server.go b/api/routes_server.go index fa06199..955527a 100644 --- a/api/routes_server.go +++ b/api/routes_server.go @@ -5,16 +5,16 @@ func (api *API) registerServerRoutes() { api.router.GET("/servers", AuthHandler("c:list"), handleGetServers) api.router.POST("/servers", AuthHandler("c:create"), handlePostServers) - api.router.DELETE("/server/:server", AuthHandler("g:server:delete"), handleDeleteServers) - api.router.GET("/server/:server", AuthHandler("s:get"), handleGetServer) - api.router.PATCH("/server/:server", AuthHandler("s:config"), handlePatchServer) + api.router.GET("/servers/:server", AuthHandler("s:get"), handleGetServer) + api.router.PATCH("/servers/:server", AuthHandler("s:config"), handlePatchServer) + api.router.DELETE("/servers/:server", AuthHandler("g:server:delete"), handleDeleteServer) - api.router.POST("/server/:server/reinstall", AuthHandler("s:install-server"), handlePostServerReinstall) - api.router.POST("/server/:server/rebuild", AuthHandler("g:server:rebuild"), handlePostServerRebuild) - api.router.POST("/server/:server/password", AuthHandler(""), handlePostServerPassword) - api.router.POST("/server/:server/power", AuthHandler("s:power"), handlePutServerPower) - api.router.POST("/server/:server/command", AuthHandler("s:command"), handlePostServerCommand) - api.router.GET("/server/:server/log", AuthHandler("s:console"), handleGetServerLog) - api.router.POST("/server/:server/suspend", AuthHandler(""), handlePostServerSuspend) - api.router.POST("/server/:server/unsuspend", AuthHandler(""), handlePostServerUnsuspend) + api.router.POST("/servers/:server/reinstall", AuthHandler("s:install-server"), handlePostServerReinstall) + api.router.POST("/servers/:server/rebuild", AuthHandler("g:server:rebuild"), handlePostServerRebuild) + api.router.POST("/servers/:server/password", AuthHandler(""), handlePostServerPassword) + api.router.POST("/servers/:server/power", AuthHandler("s:power"), handlePutServerPower) + api.router.POST("/servers/:server/command", AuthHandler("s:command"), handlePostServerCommand) + api.router.GET("/servers/:server/log", AuthHandler("s:console"), handleGetServerLog) + api.router.POST("/servers/:server/suspend", AuthHandler(""), handlePostServerSuspend) + api.router.POST("/servers/:server/unsuspend", AuthHandler(""), handlePostServerUnsuspend) } diff --git a/api/routes_server_files.go b/api/routes_server_files.go index f3b7b6e..747e05c 100644 --- a/api/routes_server_files.go +++ b/api/routes_server_files.go @@ -1,20 +1,20 @@ package api func (api *API) registerServerFileRoutes() { - api.router.GET("/server/:server/files/file/:file", AuthHandler("s:files:read"), handleGetFile) - api.router.GET("/server/:server/files/stat/:file", AuthHandler("s:files:"), handleGetFileStat) - api.router.GET("/server/:server/files/dir/:directory", AuthHandler("s:files:get"), handleGetDirectory) + api.router.GET("/servers/:server/files/file/:file", AuthHandler("s:files:read"), handleGetFile) + api.router.GET("/servers/:server/files/stat/:file", AuthHandler("s:files:"), handleGetFileStat) + api.router.GET("/servers/:server/files/dir/:directory", AuthHandler("s:files:get"), handleGetDirectory) - api.router.POST("/server/:server/files/dir/:directory", AuthHandler("s:files:create"), handlePostFilesFolder) - api.router.POST("/server/:server/files/file/:file", AuthHandler("s:files:post"), handlePostFile) + api.router.POST("/servers/:server/files/dir/:directory", AuthHandler("s:files:create"), handlePostFilesFolder) + api.router.POST("/servers/:server/files/file/:file", AuthHandler("s:files:post"), handlePostFile) - api.router.POST("/server/:server/files/copy/:file", AuthHandler("s:files:copy"), handlePostFileCopy) - api.router.POST("/server/:server/files/move/:file", AuthHandler("s:files:move"), handlePostFileMove) - api.router.POST("/server/:server/files/rename/:file", AuthHandler("s:files:move"), handlePostFileMove) - api.router.POST("/server/:server/files/compress/:file", AuthHandler("s:files:compress"), handlePostFileCompress) - api.router.POST("/server/:server/files/decompress/:file", AuthHandler("s:files:decompress"), handlePostFileDecompress) + api.router.POST("/servers/:server/files/copy/:file", AuthHandler("s:files:copy"), handlePostFileCopy) + api.router.POST("/servers/:server/files/move/:file", AuthHandler("s:files:move"), handlePostFileMove) + api.router.POST("/servers/:server/files/rename/:file", AuthHandler("s:files:move"), handlePostFileMove) + api.router.POST("/servers/:server/files/compress/:file", AuthHandler("s:files:compress"), handlePostFileCompress) + api.router.POST("/servers/:server/files/decompress/:file", AuthHandler("s:files:decompress"), handlePostFileDecompress) - api.router.DELETE("/server/:server/files/file/:file", AuthHandler("s:files:delete"), handleDeleteFile) + api.router.DELETE("/servers/:server/files/file/:file", AuthHandler("s:files:delete"), handleDeleteFile) - api.router.GET("/server/:server/files/download/:token", handleGetDownloadFile) + api.router.GET("/servers/:server/files/download/:token", handleGetDownloadFile) }