dc43921bcc
Introduces internal/api with Mount(), the {error:{code,message}}
response shape, and stubbed login/logout/me so later tasks can
land one handler at a time without breaking the build.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
26 lines
739 B
Go
26 lines
739 B
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
// errorBody is the JSON envelope for failures on /api/*. Kept separate from
|
|
// the Subsonic envelope so native clients don't have to parse two shapes.
|
|
type errorBody struct {
|
|
Error errorPayload `json:"error"`
|
|
}
|
|
|
|
type errorPayload struct {
|
|
Code string `json:"code"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// writeErr is the canonical way to emit a failure. Code is a stable
|
|
// short-string clients can switch on; message is human-readable.
|
|
func writeErr(w http.ResponseWriter, status int, code, message string) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(status)
|
|
_ = json.NewEncoder(w).Encode(errorBody{Error: errorPayload{Code: code, Message: message}})
|
|
}
|