refactor: replace key package with ctxkey for context keys

This commit is contained in:
krau
2025-06-17 22:19:06 +08:00
parent eb6f8675a4
commit 4df2c5a06d
8 changed files with 21 additions and 21 deletions

View File

@@ -13,7 +13,7 @@ import (
"github.com/krau/SaveAny-Bot/common/utils/fsutil"
"github.com/krau/SaveAny-Bot/common/utils/ioutil"
"github.com/krau/SaveAny-Bot/config"
"github.com/krau/SaveAny-Bot/pkg/enums/key"
"github.com/krau/SaveAny-Bot/pkg/enums/ctxkey"
"golang.org/x/sync/errgroup"
)
@@ -104,7 +104,7 @@ func (t *Task) processElement(ctx context.Context, elem TaskElement) error {
if err != nil {
return fmt.Errorf("failed to get file stat: %w", err)
}
vctx := context.WithValue(ctx, key.ContextKeyContentLength, fileStat.Size())
vctx := context.WithValue(ctx, ctxkey.ContentLength, fileStat.Size())
err = retry.Retry(func() error {
var file *os.File
file, err = os.Open(elem.localPath)

View File

@@ -11,7 +11,7 @@ import (
"github.com/krau/SaveAny-Bot/common/tdler"
"github.com/krau/SaveAny-Bot/common/utils/fsutil"
"github.com/krau/SaveAny-Bot/config"
"github.com/krau/SaveAny-Bot/pkg/enums/key"
"github.com/krau/SaveAny-Bot/pkg/enums/ctxkey"
)
func (t *TGFileTask) Execute(ctx context.Context) error {
@@ -52,7 +52,7 @@ func (t *TGFileTask) Execute(ctx context.Context) error {
if err != nil {
return fmt.Errorf("failed to get file stat: %w", err)
}
vctx := context.WithValue(ctx, key.ContextKeyContentLength, fileStat.Size())
vctx := context.WithValue(ctx, ctxkey.ContentLength, fileStat.Size())
for i := range config.Cfg.Retry + 1 {
if err = vctx.Err(); err != nil {
return fmt.Errorf("context canceled while saving file: %w", err)