38 lines
966 B
Go
38 lines
966 B
Go
package main
|
|
|
|
import "fmt"
|
|
import "log"
|
|
import "net/http"
|
|
import "io/ioutil"
|
|
|
|
// import "github.com/davecgh/go-spew/spew"
|
|
|
|
func handler(w http.ResponseWriter, r *http.Request) {
|
|
// spew.Dump(r)
|
|
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
|
|
log.Printf("handler: fucking unknown path")
|
|
}
|
|
|
|
func main() {
|
|
log.Println("listen on :9000")
|
|
|
|
http.HandleFunc("/", handler)
|
|
http.HandleFunc("/email", handler2)
|
|
|
|
http.ListenAndServe(":9000", nil)
|
|
}
|
|
|
|
func handler2(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
|
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
|
|
|
|
// spew.Dump(r)
|
|
fmt.Fprintf(w, "Hi there, handler2 %s!", r.URL.Path[1:])
|
|
|
|
body, err := ioutil.ReadAll(r.Body)
|
|
j := string(body)
|
|
log.Println("body =", j)
|
|
log.Println("err =", err)
|
|
}
|