Moved some code around
This commit is contained in:
+2
-20
@@ -1,11 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "encoding/json"
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
import "log"
|
import "log"
|
||||||
import "net/http"
|
import "net/http"
|
||||||
|
|
||||||
import "git.kundeng.us/phoenix/textsender-api/internal/config"
|
import "git.kundeng.us/phoenix/textsender-api/internal/config"
|
||||||
|
import "git.kundeng.us/phoenix/textsender-api/internal/handler"
|
||||||
|
|
||||||
type MessageItem struct {
|
type MessageItem struct {
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
@@ -16,26 +16,8 @@ type MessageItem struct {
|
|||||||
func main() {
|
func main() {
|
||||||
fmt.Println("textsender-api")
|
fmt.Println("textsender-api")
|
||||||
|
|
||||||
http.HandleFunc("/api/v1/message/draft", draftMessageHandler)
|
http.HandleFunc(handler.MESSAGE_DRAFT_ENDPOINT, handler.DraftMessageHandler)
|
||||||
|
|
||||||
log.Println("Starting server", config.PORT)
|
log.Println("Starting server", config.PORT)
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func draftMessageHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
da := MessageItem{
|
|
||||||
Id: 1,
|
|
||||||
Message: "The Word",
|
|
||||||
}
|
|
||||||
|
|
||||||
respondWithJSON(w, http.StatusOK, da)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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