Files
de61635b81 refactor: move all packages under pkg/ for v5 (#559)
* refactor: move all packages under pkg/ for v5

Move all 13 top-level Go packages into pkg/ for a cleaner repository
structure. All internal import paths updated from
github.com/formancehq/go-libs/v5/<pkg> to
github.com/formancehq/go-libs/v5/pkg/<pkg>.

Also includes cleanup:
- Fix .golangci.yml stale v4 CircuitBreaker path
- Replace deprecated str.Contains with stdlib slices.Contains
- Update TODO(v4) markers to TODO
- Delete stale coverage.txt
- Fix pgtesting timeout not being propagated to docker pool
- Update docs/ARCHITECTURE.md to reflect new structure

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* chore: remove compatibility aliases, unused params, and stub files

- Remove unused type aliases (Authenticator, KeySet) from authnfx
- Remove unused `debug` parameter from S3ModuleFromFlags
- Delete comment-only stub files in messaging/publish/circuit/

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* chore: rename cli.go to flags.go for consistency

Standardize naming across all packages: cli.go -> flags.go
since these files all serve the same purpose (flag definitions).

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* chore: rename

* chore(deps): update all dependencies

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: resolve package name mismatches in generated mocks

Generated mock files had stale package names from before the pkg/ move,
causing import cycles and build failures with --build-tags it.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
2026-03-20 09:17:12 +00:00

77 lines
1.7 KiB
Go

package storage
import (
"context"
"time"
"github.com/uptrace/bun"
)
type Store interface {
Insert(ctx context.Context, topic string, data []byte, metadata map[string]string) error
List(ctx context.Context) ([]*CircuitBreakerModel, error)
Delete(ctx context.Context, ids []uint64) error
}
type CircuitBreakerModel struct {
bun.BaseModel `bun:"circuit_breaker"`
ID uint64 `bun:"id,pk,autoincrement"`
CreatedAt time.Time `bun:",notnull"`
Topic string `bun:",notnull"`
Data []byte `bun:",notnull"`
Metadata map[string]string `bun:",type:jsonb"`
}
type Storage struct {
db *bun.DB
schema string
storageLimit int
}
func New(schema string, db *bun.DB, storageLimit int) *Storage {
return &Storage{
schema: schema,
db: db,
storageLimit: storageLimit,
}
}
func (s *Storage) Insert(ctx context.Context, topic string, data []byte, metadata map[string]string) error {
_, err := s.db.NewInsert().
Model(&CircuitBreakerModel{
CreatedAt: time.Now().UTC(),
Topic: topic,
Data: data,
Metadata: metadata,
},
).Exec(ctx)
return err
}
func (s *Storage) List(ctx context.Context) ([]*CircuitBreakerModel, error) {
var models []*CircuitBreakerModel
err := s.db.NewSelect().
Model(&models).
Order("created_at ASC").
Limit(s.storageLimit).
Scan(ctx)
return models, err
}
func (s *Storage) Delete(ctx context.Context, ids []uint64) error {
models := make([]*CircuitBreakerModel, 0, len(ids))
for _, id := range ids {
models = append(models, &CircuitBreakerModel{ID: id})
}
_, err := s.db.NewDelete().
Model(&models).
WherePK().
Exec(ctx)
return err
}