Files
svg-templater/internal/routes/get.go
T
tueem b378f30c05
build / Go-Build (pull_request) Successful in 1m26s
build / Go-Build (push) Successful in 1m26s
feat(svg): add GET endpoint for all svg templates
2026-05-18 14:41:25 +02:00

40 lines
735 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
}
*/
w.Header().Add("Content-Type", "application/json")
enc := json.NewEncoder(w)
for _, svg := range svgs {
enc.Encode(svg)
}
}