add mosis-portal Go project with package signing and validation
This commit is contained in:
35
portal/internal/api/handlers/handlers.go
Normal file
35
portal/internal/api/handlers/handlers.go
Normal file
@@ -0,0 +1,35 @@
|
||||
// Package handlers contains HTTP request handlers
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// ErrorResponse represents an API error response
|
||||
type ErrorResponse struct {
|
||||
Error string `json:"error"`
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
// NotImplemented returns a 501 Not Implemented response
|
||||
func NotImplemented(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusNotImplemented)
|
||||
json.NewEncoder(w).Encode(ErrorResponse{
|
||||
Error: "not_implemented",
|
||||
Message: "This endpoint is not yet implemented",
|
||||
})
|
||||
}
|
||||
|
||||
// JSON writes a JSON response with the given status code
|
||||
func JSON(w http.ResponseWriter, status int, data interface{}) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
json.NewEncoder(w).Encode(data)
|
||||
}
|
||||
|
||||
// Error writes a JSON error response
|
||||
func Error(w http.ResponseWriter, status int, err string, message string) {
|
||||
JSON(w, status, ErrorResponse{Error: err, Message: message})
|
||||
}
|
||||
Reference in New Issue
Block a user