Skip to content

Instantly share code, notes, and snippets.

@jaymecd
Forked from abdullin/main.go
Last active August 29, 2015 14:16
Show Gist options
  • Save jaymecd/e44636a7b895ba91e7cd to your computer and use it in GitHub Desktop.
Save jaymecd/e44636a7b895ba91e7cd to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
)
var queue chan string
var joblist []string
func init() {
queue = make(chan string, 10)
joblist = make([]string, 0)
}
func handler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "POST":
val := r.PostFormValue("job")
fmt.Fprintln(w, "VALUE: ", val)
queue <- val
case "GET":
fmt.Fprintln(w, joblist)
default:
fmt.Fprintf(w, "Not supported")
}
}
func projection() {
for req := range queue {
joblist = append(joblist, req)
}
}
func main() {
go projection()
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment