Handlers, DB, Cache

This commit is contained in:
2026-03-10 19:17:43 +03:00
parent e56b1f1305
commit 968c030939
23 changed files with 566 additions and 34 deletions

50
internal/service/cache/module.go vendored Normal file
View File

@@ -0,0 +1,50 @@
package cache
import (
"context"
"errors"
"go.uber.org/fx"
"payouts/internal/config"
"payouts/internal/service/database/orm"
)
var Module = fx.Options(
fx.Provide(New),
fx.Invoke(StartCache),
)
var NoSessionFound = errors.New("no session found")
type Service interface {
PutSession(string, orm.User)
GetSession(string) (orm.User, error)
StartBackground()
}
type Params struct {
fx.In
AppConfig *config.App
}
func New(p Params) (Service, error) {
return NewSessionCache(p.AppConfig.Cache.TTL)
}
// RegisterRoutes registers the api routes and starts the http server
func StartCache(s Service, lc fx.Lifecycle) {
lc.Append(fx.Hook{
OnStart: func(c context.Context) error {
go func() {
s.StartBackground()
}()
return nil
},
OnStop: func(ctx context.Context) error {
return nil
},
})
}