minor rework and filter dimensions

This commit is contained in:
Aleksandr Trushkin
2024-02-13 21:19:39 +03:00
parent f4bff6fe01
commit 3c3b4e4670
13 changed files with 969 additions and 780 deletions

View File

@ -0,0 +1,55 @@
package commands
import (
"context"
"crypto/rand"
"encoding/hex"
"fmt"
"time"
"git.loyso.art/frx/eway/cmd/cli/components"
"git.loyso.art/frx/eway/internal/entity"
"github.com/urfave/cli/v3"
)
type empty entity.Empty
type action func(ctx context.Context, c *cli.Command) error
func decorateAction(a action) cli.ActionFunc {
return func(ctx context.Context, c *cli.Command) error {
var data [3]byte
_, _ = rand.Read(data[:])
reqid := hex.EncodeToString(data[:])
log, err := components.GetLogger()
if err != nil {
return fmt.Errorf("getting logger: %w", err)
}
log = log.With().Str("reqid", reqid).Logger()
rctx := log.WithContext(ctx)
start := time.Now()
defer func() {
log.Info().Float64("elapsed", time.Since(start).Seconds()).Msg("command completed")
}()
log.Info().Msg("command execution started")
return a(rctx, c)
}
}
func cmdWithAction(cmd cli.Command, a action) *cli.Command {
if a == nil {
a = notImplementedAction
}
cmd.Action = decorateAction(a)
return &cmd
}
func notImplementedAction(_ context.Context, _ *cli.Command) error {
return entity.ErrNotImplemented
}