52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
/*
|
|
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
|
*
|
|
* This work is published and licensed under a Creative Commons
|
|
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
|
*
|
|
* Distribution of this work is permitted, but commercial use and
|
|
* modifications are strictly prohibited.
|
|
*/
|
|
package filecmd
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"mstore/pkg/filecli"
|
|
)
|
|
|
|
// DeleteFile
|
|
type DeleteFileParams struct {
|
|
Filepath string
|
|
}
|
|
|
|
type DeleteFileResult struct{}
|
|
|
|
func (util *FileUtil) DeleteFile(cmd *cobra.Command, args []string) {
|
|
util.deleteFileParams.Filepath = args[0]
|
|
res, err := util.deleteFile(&util.commonFileParams, &util.deleteFileParams)
|
|
printResponse(res, err)
|
|
}
|
|
func (util *FileUtil) deleteFile(common *CommonFileParams, params *DeleteFileParams) (*DeleteFileResult, error) {
|
|
var err error
|
|
res := &DeleteFileResult{}
|
|
ref, err := filecli.ParsePath(params.Filepath)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
timeout := time.Duration(common.Timeout) * time.Second
|
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
|
ref.SetUserinfo(common.Username, common.Password)
|
|
|
|
mw := filecli.NewBasicAuthMiddleware(ref.Userinfo())
|
|
cli := filecli.NewClient(nil, mw)
|
|
_, err = cli.DeleteFile(ctx, ref.Raw())
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
return res, err
|
|
}
|