package web import ( "encoding/json" "fmt" "net/http" "mokhan.ca/xlgmokha/idp/pkg/dto" "mokhan.ca/xlgmokha/idp/pkg/tasks" ) func (h *HttpContext) Register(w http.ResponseWriter, r *http.Request) { var request dto.ClientRegistrationRequest json.NewDecoder(r.Body).Decode(&request) if response, err := tasks.CreateClient(request); err != nil { w.WriteHeader(http.StatusBadRequest) w.Header().Set("Content-Type", "application/json") w.Header().Set("Cache-Control", "no-store") w.Header().Set("Pragma", "no-cache") fmt.Fprintf(w, `{"error":"%s","error_description":"%s"}`, err.Error(), err.Error()) } else { w.WriteHeader(http.StatusCreated) w.Header().Set("Content-Type", "application/json") w.Header().Set("Cache-Control", "no-store") w.Header().Set("Pragma", "no-cache") json.NewEncoder(w).Encode(response) } }