Please don’t rely on this Gitea instance being around forever. If any of your build scripts use my (kageru’s) projects hosted here, check my Github or IEW on Github for encoding projects. If you can’t find what you’re looking for there, tell me to migrate it.

Initial commit & PoC

Read JSON from POST requests and create blog post structure. This will
be stored persistently later.
dev
kageru 4 years ago
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…
Cancel
Save