Created
May 13, 2014 03:56
-
-
Save StareIntoTheBeard/71f56a8f9c411034dac6 to your computer and use it in GitHub Desktop.
welp
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 ("net/http" ; "encoding/json"; "io"; "time"; "fmt") | |
type Message struct { | |
Name string | |
Endpoint string | |
Query string | |
Time string | |
} | |
type Construct struct { | |
Response http.ResponseWriter | |
Body string | |
} | |
var c chan Construct = make(chan Construct) | |
func log(res http.ResponseWriter, req *http.Request){ | |
fmt.Println("request: ", req) | |
fmt.Println() | |
fmt.Println("response: ", res) | |
fmt.Println("***********************************") | |
} | |
func respondWith() { | |
message := <- c | |
io.WriteString(message.Response, message.Body) | |
} | |
func channel(res http.ResponseWriter, str string){ | |
c <- Construct{res, str} | |
} | |
func hello(res http.ResponseWriter, req *http.Request) { | |
res.Header().Set( | |
"Content-Type", | |
"application/json", | |
) | |
m := Message{"Ping", string(req.URL.Path),string(req.URL.RawQuery), time.Now().String() } | |
b, _ := json.Marshal(m) | |
str := string(b) | |
go channel(res, str) | |
go log(res,req) | |
respondWith() | |
} | |
func main() { | |
http.HandleFunc("/hello", hello) | |
http.ListenAndServe(":9000", nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment