Updated handler package
This commit is contained in:
@@ -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)
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
const MESSAGE_DRAFT_ENDPOINT = "/api/v1/message/draft"
|
||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user