Skip to content

Commit

Permalink
No message for missing cost (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
klaidliadon authored Jan 16, 2025
1 parent b8e6e76 commit 7f757ff
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions middleware/middleware_cost.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
package middleware

import (
"log/slog"
"net/http"

"github.com/0xsequence/authcontrol"
)

// SetCost middleware that sets the cost of the request, and defaults to Option.BaseRequestCost.
func SetCost(cost authcontrol.Config[int64], o Options) func(next http.Handler) http.Handler {
func SetCost(cfg authcontrol.Config[int64], o Options) func(next http.Handler) http.Handler {
o.ApplyDefaults()

return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

cost, err := cost.Get(ctx, r.URL.Path)
if err != nil {
if o.Logger != nil {
o.Logger.Error("get cost", slog.Any("error", err))
}
cost = int64(o.BaseRequestCost)
cost := int64(o.BaseRequestCost)
if v, err := cfg.Get(ctx, r.URL.Path); err == nil {
cost = v
}

ctx = WithCost(ctx, cost)
Expand Down

0 comments on commit 7f757ff

Please sign in to comment.