mirror of
https://github.com/GlueOps/autoglue.git
synced 2026-02-13 12:50:05 +01:00
feat: sdk migration in progress
This commit is contained in:
27
internal/utils/helpers.go
Normal file
27
internal/utils/helpers.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// ErrorResponse is a simple, reusable error payload.
|
||||
// swagger:model ErrorResponse
|
||||
type ErrorResponse struct {
|
||||
// A machine-readable error code, e.g. "validation_error"
|
||||
// example: validation_error
|
||||
Code string `json:"code"`
|
||||
// Human-readable message
|
||||
// example: slug is required
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func WriteJSON(w http.ResponseWriter, status int, v any) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
_ = json.NewEncoder(w).Encode(v)
|
||||
}
|
||||
|
||||
func WriteError(w http.ResponseWriter, status int, code, msg string) {
|
||||
WriteJSON(w, status, ErrorResponse{Code: code, Message: msg})
|
||||
}
|
||||
Reference in New Issue
Block a user