generated from templates/go-generic
Dan Anglin
7d0336d3db
Add the metadata endpoint so that clients can get the server's authorization and token endpoints. Changes: - Add a config object to allow administrators to configure the binding address, binding port and domain name. - Add a target in the magefiles and a step in the CI workflow to run go vet. - Add the Dockerfile. - Replace the --address flag with the --config flag. - Add the metadata endpoint to the router to return a JSON document containing the URLs to the metadata and token endpoints.
22 lines
441 B
Go
22 lines
441 B
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log/slog"
|
|
"net/http"
|
|
)
|
|
|
|
func sendJSONResponse(w http.ResponseWriter, statusCode int, payload any) {
|
|
data, err := json.Marshal(payload)
|
|
if err != nil {
|
|
slog.Error("Error marshalling the response to JSON", "error", err.Error())
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
return
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(statusCode)
|
|
_, _ = w.Write(data)
|
|
}
|