Skip to content

Instantly share code, notes, and snippets.

@geosoft1
Last active January 2, 2020 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geosoft1/77099cec979024b3999f8cbda266b4e0 to your computer and use it in GitHub Desktop.
Save geosoft1/77099cec979024b3999f8cbda266b4e0 to your computer and use it in GitHub Desktop.
Simple RESTful pipeline
package main
import (
"fmt"
"io"
"io/ioutil"
"net/http"
)
/*
curl -i -X PUT localhost:8080 -d 'a'
curl -i -X GET localhost:8080
*/
var messages = make(chan string, 3)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.Method, r.Host)
switch r.Method {
case "GET":
io.WriteString(w, <-messages)
case "PUT":
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return
}
messages <- string(body)
}
})
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment