chore(tfstated): refactor backend code to a dedicated package

This commit is contained in:
Julien Dessaux 2024-12-30 23:07:00 +01:00
parent 1dbb1b9ee7
commit 36e3d473f2
Signed by: adyxax
GPG key ID: F92E51B86E07177E
9 changed files with 60 additions and 36 deletions

22
pkg/backend/routes.go Normal file
View file

@ -0,0 +1,22 @@
package backend
import (
"net/http"
"git.adyxax.org/adyxax/tfstated/pkg/basic_auth"
"git.adyxax.org/adyxax/tfstated/pkg/database"
)
func addRoutes(
mux *http.ServeMux,
db *database.DB,
) {
mux.Handle("GET /healthz", handleHealthz())
basicAuth := basic_auth.Middleware(db)
mux.Handle("DELETE /", basicAuth(handleDelete(db)))
mux.Handle("GET /", basicAuth(handleGet(db)))
mux.Handle("LOCK /", basicAuth(handleLock(db)))
mux.Handle("POST /", basicAuth(handlePost(db)))
mux.Handle("UNLOCK /", basicAuth(handleUnlock(db)))
}