Files
svg-templater/internal/routes/get.go
T
tueem 54a16fab4a
build / Go-Build (push) Failing after 13m5s
fix(get): answer with valid json array
2026-05-25 23:55:24 +02:00

31 lines
587 B
Go

package routes
import (
"encoding/json"
"net/http"
"tomatentum.net/svg-templater/internal/database"
)
func Get(w http.ResponseWriter, r *http.Request) {
svgs, err := database.GetSVG()
if err != nil {
http.Error(w, "Cannot fetch svgs from database", http.StatusInternalServerError)
return
}
data, err := json.Marshal(svgs)
if err != nil {
http.Error(w, "An Error occurred while encoding json.", http.StatusInternalServerError)
return
}
_, err = w.Write(data)
if err != nil {
http.Error(w, "Could not write data.", http.StatusInternalServerError)
return
}
}