@@ -12,7 +12,7 @@ import (
1212 "github.com/IceWhaleTech/CasaOS-LocalStorage/common"
1313 model1 "github.com/IceWhaleTech/CasaOS-LocalStorage/model"
1414 "github.com/IceWhaleTech/CasaOS-LocalStorage/service"
15- "github.com/gin-gonic/gin "
15+ "github.com/labstack/echo/v4 "
1616 "github.com/shirou/gopsutil/v3/disk"
1717 "go.uber.org/zap"
1818)
@@ -36,14 +36,13 @@ type StorageMessage struct {
3636// @Security ApiKeyAuth
3737// @Success 200 {string} string "ok"
3838// @Router /disk/list [get]
39- func GetDiskList (c * gin .Context ) {
39+ func GetDiskList (ctx echo .Context ) error {
4040 blkList := service .MyService .Disk ().LSBLK (false )
4141
4242 dbList , err := service .MyService .Disk ().GetSerialAllFromDB ()
4343 if err != nil {
4444 logger .Error ("error when getting all volumes from database" , zap .Error (err ))
45- c .JSON (http .StatusInternalServerError , model.Result {Success : common_err .SERVICE_ERROR , Message : err .Error ()})
46- return
45+ return ctx .JSON (http .StatusInternalServerError , model.Result {Success : common_err .SERVICE_ERROR , Message : err .Error ()})
4746 }
4847
4948 part := make (map [string ]int64 , len (dbList ))
@@ -153,7 +152,7 @@ func GetDiskList(c *gin.Context) {
153152 "avail" : avail ,
154153 }
155154
156- c .JSON (common_err .SUCCESS , model.Result {Success : common_err .SUCCESS , Message : common_err .GetMsg (common_err .SUCCESS ), Data : data })
155+ return ctx .JSON (common_err .SUCCESS , model.Result {Success : common_err .SUCCESS , Message : common_err .GetMsg (common_err .SUCCESS ), Data : data })
157156}
158157
159158// @Summary disk list
@@ -164,29 +163,26 @@ func GetDiskList(c *gin.Context) {
164163// @Success 200 {string} string "ok"
165164// @Router /disk/list [get]
166165
167- func DeleteDisksUmount (c * gin .Context ) {
166+ func DeleteDisksUmount (ctx echo .Context ) error {
168167 js := make (map [string ]string )
169- if err := c .ShouldBind (& js ); err != nil {
170- c .JSON (http .StatusBadRequest , model.Result {Success : common_err .INVALID_PARAMS , Message : common_err .GetMsg (common_err .INVALID_PARAMS ), Data : err .Error ()})
171- return
168+ if err := ctx .Bind (& js ); err != nil {
169+ return ctx .JSON (http .StatusBadRequest , model.Result {Success : common_err .INVALID_PARAMS , Message : common_err .GetMsg (common_err .INVALID_PARAMS ), Data : err .Error ()})
172170 }
173171
174172 // requires password from user to confirm the action
175173 // if claims, err := jwt.ParseToken(c.GetHeader("Authorization"), false); err != nil || encryption.GetMD5ByStr(js["password"]) != claims.Password {
176- // c .JSON(http.StatusUnauthorized, model.Result{Success: common_err.PWD_INVALID, Message: common_err.GetMsg(common_err.PWD_INVALID)})
174+ // return ctx .JSON(http.StatusUnauthorized, model.Result{Success: common_err.PWD_INVALID, Message: common_err.GetMsg(common_err.PWD_INVALID)})
177175 // return
178176 // }
179177
180178 path := js ["path" ]
181179
182180 if len (path ) == 0 {
183- c .JSON (common_err .CLIENT_ERROR , model.Result {Success : common_err .INVALID_PARAMS , Message : common_err .GetMsg (common_err .INVALID_PARAMS )})
184- return
181+ return ctx .JSON (common_err .CLIENT_ERROR , model.Result {Success : common_err .INVALID_PARAMS , Message : common_err .GetMsg (common_err .INVALID_PARAMS )})
185182 }
186183
187184 if _ , ok := diskMap [path ]; ok {
188- c .JSON (common_err .SERVICE_ERROR , model.Result {Success : common_err .DISK_BUSYING , Message : common_err .GetMsg (common_err .DISK_BUSYING )})
189- return
185+ return ctx .JSON (common_err .SERVICE_ERROR , model.Result {Success : common_err .DISK_BUSYING , Message : common_err .GetMsg (common_err .DISK_BUSYING )})
190186 }
191187
192188 diskInfo := service .MyService .Disk ().GetDiskInfo (path )
@@ -197,8 +193,7 @@ func DeleteDisksUmount(c *gin.Context) {
197193 }
198194 for _ , v := range diskInfo .Children {
199195 if err := service .MyService .Disk ().UmountPointAndRemoveDir (v ); err != nil {
200- c .JSON (http .StatusInternalServerError , model.Result {Success : common_err .REMOVE_MOUNT_POINT_ERROR , Message : err .Error ()})
201- return
196+ return ctx .JSON (http .StatusInternalServerError , model.Result {Success : common_err .REMOVE_MOUNT_POINT_ERROR , Message : err .Error ()})
202197 }
203198
204199 // delete data
@@ -230,23 +225,22 @@ func DeleteDisksUmount(c *gin.Context) {
230225 }
231226 }()
232227
233- c .JSON (common_err .SUCCESS , model.Result {Success : common_err .SUCCESS , Message : common_err .GetMsg (common_err .SUCCESS ), Data : path })
228+ return ctx .JSON (common_err .SUCCESS , model.Result {Success : common_err .SUCCESS , Message : common_err .GetMsg (common_err .SUCCESS ), Data : path })
234229}
235- func GetDiskSize (c * gin.Context ) {
236- path := c .Query ("path" )
230+
231+ func GetDiskSize (ctx echo.Context ) error {
232+ path := ctx .QueryParam ("path" )
237233 if len (path ) == 0 {
238- c .JSON (common_err .CLIENT_ERROR , model.Result {Success : common_err .INVALID_PARAMS , Message : common_err .GetMsg (common_err .INVALID_PARAMS )})
239- return
234+ return ctx .JSON (common_err .CLIENT_ERROR , model.Result {Success : common_err .INVALID_PARAMS , Message : common_err .GetMsg (common_err .INVALID_PARAMS )})
240235 }
241236 p , err := disk .Usage (path )
242237 if err != nil {
243- c .JSON (common_err .SERVICE_ERROR , model.Result {Success : common_err .SERVICE_ERROR , Message : err .Error ()})
244- return
238+ return ctx .JSON (common_err .SERVICE_ERROR , model.Result {Success : common_err .SERVICE_ERROR , Message : err .Error ()})
245239 }
246240 data := map [string ]interface {}{
247241 "path" : path ,
248242 "free" : p .Free ,
249243 "used" : p .Used ,
250244 }
251- c .JSON (common_err .SUCCESS , model.Result {Success : common_err .SUCCESS , Message : common_err .GetMsg (common_err .SUCCESS ), Data : data })
245+ return ctx .JSON (common_err .SUCCESS , model.Result {Success : common_err .SUCCESS , Message : common_err .GetMsg (common_err .SUCCESS ), Data : data })
252246}
0 commit comments