diff options
| author | Bobby <[email protected]> | 2026-02-24 12:16:54 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-02-24 12:16:54 +0530 |
| commit | ae6a52c89a7bb637ce1efe9025bf020e70c12712 (patch) | |
| tree | 9be0091b6f4fa4de478e47a67fb41f312970de29 /utils | |
| parent | cd9184421327da59c00d0766452e6082055947f2 (diff) | |
| download | metachan-ae6a52c89a7bb637ce1efe9025bf020e70c12712.tar.xz metachan-ae6a52c89a7bb637ce1efe9025bf020e70c12712.zip | |
Refactor entities and repositories: update JSON tags, add season number, and implement related anime fetching logic
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/concurrency/fetch.go | 12 | ||||
| -rw-r--r-- | utils/concurrency/types.go | 11 | ||||
| -rw-r--r-- | utils/ratelimit/limiter.go | 14 | ||||
| -rw-r--r-- | utils/ratelimit/types.go | 19 | ||||
| -rw-r--r-- | utils/shortcuts/response.go | 6 | ||||
| -rw-r--r-- | utils/shortcuts/types.go | 9 |
6 files changed, 39 insertions, 32 deletions
diff --git a/utils/concurrency/fetch.go b/utils/concurrency/fetch.go index f2e827f..c94069d 100644 --- a/utils/concurrency/fetch.go +++ b/utils/concurrency/fetch.go @@ -4,12 +4,6 @@ import ( "sync" ) -// ParallelResult represents a result or error from a parallel computation -type ParallelResult[T any] struct { - Value T - Error error -} - // Parallel executes multiple functions concurrently and returns their results // This is a powerful utility that allows us to fetch data from multiple APIs in parallel func Parallel[T any](funcs ...func() (T, error)) []ParallelResult[T] { @@ -32,12 +26,6 @@ func Parallel[T any](funcs ...func() (T, error)) []ParallelResult[T] { return results } -// ParallelMapResult represents a result from a map operation that may contain an error -type ParallelMapResult[T any] struct { - Value T - Error error -} - // ParallelMap applies a function to each item in a slice concurrently // This is useful for operations like fetching skip times for multiple episodes at once func ParallelMap[T any, R any](items []T, f func(T) (R, error)) []ParallelMapResult[R] { diff --git a/utils/concurrency/types.go b/utils/concurrency/types.go new file mode 100644 index 0000000..d0a6ab1 --- /dev/null +++ b/utils/concurrency/types.go @@ -0,0 +1,11 @@ +package concurrency + +type ParallelResult[T any] struct { + Value T + Error error +} + +type ParallelMapResult[T any] struct { + Value T + Error error +} diff --git a/utils/ratelimit/limiter.go b/utils/ratelimit/limiter.go index ecbcc56..6450c8b 100644 --- a/utils/ratelimit/limiter.go +++ b/utils/ratelimit/limiter.go @@ -1,19 +1,9 @@ package ratelimit import ( - "sync" "time" ) -type RateLimiter struct { - mu sync.Mutex - lastRequest time.Time - lastRequests []time.Time - maxRequests int - window time.Duration - minDelay time.Duration -} - func NewRateLimiter(maxRequests int, window time.Duration) *RateLimiter { minDelay := window / time.Duration(maxRequests) return &RateLimiter{ @@ -91,10 +81,6 @@ func (r *RateLimiter) RemainingRequests() int { return r.maxRequests - len(r.lastRequests) } -type MultiLimiter struct { - limiters []*RateLimiter -} - func NewMultiLimiter(limiters ...*RateLimiter) *MultiLimiter { return &MultiLimiter{ limiters: limiters, diff --git a/utils/ratelimit/types.go b/utils/ratelimit/types.go new file mode 100644 index 0000000..f962f22 --- /dev/null +++ b/utils/ratelimit/types.go @@ -0,0 +1,19 @@ +package ratelimit + +import ( + "sync" + "time" +) + +type RateLimiter struct { + mu sync.Mutex + lastRequest time.Time + lastRequests []time.Time + maxRequests int + window time.Duration + minDelay time.Duration +} + +type MultiLimiter struct { + limiters []*RateLimiter +} diff --git a/utils/shortcuts/response.go b/utils/shortcuts/response.go index c5a7a1c..e90f16b 100644 --- a/utils/shortcuts/response.go +++ b/utils/shortcuts/response.go @@ -2,12 +2,6 @@ package shortcuts import "github.com/gofiber/fiber/v2" -type response struct { - ctx *fiber.Ctx - data any - status int -} - func Response(ctx *fiber.Ctx, data any) *response { return &response{ ctx: ctx, diff --git a/utils/shortcuts/types.go b/utils/shortcuts/types.go new file mode 100644 index 0000000..122ad13 --- /dev/null +++ b/utils/shortcuts/types.go @@ -0,0 +1,9 @@ +package shortcuts + +import "github.com/gofiber/fiber/v2" + +type response struct { + ctx *fiber.Ctx + data any + status int +} |
