Initial commit & PoC
Read JSON from POST requests and create blog post structure. This will be stored persistently later.
This commit is contained in:
commit
c164a26607
|
@ -0,0 +1,38 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"log"
|
||||
)
|
||||
|
||||
var messages []*string
|
||||
|
||||
func main() {
|
||||
//listener, err = net.Listen("socket", "/tmp/
|
||||
http.HandleFunc("/", get)
|
||||
http.HandleFunc("/add", post)
|
||||
log.Fatal(http.ListenAndServe(":12345", nil))
|
||||
}
|
||||
|
||||
type BlogPost struct {
|
||||
Message string `"message"`
|
||||
Title string `"title"`
|
||||
Secret string `"secret"`
|
||||
}
|
||||
|
||||
func get(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("response:"))
|
||||
for _, m := range messages {
|
||||
w.Write([]byte(*m))
|
||||
}
|
||||
}
|
||||
|
||||
func post(w http.ResponseWriter, r *http.Request) {
|
||||
var post BlogPost
|
||||
json.NewDecoder(r.Body).Decode(&post)
|
||||
fmt.Println(post.Message)
|
||||
messages = append(messages, &post.Message)
|
||||
}
|
Loading…
Reference in New Issue
Block a user