Skip to content

Instantly share code, notes, and snippets.

@abdullin
Created December 16, 2013 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save abdullin/7984076 to your computer and use it in GitHub Desktop.
Save abdullin/7984076 to your computer and use it in GitHub Desktop.
Sample web server written in Go with Tom Janssens. Nobody had any real experience in go :)
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