cleaned up main module
This commit is contained in:
@@ -20,10 +20,9 @@ func NewServer(
|
||||
conn *sql.DB,
|
||||
tokenGen *jwt.TokenGenerator,
|
||||
staticFS *fs.FS,
|
||||
maint *uint32,
|
||||
) *http.Server {
|
||||
fs := http.FS(*staticFS)
|
||||
srv := createServer(config, logger, conn, tokenGen, &fs, maint)
|
||||
srv := createServer(config, logger, conn, tokenGen, &fs)
|
||||
httpServer := &http.Server{
|
||||
Addr: net.JoinHostPort(config.Host, config.Port),
|
||||
Handler: srv,
|
||||
@@ -41,7 +40,6 @@ func createServer(
|
||||
conn *sql.DB,
|
||||
tokenGen *jwt.TokenGenerator,
|
||||
staticFS *http.FileSystem,
|
||||
maint *uint32,
|
||||
) http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
addRoutes(
|
||||
@@ -56,7 +54,7 @@ func createServer(
|
||||
// Add middleware here, must be added in reverse order of execution
|
||||
// i.e. First in list will get executed last during the request handling
|
||||
handler = middleware.Logging(logger, handler)
|
||||
handler = middleware.Authentication(logger, config, conn, tokenGen, handler, maint)
|
||||
handler = middleware.Authentication(logger, config, conn, tokenGen, handler)
|
||||
|
||||
// Gzip
|
||||
handler = middleware.Gzip(handler, config.GZIP)
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"net/http"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"projectreshoot/internal/config"
|
||||
@@ -104,7 +103,6 @@ func Authentication(
|
||||
conn *sql.DB,
|
||||
tokenGen *jwt.TokenGenerator,
|
||||
next http.Handler,
|
||||
maint *uint32,
|
||||
) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == "/static/css/output.css" ||
|
||||
@@ -114,9 +112,6 @@ func Authentication(
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
|
||||
defer cancel()
|
||||
if atomic.LoadUint32(maint) == 1 {
|
||||
cancel()
|
||||
}
|
||||
|
||||
// Start the transaction
|
||||
tx, err := conn.BeginTx(ctx, nil)
|
||||
|
||||
Reference in New Issue
Block a user