Files
sendico/api/payments/quotation/internal/server/internal/serverimp.go
2026-02-10 18:29:47 +01:00

71 lines
1.9 KiB
Go

package serverimp
import (
quotesvc "github.com/tech/sendico/payments/quotation/internal/service/orchestrator"
"github.com/tech/sendico/payments/storage"
mongostorage "github.com/tech/sendico/payments/storage/mongo"
"github.com/tech/sendico/pkg/db"
msg "github.com/tech/sendico/pkg/messaging"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/server/grpcapp"
)
func Create(logger mlogger.Logger, file string, debug bool) (*Imp, error) {
return &Imp{
logger: logger.Named("server"),
file: file,
debug: debug,
}, nil
}
func (i *Imp) Shutdown() {
i.stopDiscoveryAnnouncer()
if i.service != nil {
i.service.Shutdown()
}
i.shutdownApp()
i.closeDependencies()
}
func (i *Imp) Start() error {
cfg, err := i.loadConfig()
if err != nil {
return err
}
i.config = cfg
i.deps = i.initDependencies(cfg)
quoteRetention := cfg.quoteRetention()
repoFactory := func(logger mlogger.Logger, conn *db.MongoConnection) (storage.Repository, error) {
return mongostorage.New(logger, conn, mongostorage.WithQuoteRetention(quoteRetention))
}
serviceFactory := func(logger mlogger.Logger, repo storage.Repository, producer msg.Producer) (grpcapp.Service, error) {
opts := []quotesvc.Option{}
if i.deps != nil {
if i.deps.feesClient != nil {
opts = append(opts, quotesvc.WithFeeEngine(i.deps.feesClient, cfg.Fees.callTimeout()))
}
if i.deps.oracleClient != nil {
opts = append(opts, quotesvc.WithOracleClient(i.deps.oracleClient))
}
if i.deps.gatewayClient != nil {
opts = append(opts, quotesvc.WithChainGatewayClient(i.deps.gatewayClient))
}
}
i.startDiscoveryAnnouncer(cfg, producer)
svc := quotesvc.NewQuotationService(logger, repo, opts...)
i.service = svc
return svc, nil
}
app, err := grpcapp.NewApp(i.logger, "payments_quotation", cfg.Config, i.debug, repoFactory, serviceFactory)
if err != nil {
return err
}
i.app = app
return i.app.Start()
}