Skip to content

Commit

Permalink
fix(middleware): cmd argument in MiddlewareFunc set as pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
mj committed Jun 17, 2024
1 parent 5a3784f commit 1a33000
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/engine/command/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/pagu-project/Pagu/pkg/wallet"
)

type MiddlewareFunc func(cmd Command, appID entity.AppID, callerID string, args ...string) error
type MiddlewareFunc func(cmd *Command, appID entity.AppID, callerID string, args ...string) error

type MiddlewareHandler struct {
db *repository.DB
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/command/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/pagu-project/Pagu/internal/entity"
)

func (h *MiddlewareHandler) CreateUser(cmd Command, appID entity.AppID, callerID string, _ ...string) error {
func (h *MiddlewareHandler) CreateUser(cmd *Command, appID entity.AppID, callerID string, _ ...string) error {
if !h.db.HasUserInApp(appID, callerID) {
user := &entity.User{ApplicationID: appID, CallerID: callerID}
if err := h.db.AddUser(user); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/command/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/pagu-project/Pagu/internal/entity"
)

func (h *MiddlewareHandler) WalletBalance(_ Command, _ entity.AppID, _ string, _ ...string) error {
func (h *MiddlewareHandler) WalletBalance(_ *Command, _ entity.AppID, _ string, _ ...string) error {
if h.wallet.Balance() < 5 {
return errors.New("empty pagu phoenix wallet")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (be *BotEngine) Run(appID entity.AppID, callerID string, tokens []string) c
}

for _, middlewareFunc := range cmd.Middlewares {
if err = middlewareFunc(cmd, appID, callerID, args...); err != nil {
if err = middlewareFunc(&cmd, appID, callerID, args...); err != nil {
log.Error(err.Error())
return cmd.ErrorResult(errors.New("command is not available. please try again later"))
}
Expand Down

0 comments on commit 1a33000

Please sign in to comment.