-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactoring: use fx library * Fix: security issue #23 * Fix: add websocket endpoint * Remove unused notificator * Refactoring: api server creation
- Loading branch information
1 parent
f524581
commit 5185129
Showing
81 changed files
with
1,298 additions
and
858 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/celenium-io/astria-indexer/cmd/api/bus" | ||
"github.com/celenium-io/astria-indexer/cmd/api/cache" | ||
"github.com/celenium-io/astria-indexer/cmd/api/handler/websocket" | ||
"github.com/celenium-io/astria-indexer/internal/storage" | ||
"github.com/dipdup-net/indexer-sdk/pkg/storage/postgres" | ||
"github.com/grafana/pyroscope-go" | ||
"github.com/labstack/echo/v4" | ||
"github.com/pkg/errors" | ||
"go.uber.org/fx" | ||
) | ||
|
||
type App struct { | ||
e *echo.Echo | ||
db *postgres.Storage | ||
wsManager *websocket.Manager | ||
dispatcher *bus.Dispatcher | ||
constantCache *cache.ConstantsCache | ||
endpointCache *cache.Cache | ||
prscp *pyroscope.Profiler | ||
constants storage.IConstant | ||
} | ||
|
||
func newApp( | ||
lc fx.Lifecycle, | ||
cfg *Config, | ||
e *echo.Echo, | ||
db *postgres.Storage, | ||
wsManager *websocket.Manager, | ||
dispatcher *bus.Dispatcher, | ||
constantCache *cache.ConstantsCache, | ||
endpointCache *cache.Cache, | ||
prscp *pyroscope.Profiler, | ||
constants storage.IConstant, | ||
) *App { | ||
app := &App{ | ||
e: e, | ||
db: db, | ||
wsManager: wsManager, | ||
dispatcher: dispatcher, | ||
constantCache: constantCache, | ||
endpointCache: endpointCache, | ||
prscp: prscp, | ||
constants: constants, | ||
} | ||
|
||
lc.Append(fx.Hook{ | ||
OnStart: func(ctx context.Context) error { | ||
dispatcher.Start(ctx) | ||
wsManager.Start(ctx) | ||
endpointCache.Start(ctx) | ||
if err := constantCache.Start(ctx, app.constants); err != nil { | ||
return errors.Wrap(err, "start constant cache") | ||
} | ||
|
||
if err := app.e.Start(cfg.ApiConfig.Bind); err != nil && errors.Is(err, http.ErrServerClosed) { | ||
return errors.Wrap(err, "shutting down the server") | ||
} | ||
return nil | ||
}, | ||
OnStop: func(ctx context.Context) error { | ||
if app.wsManager != nil { | ||
if err := app.wsManager.Close(); err != nil { | ||
return errors.Wrap(err, "closing websocket manager") | ||
} | ||
} | ||
if app.endpointCache != nil { | ||
if err := app.endpointCache.Close(); err != nil { | ||
return errors.Wrap(err, "closing cache") | ||
} | ||
} | ||
if app.constantCache != nil { | ||
if err := app.constantCache.Close(); err != nil { | ||
return errors.Wrap(err, "closing constant cache") | ||
} | ||
} | ||
if app.dispatcher != nil { | ||
if err := app.dispatcher.Close(); err != nil { | ||
return errors.Wrap(err, "closing bus dispatcher") | ||
} | ||
} | ||
|
||
if err := app.e.Shutdown(ctx); err != nil { | ||
return errors.Wrap(err, "closing server") | ||
} | ||
|
||
if app.prscp != nil { | ||
if err := app.prscp.Stop(); err != nil { | ||
return errors.Wrap(err, "closing profler") | ||
} | ||
} | ||
if err := app.db.Close(); err != nil { | ||
return errors.Wrap(err, "closing database") | ||
} | ||
return nil | ||
}, | ||
}) | ||
return app | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package handler | ||
|
||
import "github.com/labstack/echo/v4" | ||
|
||
type Handler interface { | ||
InitRoutes(srvr *echo.Group) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.