Updated handler package

This commit is contained in:
phoenix
2025-10-22 22:48:22 -04:00
parent bbecbdb723
commit d0158d108e
3 changed files with 30 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
package handler
import "net/http"
func DraftMessageHandler(w http.ResponseWriter, r *http.Request) {
da := MessageItem{
Id: 1,
Message: "The Word",
}
RespondWithJSON(w, http.StatusOK, da)
}
+3
View File
@@ -0,0 +1,3 @@
package handler
const MESSAGE_DRAFT_ENDPOINT = "/api/v1/message/draft"
+15
View File
@@ -0,0 +1,15 @@
package handler
import "encoding/json"
import "log"
import "net/http"
// Helper function to send JSON responses
func RespondWithJSON(w http.ResponseWriter, statusCode int, data interface{}) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(statusCode)
if err := json.NewEncoder(w).Encode(data); err != nil {
log.Printf("Error encoding JSON: %v", err)
}
}