udemy-go-microservices/broker-service/cmd/api/handlers.go
2024-08-28 09:28:34 +02:00

25 lines
487 B
Go

package main
import (
"encoding/json"
"net/http"
)
type jsonResponse struct {
Error bool `json:"error"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
func (app *Config) Broker(w http.ResponseWriter, r *http.Request) {
payload := jsonResponse{
Error: false,
Message: "Hit the broker",
}
out, _ := json.MarshalIndent(payload, "", "\t")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusAccepted)
w.Write(out)
}