2 Commits
32 changed files with 1544 additions and 0 deletions

No files matched your search

+77
View File
@@ -0,0 +1,77 @@
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
/.idea/
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
*.iml
convert_service
convert-service
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
cmake-build-release/
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Go template
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
/node_modules/
/vendor/
google/
package.json
yarn.lock
conf/config_dev.yml
/http-client.private.env.json
+53
View File
@@ -0,0 +1,53 @@
run:
allow-parallel-runners: true
issues:
exclude-rules:
- path: controller #достаточное кол-во контекса на уровне контроллеров
linters:
- wrapcheck
- path: transaction #транзакции прозрачны
linters:
- wrapcheck
linters:
enable-all: true
disable:
- goimports #у нас собственные правила форматирования импортов
- wsl #расставление пробелов очень индивидуально
- varnamelen #очень индивидуально (db)
- exhaustruct #не имеет смысла
- contextcheck #не имеет смысла
- gci #у нас собственные правила форматирования импортов
- gofumpt #у нас собственные правила форматирования импортов
- nolintlint #Goland все равно форматирует с отступом
- nlreturn #не всегда имеет смысл
- godot #не актуально для свагера
- godox #не позволяет оставлять todo
- depguard #не всегда имеет смысл
- dupword #не имеет смысла
- tagalign #не всегда имеет смысл
- musttag #у нас собственные правило: не используем теги, если работаем с пакетом isp-kit/json и с внутренними структурами(между нашими сервисами), при этом теги обязательный для всех внених для нас структур
- perfsprint #мнимая производительность в угоду читаемости
- gomnd #устарел
- exportloopref #устарел
- execinquery #устарел
linters-settings:
funlen:
lines: 80
lll:
line-length: 150
cyclop:
max-complexity: 15 #по умолчанию 10 мало
revive:
rules:
- name: var-naming #отключаем Id -> ID
disabled: true
stylecheck:
checks: #отключаем Id -> ID
- "-ST1000"
- "-ST1016"
- "-ST1020"
- "-ST1021"
- "-ST1022"
testifylint:
disable:
- compares
+1
View File
@@ -0,0 +1 @@
1.3.0
+15
View File
@@ -0,0 +1,15 @@
# v1.3.0
* добавлены методы `/daily_limit/increment` и `/daily_limit/set`
* удалена неиспользуемая структура `domain.GrpcError`
* обновлены зависимости
# v1.2.0
* добавлен метод `/rate_limit`
* обновлены зависимости
# v1.1.0
* обновлены зависимости
# v1.0.2
* обновлены зависимости
# v1.0.1
* убрано избыточное логгирование
# v1.0.0
* первая версия
+67
View File
@@ -0,0 +1,67 @@
# Сервис распределенной блокировки
Общая идея состоит в том, чтобы реализовать поведение sync.Mutex на основе http вызова и через redis. Для этого используется библиотека [redsync](github.com/go-redsync/redsync).
## Вызовы
Модуль имеет два вызова
### Блокировка
- isp-lock-service/lock
- входящий запрос
- key - строка, описывающая, что мы блокируем. ОБЯЗАТЕЛЬНОЕ
- ttlInSec - число секунд после которых блокировка снимется автоматически. Если не передано, то будет использовано значение из конфига (.redis.defaultTimeOut). . ОБЯЗАТЕЛЬНОЕ
- ответ
- lockKey - строка. ключ для разблокировки, чтобы тот, кто не ставил блокировку не мог ее снять
### Пример вызова
```
POST {{proto}}://{{address}}/api/isp-lock-service/lock
Content-Type: application/json
X-Application-Token: {{token}}
{
"key": "abc",
"ttlInSec": 20
}
```
### Пример ответа
```
{
"lockKey": "Km1wmwaP3eKzqLbuEd46lQ=="
}
```
### Разблокировка
- isp-lock-service/unlock
- входящий запрос
- key - строка, описывающая, что мы разблокируем. ОБЯЗАТЕЛЬНОЕ
- lockKey - строка, ключ для разблокировки, полученный в ответ при блокировке. ОБЯЗАТЕЛЬНОЕ
- ответ
- пустой
### Пример вызова
```
POST {{proto}}://{{address}}/api/isp-lock-service/unlock
Content-Type: application/json
X-Application-Token: {{token}}
{
"key": "abc",
"lockKey": "{{lockKey}}"
}
```
### Пример ответа
```
{
}
```
+128
View File
@@ -0,0 +1,128 @@
package assembly
import (
"context"
goredislib "github.com/redis/go-redis/v9"
"github.com/txix-open/isp-kit/observability/sentry"
"github.com/txix-open/isp-kit/rc"
"isp-lock-service/conf"
"github.com/pkg/errors"
"github.com/txix-open/isp-kit/app"
"github.com/txix-open/isp-kit/bootstrap"
"github.com/txix-open/isp-kit/cluster"
"github.com/txix-open/isp-kit/grpc"
"github.com/txix-open/isp-kit/log"
)
type Assembly struct {
boot *bootstrap.Bootstrap
server *grpc.Server
redisCli *goredislib.Client
logger *log.Adapter
}
func New(boot *bootstrap.Bootstrap) (*Assembly, error) {
server := grpc.DefaultServer()
return &Assembly{
boot: boot,
server: server,
redisCli: nil,
logger: boot.App.Logger(),
}, nil
}
func (a *Assembly) ReceiveConfig(ctx context.Context, remoteConfig []byte) error {
newCfg, _, err := rc.Upgrade[conf.Remote](a.boot.RemoteConfig, remoteConfig)
if err != nil {
a.boot.Fatal(errors.WithMessage(err, "upgrade remote config"))
}
err = a.redisClient(newCfg.Redis)
if err != nil {
a.boot.Fatal(errors.WithMessage(err, "upgrade redis client"))
}
a.logger.SetLevel(newCfg.LogLevel)
logger := sentry.WrapErrorLogger(a.logger, a.boot.SentryHub)
locator := NewLocator(logger, a.redisCli, newCfg)
handler := locator.Handler()
a.server.Upgrade(handler)
return nil
}
func (a *Assembly) Runners() []app.Runner {
eventHandler := cluster.NewEventHandler().
RemoteConfigReceiver(a)
return []app.Runner{
app.RunnerFunc(func(ctx context.Context) error {
err := a.server.ListenAndServe(a.boot.BindingAddress)
if err != nil {
return errors.WithMessage(err, "listen ans serve grpc server")
}
return nil
}),
app.RunnerFunc(func(ctx context.Context) error {
err := a.boot.ClusterCli.Run(ctx, eventHandler)
if err != nil {
return errors.WithMessage(err, "run cluster client")
}
return nil
}),
}
}
func (a *Assembly) Closers() []app.Closer {
return []app.Closer{
a.boot.ClusterCli,
app.CloserFunc(func() error {
a.server.Shutdown()
return nil
}),
app.CloserFunc(func() error {
_ = a.redisCli.Close()
return nil
}),
}
}
func (a *Assembly) redisClient(cfg conf.Redis) error {
var (
oldCli = a.redisCli
newCli *goredislib.Client
)
if cfg.Sentinel != nil {
newCli = goredislib.NewFailoverClient(&goredislib.FailoverOptions{
MasterName: cfg.Sentinel.MasterName,
SentinelAddrs: cfg.Sentinel.Addresses,
SentinelUsername: cfg.Sentinel.Username,
SentinelPassword: cfg.Sentinel.Password,
Password: cfg.Password,
Username: cfg.Username,
})
} else {
newCli = goredislib.NewClient(&goredislib.Options{
Addr: cfg.Address,
Username: cfg.Username,
Password: cfg.Password,
DB: cfg.Db,
})
}
err := newCli.Ping(a.boot.App.Context()).Err()
if err != nil {
return errors.WithMessage(err, "ping new redis client")
}
a.redisCli = newCli
if oldCli != nil {
err := oldCli.Close()
if err != nil {
return errors.WithMessage(err, "close old redis client")
}
}
return nil
}
+51
View File
@@ -0,0 +1,51 @@
package assembly
import (
goredislib "github.com/redis/go-redis/v9"
"isp-lock-service/conf"
"isp-lock-service/controller"
"isp-lock-service/repository"
"isp-lock-service/routes"
"isp-lock-service/service"
"github.com/txix-open/isp-kit/grpc"
"github.com/txix-open/isp-kit/grpc/endpoint"
"github.com/txix-open/isp-kit/log"
)
type Locator struct {
redisCli goredislib.UniversalClient
cfg conf.Remote
logger log.Logger
}
func NewLocator(logger log.Logger, redisCli goredislib.UniversalClient, cfg conf.Remote) Locator {
return Locator{
redisCli: redisCli,
cfg: cfg,
logger: logger,
}
}
func (l Locator) Handler() *grpc.Mux {
lockRepo := repository.NewLocker(l.logger, l.redisCli, l.cfg.Redis)
lockerService := service.NewLocker(l.logger, lockRepo)
lockerController := controller.NewLocker(l.logger, lockerService)
rateLimiterRepo := repository.NewRateLimiter(l.logger, l.redisCli, l.cfg.Redis)
rateLimiterService := service.NewRateLimiter(rateLimiterRepo)
rateLimiterController := controller.NewRateLimiter(rateLimiterService)
dailyLimiterRepo := repository.NewDailyLimiter(l.redisCli, l.cfg.Redis)
dailyLimiterService := service.NewDailyLimiter(dailyLimiterRepo)
dailyLimiterController := controller.NewDailyLimiter(dailyLimiterService)
c := routes.Controllers{
Locker: lockerController,
RateLimiter: rateLimiterController,
DailyLimiter: dailyLimiterController,
}
mapper := endpoint.DefaultWrapper(l.logger, endpoint.BodyLogger(l.logger))
handler := routes.Handler(mapper, c)
return handler
}
+16
View File
@@ -0,0 +1,16 @@
configServiceAddress:
ip: 127.0.0.1
port: 9001
grpcOuterAddress:
#ip: 127.0.0.1
port: 9740
grpcInnerAddress:
ip: 0.0.0.0
port: 9740
moduleName: isp-lock-service
logfile:
path: /var/log/isp-lock-service/runtime.log
maxSizeMb: 512
maxBackups: 4
compress: true
+9
View File
@@ -0,0 +1,9 @@
{
"logLevel": "debug",
"redis": {
"address": "{{ msp_redis_address }}:{{ msp_redis_port }}",
"password": "",
"db": 0,
"prefix": "isp-lock-service"
}
}
+39
View File
@@ -0,0 +1,39 @@
package conf
import (
"reflect"
"github.com/txix-open/isp-kit/log"
"github.com/txix-open/isp-kit/rc/schema"
"github.com/txix-open/jsonschema"
)
// nolint: gochecknoinits
func init() {
schema.CustomGenerators.Register("logLevel", func(field reflect.StructField, s *jsonschema.Schema) {
s.Type = "string"
s.Enum = []any{"debug", "info", "error", "fatal"}
})
}
type Remote struct {
LogLevel log.Level `schemaGen:"logLevel" schema:"Уровень логирования"`
Redis Redis `schema:"Настройки redis"`
}
type Redis struct {
Address string `schema:"Адрес,обязательное, если sentinel не указан"`
Username string `schema:"Имя пользователя"`
Password string `schema:"Пароль"`
Sentinel *RedisSentinel `schema:"Настройки sentinel,обязательно, если address не указан"`
Db int `schema:"номер БД в redis"`
Prefix string `schema:"Префикс ключей для модуля"`
}
type RedisSentinel struct {
Addresses []string `validate:"required" schema:"Адреса нод в кластере"`
MasterName string `validate:"required" schema:"Имя мастера"`
Username string `schema:"Имя пользователя в sentinel"`
Password string `schema:"Пароль в sentinel"`
}
+14
View File
@@ -0,0 +1,14 @@
package conf_test
import (
"testing"
"isp-lock-service/conf"
"github.com/txix-open/isp-kit/test/rct"
)
func TestDefaultRemoteConfig(t *testing.T) {
t.Parallel()
rct.Test(t, "default_remote_config.json", conf.Remote{})
}
+35
View File
@@ -0,0 +1,35 @@
package controller
import (
"context"
"github.com/txix-open/isp-kit/grpc/apierrors"
"isp-lock-service/domain"
)
type dailyLimiterService interface {
Increment(ctx context.Context, req domain.IncrementRequest) (*domain.IncrementResponse, error)
Set(ctx context.Context, req domain.SetRequest) error
}
type DailyLimiter struct {
svc dailyLimiterService
}
func NewDailyLimiter(svc dailyLimiterService) DailyLimiter { return DailyLimiter{svc: svc} }
func (c DailyLimiter) Increment(ctx context.Context, req domain.IncrementRequest) (*domain.IncrementResponse, error) {
resp, err := c.svc.Increment(ctx, req)
if err != nil {
return nil, apierrors.NewInternalServiceError(err)
}
return resp, nil
}
func (c DailyLimiter) Set(ctx context.Context, req domain.SetRequest) error {
err := c.svc.Set(ctx, req)
if err != nil {
return apierrors.NewInternalServiceError(err)
}
return nil
}
+53
View File
@@ -0,0 +1,53 @@
package controller
import (
"context"
"isp-lock-service/domain"
"github.com/txix-open/isp-kit/log"
)
type LockerService interface {
Lock(ctx context.Context, req domain.LockRequest) (*domain.LockResponse, error)
UnLock(ctx context.Context, req domain.UnLockRequest) (*domain.LockResponse, error)
}
type Locker struct {
s LockerService
logger log.Logger
}
// Lock
// @Tags locker
// @Summary выставляем лок на строку
// @Description Возвращаем ключ для разблокировки
// @Param key query string true "строка для лока"
// @Param ttlInSec query int true "число секунд после которых блокировка снимется автоматически"
// @Accept json
// @Produce json
// @Success 200 {object} domain.LockResponse
// @Router /api/isp-lock-service/lock [POST]
func (l Locker) Lock(ctx context.Context, req domain.LockRequest) (*domain.LockResponse, error) {
return l.s.Lock(ctx, req)
}
// UnLock
// @Tags locker
// @Summary снимаем лок со строки
// @Param key query string true "строка для лока"
// @Param lockKey query string true "ключ для разблокировки, полученный из Lock"
// @Accept json
// @Produce json
// @Success 200
// @Router /api/isp-lock-service/unlock [POST]
func (l Locker) UnLock(ctx context.Context, req domain.UnLockRequest) (*domain.LockResponse, error) {
return l.s.UnLock(ctx, req)
}
func NewLocker(logger log.Logger, s LockerService) Locker {
return Locker{
s: s,
logger: logger,
}
}
+23
View File
@@ -0,0 +1,23 @@
package controller
import (
"context"
"isp-lock-service/domain"
)
type limiterService interface {
Limit(ctx context.Context, req domain.RateLimiterRequest) (*domain.RateLimiterResponse, error)
}
type RateLimiter struct {
svc limiterService
}
func NewRateLimiter(svc limiterService) RateLimiter {
return RateLimiter{svc: svc}
}
func (c RateLimiter) Limit(ctx context.Context, req domain.RateLimiterRequest) (*domain.RateLimiterResponse, error) {
return c.svc.Limit(ctx, req)
}
+66
View File
@@ -0,0 +1,66 @@
basePath: /api/isp-lock-service
definitions:
domain.LockResponse:
properties:
lockKey:
type: string
type: object
host: localhost:9000
info:
contact: {}
description: Шаблон сервиса
license:
name: GNU GPL v3.0
title: isp-lock-service
version: 1.0.0
paths:
/api/isp-lock-service/lock:
post:
consumes:
- application/json
description: Возвращаем ключ для разблокировки
parameters:
- description: строка для лока
in: query
name: key
required: true
type: string
- description: число секунд после которых блокировка снимется автоматически
in: query
name: ttlInSec
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/domain.LockResponse'
summary: выставляем лок на строку
tags:
- locker
/api/isp-lock-service/unlock:
post:
consumes:
- application/json
parameters:
- description: строка для лока
in: query
name: key
required: true
type: string
- description: ключ для разблокировки, полученный из Lock
in: query
name: lockKey
required: true
type: string
produces:
- application/json
responses:
"200":
description: ""
summary: снимаем лок со строки
tags:
- locker
swagger: "2.0"
+20
View File
@@ -0,0 +1,20 @@
package domain
import (
"time"
)
type IncrementRequest struct {
Key string `validate:"required"`
Today time.Time `validate:"required"`
}
type IncrementResponse struct {
Value uint64
}
type SetRequest struct {
Key string `validate:"required"`
Value uint64 `validate:"required"`
Today time.Time `validate:"required"`
}
+16
View File
@@ -0,0 +1,16 @@
package domain
type LockRequest struct {
Key string `validate:"required"`
TTLInSec int `validate:"required"`
}
type UnLockRequest struct {
Key string `validate:"required"`
LockKey string `validate:"required"`
}
type LockResponse struct {
// nolint: tagliatelle
LockKey string `json:",omitempty"`
}
+16
View File
@@ -0,0 +1,16 @@
package domain
import (
"time"
)
type RateLimiterRequest struct {
Key string `validate:"required"`
MaxRps int `validate:"required"`
}
type RateLimiterResponse struct {
Allow bool
Remaining int
RetryAfter time.Duration
}
+75
View File
@@ -0,0 +1,75 @@
module isp-lock-service
go 1.23
require (
github.com/go-redis/redis_rate/v10 v10.0.1
github.com/go-redsync/redsync/v4 v4.13.0
github.com/pkg/errors v0.9.1
github.com/redis/go-redis/v9 v9.6.1
github.com/txix-open/isp-kit v1.38.1
github.com/txix-open/jsonschema v1.2.0
golang.org/x/sync v0.8.0
)
require (
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/coder/websocket v1.8.12 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
github.com/getsentry/sentry-go v0.29.0 // indirect
github.com/go-faker/faker/v4 v4.4.2 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.20.4 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.59.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/txix-open/bellows v1.2.0 // indirect
github.com/txix-open/etp/v3 v3.2.0 // indirect
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
go.opentelemetry.io/otel v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.30.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/sdk v1.30.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.67.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
+191
View File
@@ -0,0 +1,191 @@
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo=
github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4=
github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4=
github.com/getsentry/sentry-go v0.29.0 h1:YtWluuCFg9OfcqnaujpY918N/AhCCwarIDWOYSBAjCA=
github.com/getsentry/sentry-go v0.29.0/go.mod h1:jhPesDAL0Q0W2+2YEuVOvdWmVtdsr1+jtBrlDEVWwLY=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/go-faker/faker/v4 v4.4.2 h1:96WeU9QKEqRUVYdjHquY2/5bAqmVM0IfGKHV5mbfqmQ=
github.com/go-faker/faker/v4 v4.4.2/go.mod h1:4K3v4AbKXYNHMQNaREMc9/kRB9j5JJzpFo6KHRvrcIw=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg=
github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-redis/redis/v7 v7.4.1 h1:PASvf36gyUpr2zdOUS/9Zqc80GbM+9BDyiJSJDDOrTI=
github.com/go-redis/redis/v7 v7.4.1/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-redis/redis_rate/v10 v10.0.1 h1:calPxi7tVlxojKunJwQ72kwfozdy25RjA0bCj1h0MUo=
github.com/go-redis/redis_rate/v10 v10.0.1/go.mod h1:EMiuO9+cjRkR7UvdvwMO7vbgqJkltQHtwbdIQvaBKIU=
github.com/go-redsync/redsync/v4 v4.13.0 h1:49X6GJfnbLGaIpBBREM/zA4uIMDXKAh1NDkvQ1EkZKA=
github.com/go-redsync/redsync/v4 v4.13.0/go.mod h1:HMW4Q224GZQz6x1Xc7040Yfgacukdzu7ifTDAKiyErQ=
github.com/gomodule/redigo v1.8.9 h1:Sl3u+2BI/kk+VEatbj0scLdrFhjPmbxOc1myhDP41ws=
github.com/gomodule/redigo v1.8.9/go.mod h1:7ArFNvsTjH8GMMzB4uy1snslv2BwmginuMs06a1uzZE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.20.4 h1:Tgh3Yr67PaOv/uTqloMsCEdeuFTatm5zIq5+qNN23vI=
github.com/prometheus/client_golang v1.20.4/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0=
github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/rabbitmq/amqp091-go v1.10.0 h1:STpn5XsHlHGcecLmMFCtg7mqq0RnD+zFr4uzukfVhBw=
github.com/rabbitmq/amqp091-go v1.10.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o=
github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
github.com/redis/rueidis v1.0.19 h1:s65oWtotzlIFN8eMPhyYwxlwLR1lUdhza2KtWprKYSo=
github.com/redis/rueidis v1.0.19/go.mod h1:8B+r5wdnjwK3lTFml5VtxjzGOQAC+5UmujoD12pDrEo=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stvp/tempredis v0.0.0-20181119212430-b82af8480203 h1:QVqDTf3h2WHt08YuiTGPZLls0Wq99X9bWd0Q5ZSBesM=
github.com/stvp/tempredis v0.0.0-20181119212430-b82af8480203/go.mod h1:oqN97ltKNihBbwlX8dLpwxCl3+HnXKV/R0e+sRLd9C8=
github.com/txix-open/bellows v1.2.0 h1:CXv8nQaZtB/micraeRilYyj/gtfv+bqBgP5aPYQgjeY=
github.com/txix-open/bellows v1.2.0/go.mod h1:qbKCy+RTgD30Qpw1fyb3y3jp5Y9mGhLLxgae1l0W92o=
github.com/txix-open/etp/v3 v3.2.0 h1:EgTchT8VtCYV1iEo/y4jII3/NybrXiQDE0y6pmS350M=
github.com/txix-open/etp/v3 v3.2.0/go.mod h1:lgen0TJmiturgBhvlxH1/PQ7iLL/OebKbxPAQYkuKI0=
github.com/txix-open/grmq v1.6.0 h1:V4QRb0sI2CMfdMaMsFGvGvUIDGad5vr3khNU7A3LlP8=
github.com/txix-open/grmq v1.6.0/go.mod h1:s+NNNv42+32yLpjvl2tpqtyBbMB9e7kKFee3lfa/dyo=
github.com/txix-open/isp-kit v1.38.1 h1:IYsiW2xc06//xQsWcHX9A1GXCGTXQRXbUqotcxa6eDY=
github.com/txix-open/isp-kit v1.38.1/go.mod h1:uVn5y71Rg8jlFjFK3+QCh9uw1O7mcK+1grCNFZRWhME=
github.com/txix-open/jsonschema v1.2.0 h1:B8TrdSsPhDvYv67oi/LVqf7/+PuqFlMsNwUzGeHfl1s=
github.com/txix-open/jsonschema v1.2.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00=
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99 h1:Z0Sqf+U+Sc6hfIXtRCIZlbJprkCjwMFbS4ZbEPQ44To=
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99/go.mod h1:pA0NYmhL0uEkkxj55S+S7MZU4e2QIt46x9XSrzrWc3c=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
go.opentelemetry.io/otel v1.30.0 h1:F2t8sK4qf1fAmY9ua4ohFS/K+FUuOPemHUIXHtktrts=
go.opentelemetry.io/otel v1.30.0/go.mod h1:tFw4Br9b7fOS+uEao81PJjVMjW/5fvNCbpsDIXqP0pc=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.30.0 h1:lsInsfvhVIfOI6qHVyysXMNDnjO9Npvl7tlDPJFBVd4=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.30.0/go.mod h1:KQsVNh4OjgjTG0G6EiNi1jVpnaeeKsKMRwbLN+f1+8M=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.30.0 h1:umZgi92IyxfXd/l4kaDhnKgY8rnN/cZcF1LKc6I8OQ8=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.30.0/go.mod h1:4lVs6obhSVRb1EW5FhOuBTyiQhtRtAnnva9vD3yRfq8=
go.opentelemetry.io/otel/metric v1.30.0 h1:4xNulvn9gjzo4hjg+wzIKG7iNFEaBMX00Qd4QIZs7+w=
go.opentelemetry.io/otel/metric v1.30.0/go.mod h1:aXTfST94tswhWEb+5QjlSqG+cZlmyXy/u8jFpor3WqQ=
go.opentelemetry.io/otel/sdk v1.30.0 h1:cHdik6irO49R5IysVhdn8oaiR9m8XluDaJAs4DfOrYE=
go.opentelemetry.io/otel/sdk v1.30.0/go.mod h1:p14X4Ok8S+sygzblytT1nqG98QG2KYKv++HE0LY/mhg=
go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc=
go.opentelemetry.io/otel/trace v1.30.0/go.mod h1:5EyKqTzzmyqB9bwtCCq6pDLktPK6fmGf/Dph+8VI02o=
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 h1:hjSy6tcFQZ171igDaN5QHOw2n6vx40juYbC/x67CEhc=
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:qpvKtACPCQhAdu3PyQgV4l3LMXZEtft7y8QcarRsp9I=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.67.0 h1:IdH9y6PF5MPSdAntIcpjQ+tXO41pcQsfZV2RxtQgVcw=
google.golang.org/grpc v1.67.0/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+49
View File
@@ -0,0 +1,49 @@
package main
import (
"isp-lock-service/assembly"
"isp-lock-service/conf"
"isp-lock-service/routes"
"github.com/txix-open/isp-kit/bootstrap"
"github.com/txix-open/isp-kit/shutdown"
)
var (
version = "1.0.0"
)
// @title isp-lock-service
// @version 1.0.0
// @description Шаблон сервиса
// @license.name GNU GPL v3.0
// @host localhost:9000
// @BasePath /api/isp-lock-service
//go:generate swag init
//go:generate rm -f docs/swagger.json docs/docs.go
func main() {
boot := bootstrap.New(version, conf.Remote{}, routes.EndpointDescriptors())
app := boot.App
logger := app.Logger()
assembly, err := assembly.New(boot)
if err != nil {
boot.Fatal(err)
}
app.AddRunners(assembly.Runners()...)
app.AddClosers(assembly.Closers()...)
shutdown.On(func() {
logger.Info(app.Context(), "starting shutdown")
app.Shutdown()
logger.Info(app.Context(), "shutdown completed")
})
err = app.Run()
if err != nil {
boot.Fatal(err)
}
}
+51
View File
@@ -0,0 +1,51 @@
package repository
import (
"context"
"time"
"github.com/pkg/errors"
"github.com/redis/go-redis/v9"
"isp-lock-service/conf"
)
const (
dailyLimiterKeyTtl = 24 * time.Hour
)
type dailyLimiter struct {
redisCli redis.UniversalClient
keyPrefix string
}
func NewDailyLimiter(redisCli redis.UniversalClient, cfg conf.Redis) dailyLimiter {
return dailyLimiter{
redisCli: redisCli,
keyPrefix: cfg.Prefix + "::daily-limit",
}
}
func (r dailyLimiter) Increment(ctx context.Context, key string) (uint64, error) {
key = makeKey(r.keyPrefix, key)
v, err := r.redisCli.Incr(ctx, key).Uint64()
if err != nil {
return 0, errors.WithMessage(err, "redis cli incr")
}
if v == 1 {
err := r.redisCli.ExpireNX(ctx, key, dailyLimiterKeyTtl).Err()
if err != nil {
return 0, errors.WithMessage(err, "redis cli expire nx")
}
}
return v, nil
}
func (r dailyLimiter) Set(ctx context.Context, key string, dailyLimit uint64) error {
err := r.redisCli.Set(ctx, makeKey(r.keyPrefix, key), dailyLimit, dailyLimiterKeyTtl).Err()
if err != nil {
return errors.WithMessage(err, "redis cli set nx")
}
return nil
}
+58
View File
@@ -0,0 +1,58 @@
package repository
import (
"context"
"time"
"github.com/go-redsync/redsync/v4"
"github.com/go-redsync/redsync/v4/redis/goredis/v9"
"isp-lock-service/conf"
"isp-lock-service/domain"
"github.com/pkg/errors"
goredislib "github.com/redis/go-redis/v9"
"github.com/txix-open/isp-kit/log"
)
type Locker struct {
logger log.Logger
cli *redsync.Redsync
prefix string
}
func NewLocker(logger log.Logger, cli goredislib.UniversalClient, cfg conf.Redis) Locker {
return Locker{
logger: logger,
cli: redsync.New(goredis.NewPool(cli)),
prefix: cfg.Prefix,
}
}
func (l Locker) Lock(ctx context.Context, key string, ttl int) (*domain.LockResponse, error) {
key = makeKey(l.prefix, key)
mtx := l.cli.NewMutex(key, redsync.WithExpiry(time.Duration(ttl)*time.Second))
if err := mtx.Lock(); err != nil {
return nil, errors.WithMessagef(err, "fail lock. key=%s", key)
}
value := mtx.Value()
return &domain.LockResponse{LockKey: value}, nil
}
func (l Locker) UnLock(ctx context.Context, key, lockKey string) (*domain.LockResponse, error) {
key = makeKey(l.prefix, key)
_, err := l.cli.NewMutex(key, redsync.WithValue(lockKey)).Unlock()
if err != nil {
return nil, errors.WithMessagef(err, "fail unlock. key=%s", key)
}
return &domain.LockResponse{}, nil
}
func makeKey(prefix, key string) string {
return prefix + "::" + key
}
+39
View File
@@ -0,0 +1,39 @@
package repository
import (
"context"
"github.com/go-redis/redis_rate/v10"
"github.com/pkg/errors"
goredislib "github.com/redis/go-redis/v9"
"github.com/txix-open/isp-kit/log"
"isp-lock-service/conf"
"isp-lock-service/domain"
)
type rateLimiter struct {
logger log.Logger
cli *redis_rate.Limiter
prefix string
}
func NewRateLimiter(logger log.Logger, cli goredislib.UniversalClient, cfg conf.Redis) rateLimiter {
return rateLimiter{
logger: logger,
cli: redis_rate.NewLimiter(cli),
prefix: cfg.Prefix + "::rate-limiter",
}
}
func (r rateLimiter) Limit(ctx context.Context, key string, maxRps int) (*domain.RateLimiterResponse, error) {
res, err := r.cli.Allow(ctx, makeKey(r.prefix, key), redis_rate.PerSecond(maxRps))
if err != nil {
return nil, errors.WithMessage(err, "allow request")
}
return &domain.RateLimiterResponse{
Allow: res.Allowed > 0,
Remaining: res.Remaining,
RetryAfter: res.RetryAfter,
}, nil
}
+26
View File
@@ -0,0 +1,26 @@
### Lock
POST http://{{address}}/api/isp-lock-service/lock
Content-Type: application/json
X-Application-Token: {{token}}
x-auth-admin: {{admin-token}}
{
"key": "abc",
"ttlInSec": 15
}
> {%
client.global.set("lockKey", response.body.lockKey);
%}
### UnLock
POST http://{{address}}/api/isp-lock-service/unlock
Content-Type: application/json
X-Application-Token: {{token}}
x-auth-admin: {{admin-token}}
{
"key": "abc",
"lockKey": "{{lockKey}}"
}
###
+56
View File
@@ -0,0 +1,56 @@
package routes
import (
"github.com/txix-open/isp-kit/cluster"
"github.com/txix-open/isp-kit/grpc"
"github.com/txix-open/isp-kit/grpc/endpoint"
"isp-lock-service/controller"
)
type Controllers struct {
Locker controller.Locker
RateLimiter controller.RateLimiter
DailyLimiter controller.DailyLimiter
}
func EndpointDescriptors() []cluster.EndpointDescriptor {
return endpointDescriptors(Controllers{})
}
func Handler(wrapper endpoint.Wrapper, c Controllers) *grpc.Mux {
muxer := grpc.NewMux()
for _, descriptor := range endpointDescriptors(c) {
muxer.Handle(descriptor.Path, wrapper.Endpoint(descriptor.Handler))
}
return muxer
}
func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor {
return []cluster.EndpointDescriptor{{
Path: "isp-lock-service/lock",
Inner: true,
UserAuthRequired: false,
Handler: c.Locker.Lock,
}, {
Path: "isp-lock-service/unlock",
Inner: true,
UserAuthRequired: false,
Handler: c.Locker.UnLock,
}, {
Path: "isp-lock-service/rate_limit",
Inner: true,
UserAuthRequired: false,
Handler: c.RateLimiter.Limit,
}, {
Path: "isp-lock-service/daily_limit/increment",
Inner: true,
UserAuthRequired: false,
Handler: c.DailyLimiter.Increment,
}, {
Path: "isp-lock-service/daily_limit/set",
Inner: true,
UserAuthRequired: false,
Handler: c.DailyLimiter.Set,
}}
}
+41
View File
@@ -0,0 +1,41 @@
package service
import (
"context"
"fmt"
"time"
"github.com/pkg/errors"
"isp-lock-service/domain"
)
type dailyLimiterRepo interface {
Increment(ctx context.Context, key string) (uint64, error)
Set(ctx context.Context, key string, dailyLimit uint64) error
}
type dailyLimiter struct {
repo dailyLimiterRepo
}
func NewDailyLimiter(repo dailyLimiterRepo) dailyLimiter { return dailyLimiter{repo: repo} }
func (s dailyLimiter) Increment(ctx context.Context, req domain.IncrementRequest) (*domain.IncrementResponse, error) {
v, err := s.repo.Increment(ctx, s.makeKey(req.Key, req.Today))
if err != nil {
return nil, errors.WithMessage(err, "repo increment")
}
return &domain.IncrementResponse{Value: v}, nil
}
func (s dailyLimiter) Set(ctx context.Context, req domain.SetRequest) error {
err := s.repo.Set(ctx, s.makeKey(req.Key, req.Today), req.Value)
if err != nil {
return errors.WithMessage(err, "repo set")
}
return nil
}
func (s dailyLimiter) makeKey(key string, today time.Time) string {
return fmt.Sprintf("%s:%s", key, today.Format(time.DateOnly))
}
+36
View File
@@ -0,0 +1,36 @@
package service
import (
"context"
"isp-lock-service/domain"
"github.com/txix-open/isp-kit/log"
)
type LockerRepo interface {
Lock(ctx context.Context, key string, ttlInSec int) (*domain.LockResponse, error)
UnLock(ctx context.Context, key, lockKey string) (*domain.LockResponse, error)
}
type Locker struct {
repo LockerRepo
logger log.Logger
}
func (l Locker) Lock(ctx context.Context, req domain.LockRequest) (*domain.LockResponse, error) {
// nolint: wrapcheck
return l.repo.Lock(ctx, req.Key, req.TTLInSec)
}
func (l Locker) UnLock(ctx context.Context, req domain.UnLockRequest) (*domain.LockResponse, error) {
// nolint: wrapcheck
return l.repo.UnLock(ctx, req.Key, req.LockKey)
}
func NewLocker(logger log.Logger, repo LockerRepo) Locker {
return Locker{
repo: repo,
logger: logger,
}
}
+23
View File
@@ -0,0 +1,23 @@
package service
import (
"context"
"isp-lock-service/domain"
)
type limiterRepo interface {
Limit(ctx context.Context, key string, maxRps int) (*domain.RateLimiterResponse, error)
}
type rateLimiter struct {
repo limiterRepo
}
func NewRateLimiter(repo limiterRepo) rateLimiter {
return rateLimiter{repo: repo}
}
func (s rateLimiter) Limit(ctx context.Context, req domain.RateLimiterRequest) (*domain.RateLimiterResponse, error) {
return s.repo.Limit(ctx, req.Key, req.MaxRps) // nolint:wrapcheck
}
+45
View File
@@ -0,0 +1,45 @@
package tests_test
import (
"context"
"testing"
"github.com/txix-open/isp-kit/test"
"github.com/txix-open/isp-kit/test/fake"
"isp-lock-service/conf"
"isp-lock-service/domain"
"isp-lock-service/repository"
"isp-lock-service/service"
)
func TestDailyLimiter(t *testing.T) {
t.Parallel()
var (
tst, required = test.New(t)
redis = NewRedis(tst)
r = repository.NewDailyLimiter(redis, conf.Redis{Prefix: "test"})
svc = service.NewDailyLimiter(r)
ctx = context.Background()
req = fake.It[domain.IncrementRequest]()
)
for i := range 1000 {
resp, err := svc.Increment(ctx, req)
required.NoError(err)
required.EqualValues(i+1, resp.Value)
}
dailyLimits := fake.It[[]uint64](fake.MinSliceSize(1000))
for _, v := range dailyLimits {
err := svc.Set(ctx, domain.SetRequest{
Key: req.Key,
Value: v,
Today: req.Today,
})
required.NoError(err)
resp, err := svc.Increment(ctx, req)
required.NoError(err)
required.EqualValues(v+1, resp.Value)
}
}
+67
View File
@@ -0,0 +1,67 @@
package tests_test
import (
"context"
"testing"
"time"
"github.com/txix-open/isp-kit/test"
"github.com/txix-open/isp-kit/test/fake"
"isp-lock-service/conf"
"isp-lock-service/domain"
"isp-lock-service/repository"
)
func TestRateLimiter(t *testing.T) {
t.Parallel()
tst, required := test.New(t)
redis := NewRedis(tst)
r := repository.NewRateLimiter(tst.Logger(), redis, conf.Redis{Prefix: "test"})
var (
maxRps = 5
key = "key"
)
for i := range maxRps {
resp, err := r.Limit(context.Background(), key, maxRps)
required.NoError(err)
exp := &domain.RateLimiterResponse{
Allow: true,
Remaining: maxRps - (i + 1),
RetryAfter: -1,
}
required.EqualValues(exp, resp)
}
resp, err := r.Limit(context.Background(), key, maxRps)
required.NoError(err)
exp := &domain.RateLimiterResponse{
Allow: false,
Remaining: 0,
RetryAfter: resp.RetryAfter,
}
required.Greater(exp.RetryAfter, time.Duration(0))
required.EqualValues(exp, resp)
time.Sleep(time.Second)
resp, err = r.Limit(context.Background(), key, maxRps)
required.NoError(err)
exp = &domain.RateLimiterResponse{
Allow: true,
Remaining: maxRps - 1,
RetryAfter: -1,
}
required.EqualValues(exp, resp)
for range 1000 {
key := fake.It[string]()
resp, err := r.Limit(context.Background(), key, 1)
required.NoError(err)
exp := &domain.RateLimiterResponse{
Allow: true,
Remaining: 0,
RetryAfter: -1,
}
required.EqualValues(exp, resp)
}
}
+88
View File
@@ -0,0 +1,88 @@
package tests_test
import (
"context"
"fmt"
"testing"
"time"
"github.com/redis/go-redis/v9"
"golang.org/x/sync/errgroup"
"isp-lock-service/conf"
"isp-lock-service/repository"
"github.com/txix-open/isp-kit/test"
)
func NewRedis(test *test.Test) *redis.Client {
redisHost := test.Config().Optional().String("REDIS_HOST", "localhost")
redisPort := test.Config().Optional().String("REDIS_PORT", "6379")
addr := fmt.Sprintf("%s:%s", redisHost, redisPort)
return redis.NewClient(&redis.Options{Addr: addr})
}
func TestOne(t *testing.T) {
t.Parallel()
tst, required := test.New(t)
rcli := NewRedis(tst)
ctx := context.Background()
r := repository.NewLocker(tst.Logger(), rcli, conf.Redis{Prefix: "testPrefix"})
// success story
key := time.Now().String()
l, err := r.Lock(ctx, key, 1)
required.NoError(err)
_, err = r.UnLock(ctx, key, l.LockKey)
required.NoError(err)
// look at wait
_, err = r.Lock(ctx, key, 1)
required.NoError(err)
n := time.Now()
_, err = r.Lock(ctx, key, 1)
required.NoError(err)
diff := time.Since(n)
required.Greater(diff, time.Second)
// look at error
l, err = r.Lock(ctx, key, 10)
required.NoError(err)
_, err = r.Lock(ctx, key, 1)
required.Error(err)
if err != nil {
required.Error(err, "fail lock")
}
_, err = r.UnLock(ctx, key, l.LockKey)
required.NoError(err)
}
func TestConcurrency(t *testing.T) {
t.Parallel()
tst, required := test.New(t)
redis := NewRedis(tst)
r := repository.NewLocker(tst.Logger(), redis, conf.Redis{Prefix: "testPrefix"})
group, ctx := errgroup.WithContext(context.Background())
group.SetLimit(32)
for range 10000 {
group.Go(func() error {
resp, err := r.Lock(ctx, "key", 5)
required.NoError(err)
_, err = r.UnLock(ctx, "key", resp.LockKey)
required.NoError(err)
return nil
})
}
err := group.Wait()
required.NoError(err)
}