Skip to content

Commit

Permalink
🔄 Sync from monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
mojo-machine[bot] committed Jan 3, 2025
1 parent 3d3a9f7 commit 5d411bb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 34 deletions.
2 changes: 1 addition & 1 deletion lib/ab/ab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var (
)

func BenchmarkParse(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
Check(testID, userID, 5000)
}
}
1 change: 0 additions & 1 deletion lib/crpc/server_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:bodyclose // incorrect
package crpc

import (
Expand Down
2 changes: 1 addition & 1 deletion lib/ksuid/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestParse(t *testing.T) {
}

func BenchmarkParse(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
_, _ = Parse("user_000000BPG6Lks9tQoAiJYrBRSXPX6")
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ksuid/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func BenchmarkGenerate(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
Generate(context.Background(), "user")
}
}
55 changes: 27 additions & 28 deletions lib/middleware/request/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,36 +97,35 @@ func Logger(log *logrus.Entry) func(http.Handler) http.Handler {
err := getError(clog.Get(ctx))
if err == nil {
mlog.Info(ctx, merr.New(ctx, "request_completed", nil))
} else {
var fn func(context.Context, merr.Merrer)
switch clog.DetermineLevel(err, clog.TimeoutsAsErrors(ctx)) {
case
logrus.PanicLevel,
logrus.FatalLevel,
logrus.ErrorLevel:
fn = mlog.Error
case
logrus.WarnLevel:
fn = mlog.Warn
case
logrus.InfoLevel,
logrus.DebugLevel,
logrus.TraceLevel:
fn = mlog.Info
}
return
}
var fn func(context.Context, merr.Merrer)
switch clog.DetermineLevel(err, clog.TimeoutsAsErrors(ctx)) {
case
logrus.PanicLevel,
logrus.FatalLevel,
logrus.ErrorLevel:
fn = mlog.Error
case logrus.WarnLevel:
fn = mlog.Warn
case
logrus.InfoLevel,
logrus.DebugLevel,
logrus.TraceLevel:
fn = mlog.Info
}

if mErr, ok := gerrors.As[merr.E](err); ok {
fn(ctx, mErr)
} else if cErr, ok := gerrors.As[cher.E](err); ok {
reasons := slicefn.Map(cErr.Reasons, func(r cher.E) error { return r })
// If the cher error has no reasons, add the cher error itself
if len(reasons) == 0 {
reasons = append(reasons, cErr)
}
fn(ctx, merr.New(ctx, merr.Code(cErr.Code), merr.M(cErr.Meta), reasons...))
} else {
fn(ctx, merr.New(ctx, "unexpected_request_failure", nil, err))
if mErr, ok := gerrors.As[merr.E](err); ok {
fn(ctx, mErr)
} else if cErr, ok := gerrors.As[cher.E](err); ok {
reasons := slicefn.Map(cErr.Reasons, func(r cher.E) error { return r })
// If the cher error has no reasons, add the cher error itself
if len(reasons) == 0 {
reasons = append(reasons, cErr)
}
fn(ctx, merr.New(ctx, merr.Code(cErr.Code), merr.M(cErr.Meta), reasons...))
} else {
fn(ctx, merr.New(ctx, "unexpected_request_failure", nil, err))
}
})
}
Expand Down
5 changes: 3 additions & 2 deletions lib/revenuecat/revenuecat.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package revenuecat
import (
"context"
"fmt"
"maps"
"net/url"
"slices"
"time"

"github.com/samber/lo"
"github.com/wearemojo/mojo-public-go/lib/httpclient"
"github.com/wearemojo/mojo-public-go/lib/jsonclient"
"github.com/wearemojo/mojo-public-go/lib/secret"
"golang.org/x/exp/maps"
)

const baseURL = "https://api.revenuecat.com/v1"
Expand Down Expand Up @@ -92,7 +93,7 @@ func (c *Client) GetOrCreateSubscriberInfo(ctx context.Context, appUserID string
}

func (s *Subscriber) ActiveSubscriptionCount() int {
activeNonSubCount := len(lo.Flatten(maps.Values(s.NonSubscriptions))) // always active
activeNonSubCount := len(lo.Flatten(slices.Collect(maps.Values(s.NonSubscriptions)))) // always active
activeSubCount := 0
now := time.Now()

Expand Down

0 comments on commit 5d411bb

Please sign in to comment.