Created
December 16, 2013 08:51
-
-
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 :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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