Refactored the code some more
This commit is contained in:
+2
-7
@@ -7,17 +7,12 @@ 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"
|
import "git.kundeng.us/phoenix/textsender-api/internal/handler"
|
||||||
|
|
||||||
type MessageItem struct {
|
|
||||||
Id int `json:"id"`
|
|
||||||
Message string `json:"message"`
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("textsender-api")
|
fmt.Println(config.APP_NAME)
|
||||||
|
|
||||||
http.HandleFunc(handler.MESSAGE_DRAFT_ENDPOINT, handler.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(config.PortString(), nil))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,13 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
const PORT = 8080
|
const PORT = 8080
|
||||||
|
|
||||||
|
const APP_NAME = "textsender-api"
|
||||||
|
|
||||||
|
func PortString() string {
|
||||||
|
portMessage := fmt.Sprintf(":%d", PORT)
|
||||||
|
|
||||||
|
return portMessage
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package handler
|
|||||||
|
|
||||||
import "net/http"
|
import "net/http"
|
||||||
|
|
||||||
|
import "git.kundeng.us/phoenix/textsender-api/internal/model"
|
||||||
|
|
||||||
func DraftMessageHandler(w http.ResponseWriter, r *http.Request) {
|
func DraftMessageHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
da := MessageItem{
|
da := model.MessageItem{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
Message: "The Word",
|
Message: "The Word",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
type MessageItem struct {
|
||||||
|
Id int `json:"id"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user