Application superstructure (or supersingleton, if you want).
Some checks failed
continuous-integration/drone/push Build is failing

Got rid of context thing which misleads due to existance of stdlib's
context package.

Also fixed golangci-lint configuration.

Fixes #20.
This commit is contained in:
2022-08-19 21:52:49 +05:00
parent b87921c811
commit 5fc6d3a181
35 changed files with 589 additions and 440 deletions

View File

@@ -25,15 +25,15 @@
package indexpage
import (
"go.dev.pztrn.name/fastpastebin/internal/context"
"go.dev.pztrn.name/fastpastebin/internal/application"
)
var ctx *context.Context
var app *application.Application
// New initializes pastes package and adds necessary HTTP and API
// endpoints.
func New(cc *context.Context) {
ctx = cc
func New(cc *application.Application) {
app = cc
ctx.Echo.GET("/", indexGet)
app.Echo.GET("/", indexGet)
}

View File

@@ -37,8 +37,8 @@ import (
// Index of this site.
func indexGet(ectx echo.Context) error {
// We should check if database connection available.
dbConn := ctx.Database.GetDatabaseConnection()
if ctx.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil {
dbConn := app.Database.GetDatabaseConnection()
if app.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil {
//nolint:wrapcheck
return ectx.Redirect(http.StatusFound, "/database_not_available")
}