diff --git a/internal/server/authorization_test.go b/internal/server/authorization_test.go index 3e4c2d7..b426cc5 100644 --- a/internal/server/authorization_test.go +++ b/internal/server/authorization_test.go @@ -21,7 +21,7 @@ func TestAuthorization(t *testing.T) { env := &server.Environment{} env.DB = testdb env.JWTSecret = []byte("secret") - ts := httptest.NewTLSServer(server.NewRouter(env)) + ts := httptest.NewTLSServer(server.NewHandler(env)) defer ts.Close() client := ts.Client() diff --git a/internal/server/handlers_certificate_requests.go b/internal/server/handlers_certificate_requests.go index 650a98f..b975db1 100644 --- a/internal/server/handlers_certificate_requests.go +++ b/internal/server/handlers_certificate_requests.go @@ -17,16 +17,16 @@ func GetCertificateRequests(env *Environment) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { certs, err := env.DB.RetrieveAllCSRs() if err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } body, err := json.Marshal(certs) if err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } if _, err := w.Write(body); err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) } } } @@ -36,25 +36,25 @@ func PostCertificateRequest(env *Environment) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { csr, err := io.ReadAll(r.Body) if err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } id, err := env.DB.CreateCSR(string(csr)) if err != nil { if strings.Contains(err.Error(), "UNIQUE constraint failed") { - logErrorAndWriteResponse("given csr already recorded", http.StatusBadRequest, w) + writeError("given csr already recorded", http.StatusBadRequest, w) return } if strings.Contains(err.Error(), "csr validation failed") { - logErrorAndWriteResponse(err.Error(), http.StatusBadRequest, w) + writeError(err.Error(), http.StatusBadRequest, w) return } - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } w.WriteHeader(http.StatusCreated) if _, err := w.Write([]byte(strconv.FormatInt(id, 10))); err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) } } } @@ -67,19 +67,19 @@ func GetCertificateRequest(env *Environment) http.HandlerFunc { cert, err := env.DB.RetrieveCSR(id) if err != nil { if errors.Is(err, db.ErrIdNotFound) { - logErrorAndWriteResponse(err.Error(), http.StatusNotFound, w) + writeError(err.Error(), http.StatusNotFound, w) return } - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } body, err := json.Marshal(cert) if err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } if _, err := w.Write(body); err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) } } } @@ -92,15 +92,15 @@ func DeleteCertificateRequest(env *Environment) http.HandlerFunc { insertId, err := env.DB.DeleteCSR(id) if err != nil { if errors.Is(err, db.ErrIdNotFound) { - logErrorAndWriteResponse(err.Error(), http.StatusNotFound, w) + writeError(err.Error(), http.StatusNotFound, w) return } - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } w.WriteHeader(http.StatusAccepted) if _, err := w.Write([]byte(strconv.FormatInt(insertId, 10))); err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) } } } @@ -111,7 +111,7 @@ func PostCertificate(env *Environment) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cert, err := io.ReadAll(r.Body) if err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusBadRequest, w) + writeError(err.Error(), http.StatusBadRequest, w) return } id := r.PathValue("id") @@ -120,10 +120,10 @@ func PostCertificate(env *Environment) http.HandlerFunc { if errors.Is(err, db.ErrIdNotFound) || err.Error() == "certificate does not match CSR" || strings.Contains(err.Error(), "cert validation failed") { - logErrorAndWriteResponse(err.Error(), http.StatusBadRequest, w) + writeError(err.Error(), http.StatusBadRequest, w) return } - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } insertIdStr := strconv.FormatInt(insertId, 10) @@ -135,7 +135,7 @@ func PostCertificate(env *Environment) http.HandlerFunc { } w.WriteHeader(http.StatusCreated) if _, err := w.Write([]byte(insertIdStr)); err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) } } } @@ -146,10 +146,10 @@ func RejectCertificate(env *Environment) http.HandlerFunc { insertId, err := env.DB.UpdateCSR(id, "rejected") if err != nil { if errors.Is(err, db.ErrIdNotFound) { - logErrorAndWriteResponse(err.Error(), http.StatusNotFound, w) + writeError(err.Error(), http.StatusNotFound, w) return } - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } insertIdStr := strconv.FormatInt(insertId, 10) @@ -161,7 +161,7 @@ func RejectCertificate(env *Environment) http.HandlerFunc { } w.WriteHeader(http.StatusAccepted) if _, err := w.Write([]byte(insertIdStr)); err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) } } } @@ -174,10 +174,10 @@ func DeleteCertificate(env *Environment) http.HandlerFunc { insertId, err := env.DB.UpdateCSR(id, "") if err != nil { if errors.Is(err, db.ErrIdNotFound) { - logErrorAndWriteResponse(err.Error(), http.StatusBadRequest, w) + writeError(err.Error(), http.StatusBadRequest, w) return } - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } insertIdStr := strconv.FormatInt(insertId, 10) @@ -189,7 +189,7 @@ func DeleteCertificate(env *Environment) http.HandlerFunc { } w.WriteHeader(http.StatusAccepted) if _, err := w.Write([]byte(insertIdStr)); err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) } } } diff --git a/internal/server/handlers_certificate_requests_test.go b/internal/server/handlers_certificate_requests_test.go index 1a6d5e1..7b96e7b 100644 --- a/internal/server/handlers_certificate_requests_test.go +++ b/internal/server/handlers_certificate_requests_test.go @@ -145,7 +145,7 @@ func TestNotaryCertificatesHandlers(t *testing.T) { } env := &server.Environment{} env.DB = testdb - ts := httptest.NewTLSServer(server.NewRouter(env)) + ts := httptest.NewTLSServer(server.NewHandler(env)) defer ts.Close() client := ts.Client() diff --git a/internal/server/handlers_health.go b/internal/server/handlers_health.go index 5dc9c34..bb16bc3 100644 --- a/internal/server/handlers_health.go +++ b/internal/server/handlers_health.go @@ -11,14 +11,14 @@ func HealthCheck(env *Environment) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { users, err := env.DB.RetrieveAllUsers() if err != nil { - logErrorAndWriteResponse("couldn't generate status", http.StatusInternalServerError, w) + writeError("couldn't generate status", http.StatusInternalServerError, w) return } response, err := json.Marshal(map[string]any{ "initialized": len(users) > 0, }) if err != nil { - logErrorAndWriteResponse("couldn't generate status", http.StatusInternalServerError, w) + writeError("couldn't generate status", http.StatusInternalServerError, w) return } w.Write(response) //nolint:errcheck diff --git a/internal/server/handlers_login.go b/internal/server/handlers_login.go index abf26a1..05e7c1f 100644 --- a/internal/server/handlers_login.go +++ b/internal/server/handlers_login.go @@ -40,39 +40,39 @@ func Login(env *Environment) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var userRequest db.User if err := json.NewDecoder(r.Body).Decode(&userRequest); err != nil { - logErrorAndWriteResponse("Invalid JSON format", http.StatusBadRequest, w) + writeError("Invalid JSON format", http.StatusBadRequest, w) return } if userRequest.Username == "" { - logErrorAndWriteResponse("Username is required", http.StatusBadRequest, w) + writeError("Username is required", http.StatusBadRequest, w) return } if userRequest.Password == "" { - logErrorAndWriteResponse("Password is required", http.StatusBadRequest, w) + writeError("Password is required", http.StatusBadRequest, w) return } userAccount, err := env.DB.RetrieveUserByUsername(userRequest.Username) if err != nil { status := http.StatusInternalServerError if errors.Is(err, db.ErrIdNotFound) { - logErrorAndWriteResponse("The username or password is incorrect. Try again.", http.StatusUnauthorized, w) + writeError("The username or password is incorrect. Try again.", http.StatusUnauthorized, w) return } - logErrorAndWriteResponse(err.Error(), status, w) + writeError(err.Error(), status, w) return } if err := bcrypt.CompareHashAndPassword([]byte(userAccount.Password), []byte(userRequest.Password)); err != nil { - logErrorAndWriteResponse("The username or password is incorrect. Try again.", http.StatusUnauthorized, w) + writeError("The username or password is incorrect. Try again.", http.StatusUnauthorized, w) return } jwt, err := generateJWT(userAccount.ID, userAccount.Username, env.JWTSecret, userAccount.Permissions) if err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } w.WriteHeader(http.StatusOK) if _, err := w.Write([]byte(jwt)); err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) } } } diff --git a/internal/server/handlers_login_test.go b/internal/server/handlers_login_test.go index 9eda0c7..ed2a827 100644 --- a/internal/server/handlers_login_test.go +++ b/internal/server/handlers_login_test.go @@ -22,7 +22,7 @@ func TestLogin(t *testing.T) { env := &server.Environment{} env.DB = testdb env.JWTSecret = []byte("secret") - ts := httptest.NewTLSServer(server.NewRouter(env)) + ts := httptest.NewTLSServer(server.NewHandler(env)) defer ts.Close() client := ts.Client() diff --git a/internal/server/handlers_users.go b/internal/server/handlers_users.go index e98e969..67b1008 100644 --- a/internal/server/handlers_users.go +++ b/internal/server/handlers_users.go @@ -79,7 +79,7 @@ func GetUserAccounts(env *Environment) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { users, err := env.DB.RetrieveAllUsers() if err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } for i := range users { @@ -87,11 +87,11 @@ func GetUserAccounts(env *Environment) http.HandlerFunc { } body, err := json.Marshal(users) if err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } if _, err := w.Write(body); err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) } } } @@ -106,7 +106,7 @@ func GetUserAccount(env *Environment) http.HandlerFunc { if id == "me" { claims, headerErr := getClaimsFromAuthorizationHeader(r.Header.Get("Authorization"), env.JWTSecret) if headerErr != nil { - logErrorAndWriteResponse(headerErr.Error(), http.StatusUnauthorized, w) + writeError(headerErr.Error(), http.StatusUnauthorized, w) } userAccount, err = env.DB.RetrieveUserByUsername(claims.Username) } else { @@ -114,20 +114,20 @@ func GetUserAccount(env *Environment) http.HandlerFunc { } if err != nil { if errors.Is(err, db.ErrIdNotFound) { - logErrorAndWriteResponse(err.Error(), http.StatusNotFound, w) + writeError(err.Error(), http.StatusNotFound, w) return } - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } userAccount.Password = "" body, err := json.Marshal(userAccount) if err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } if _, err := w.Write(body); err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) } } } @@ -137,24 +137,24 @@ func PostUserAccount(env *Environment) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var user db.User if err := json.NewDecoder(r.Body).Decode(&user); err != nil { - logErrorAndWriteResponse("Invalid JSON format", http.StatusBadRequest, w) + writeError("Invalid JSON format", http.StatusBadRequest, w) return } if user.Username == "" { - logErrorAndWriteResponse("Username is required", http.StatusBadRequest, w) + writeError("Username is required", http.StatusBadRequest, w) return } shouldGeneratePassword := user.Password == "" if shouldGeneratePassword { generatedPassword, err := generatePassword() if err != nil { - logErrorAndWriteResponse("Failed to generate password", http.StatusInternalServerError, w) + writeError("Failed to generate password", http.StatusInternalServerError, w) return } user.Password = generatedPassword } if !validatePassword(user.Password) { - logErrorAndWriteResponse( + writeError( "Password must have 8 or more characters, must include at least one capital letter, one lowercase letter, and either a number or a symbol.", http.StatusBadRequest, w, @@ -163,7 +163,7 @@ func PostUserAccount(env *Environment) http.HandlerFunc { } users, err := env.DB.RetrieveAllUsers() if err != nil { - logErrorAndWriteResponse("Failed to retrieve users: "+err.Error(), http.StatusInternalServerError, w) + writeError("Failed to retrieve users: "+err.Error(), http.StatusInternalServerError, w) return } @@ -174,10 +174,10 @@ func PostUserAccount(env *Environment) http.HandlerFunc { id, err := env.DB.CreateUser(user.Username, user.Password, permission) if err != nil { if strings.Contains(err.Error(), "UNIQUE constraint failed") { - logErrorAndWriteResponse("user with given username already exists", http.StatusBadRequest, w) + writeError("user with given username already exists", http.StatusBadRequest, w) return } - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } w.Header().Set("Content-Type", "application/json") @@ -187,10 +187,10 @@ func PostUserAccount(env *Environment) http.HandlerFunc { response, err = json.Marshal(map[string]any{"id": id, "password": user.Password}) } if err != nil { - logErrorAndWriteResponse("Error marshaling response", http.StatusInternalServerError, w) + writeError("Error marshaling response", http.StatusInternalServerError, w) } if _, err := w.Write(response); err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) } } } @@ -203,26 +203,26 @@ func DeleteUserAccount(env *Environment) http.HandlerFunc { user, err := env.DB.RetrieveUser(id) if err != nil { if !errors.Is(err, db.ErrIdNotFound) { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } } if user.Permissions == 1 { - logErrorAndWriteResponse("deleting an Admin account is not allowed.", http.StatusBadRequest, w) + writeError("deleting an Admin account is not allowed.", http.StatusBadRequest, w) return } insertId, err := env.DB.DeleteUser(id) if err != nil { if errors.Is(err, db.ErrIdNotFound) { - logErrorAndWriteResponse(err.Error(), http.StatusNotFound, w) + writeError(err.Error(), http.StatusNotFound, w) return } - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } w.WriteHeader(http.StatusAccepted) if _, err := w.Write([]byte(strconv.FormatInt(insertId, 10))); err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) } } } @@ -233,25 +233,25 @@ func ChangeUserAccountPassword(env *Environment) http.HandlerFunc { if id == "me" { claims, err := getClaimsFromAuthorizationHeader(r.Header.Get("Authorization"), env.JWTSecret) if err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusUnauthorized, w) + writeError(err.Error(), http.StatusUnauthorized, w) } userAccount, err := env.DB.RetrieveUserByUsername(claims.Username) if err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusUnauthorized, w) + writeError(err.Error(), http.StatusUnauthorized, w) } id = strconv.Itoa(userAccount.ID) } var user db.User if err := json.NewDecoder(r.Body).Decode(&user); err != nil { - logErrorAndWriteResponse("Invalid JSON format", http.StatusBadRequest, w) + writeError("Invalid JSON format", http.StatusBadRequest, w) return } if user.Password == "" { - logErrorAndWriteResponse("Password is required", http.StatusBadRequest, w) + writeError("Password is required", http.StatusBadRequest, w) return } if !validatePassword(user.Password) { - logErrorAndWriteResponse( + writeError( "Password must have 8 or more characters, must include at least one capital letter, one lowercase letter, and either a number or a symbol.", http.StatusBadRequest, w, @@ -261,15 +261,15 @@ func ChangeUserAccountPassword(env *Environment) http.HandlerFunc { ret, err := env.DB.UpdateUser(id, user.Password) if err != nil { if errors.Is(err, db.ErrIdNotFound) { - logErrorAndWriteResponse(err.Error(), http.StatusNotFound, w) + writeError(err.Error(), http.StatusNotFound, w) return } - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) return } w.WriteHeader(http.StatusOK) if _, err := w.Write([]byte(strconv.FormatInt(ret, 10))); err != nil { - logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + writeError(err.Error(), http.StatusInternalServerError, w) } } } diff --git a/internal/server/handlers_users_test.go b/internal/server/handlers_users_test.go index 92c2c93..dd0d06d 100644 --- a/internal/server/handlers_users_test.go +++ b/internal/server/handlers_users_test.go @@ -32,7 +32,7 @@ func TestNotaryUsersHandlers(t *testing.T) { } env := &server.Environment{} env.DB = testdb - ts := httptest.NewTLSServer(server.NewRouter(env)) + ts := httptest.NewTLSServer(server.NewHandler(env)) defer ts.Close() client := ts.Client() diff --git a/internal/server/middleware.go b/internal/server/middleware.go index b05c239..3585dfe 100644 --- a/internal/server/middleware.go +++ b/internal/server/middleware.go @@ -28,9 +28,9 @@ type middlewareContext struct { firstAccountIssued bool } -// The responseWriterCloner struct wraps the http.ResponseWriter struct, and extracts the status +// The statusRecorder struct wraps the http.ResponseWriter struct, and extracts the status // code of the response writer for the middleware to read -type responseWriterCloner struct { +type statusRecorder struct { http.ResponseWriter statusCode int } @@ -38,12 +38,12 @@ type responseWriterCloner struct { // newResponseWriter returns a new ResponseWriterCloner struct // it returns http.StatusOK by default because the http.ResponseWriter defaults to that header // if the WriteHeader() function is never called. -func newResponseWriter(w http.ResponseWriter) *responseWriterCloner { - return &responseWriterCloner{w, http.StatusOK} +func newResponseWriter(w http.ResponseWriter) *statusRecorder { + return &statusRecorder{w, http.StatusOK} } // WriteHeader overrides the ResponseWriter method to duplicate the status code into the wrapper struct -func (rwc *responseWriterCloner) WriteHeader(code int) { +func (rwc *statusRecorder) WriteHeader(code int) { rwc.statusCode = code rwc.ResponseWriter.WriteHeader(code) } @@ -114,17 +114,17 @@ func authMiddleware(ctx *middlewareContext) middleware { } claims, err := getClaimsFromAuthorizationHeader(r.Header.Get("Authorization"), ctx.jwtSecret) if err != nil { - logErrorAndWriteResponse(fmt.Sprintf("auth failed: %s", err.Error()), http.StatusUnauthorized, w) + writeError(fmt.Sprintf("auth failed: %s", err.Error()), http.StatusUnauthorized, w) return } if claims.Permissions == UserPermission { requestAllowed, err := AllowRequest(claims, r.Method, r.URL.Path) if err != nil { - logErrorAndWriteResponse(fmt.Sprintf("error processing path: %s", err.Error()), http.StatusInternalServerError, w) + writeError(fmt.Sprintf("error processing path: %s", err.Error()), http.StatusInternalServerError, w) return } if !requestAllowed { - logErrorAndWriteResponse("forbidden", http.StatusForbidden, w) + writeError("forbidden", http.StatusForbidden, w) return } } diff --git a/internal/server/response.go b/internal/server/response.go index 2e61db3..4c784b0 100644 --- a/internal/server/response.go +++ b/internal/server/response.go @@ -6,8 +6,8 @@ import ( "net/http" ) -// logErrorAndWriteResponse is a helper function that logs any error and writes it back as an http response -func logErrorAndWriteResponse(msg string, status int, w http.ResponseWriter) { +// writeError is a helper function that logs any error and writes it back as an http response +func writeError(msg string, status int, w http.ResponseWriter) { errMsg := fmt.Sprintf("error: %s", msg) log.Println(errMsg) w.WriteHeader(status) diff --git a/internal/server/router.go b/internal/server/router.go index d3156c5..e04de95 100644 --- a/internal/server/router.go +++ b/internal/server/router.go @@ -6,10 +6,10 @@ import ( "github.com/canonical/notary/internal/metrics" ) -// NewRouter takes in an environment struct, passes it along to any handlers that will need +// NewHandler takes in an environment struct, passes it along to any handlers that will need // access to it, and takes an http.Handler that will be used to handle metrics. // then builds and returns it for a server to consume -func NewRouter(env *Environment) http.Handler { +func NewHandler(env *Environment) http.Handler { apiV1Router := http.NewServeMux() apiV1Router.HandleFunc("GET /certificate_requests", GetCertificateRequests(env)) apiV1Router.HandleFunc("POST /certificate_requests", PostCertificateRequest(env)) diff --git a/internal/server/server.go b/internal/server/server.go index cf70b92..23bf9a8 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -55,7 +55,7 @@ func NewServer(port int, cert []byte, key []byte, dbPath string, pebbleNotificat env.DB = db env.SendPebbleNotifications = pebbleNotificationsEnabled env.JWTSecret = jwtSecret - router := NewRouter(env) + router := NewHandler(env) s := &http.Server{ Addr: fmt.Sprintf(":%d", port),