1st commit

This commit is contained in:
Alfonso 2019-05-25 15:30:40 -07:00
parent 394abf0fc1
commit a698be5fad
1 changed files with 53 additions and 0 deletions

53
signup.go Normal file
View File

@ -0,0 +1,53 @@
package main
import "fmt"
import "log"
import "net/http"
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: unknown path")
}
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, "handler2 %s!", r.URL.Path[1:])
log.Printf("handler: method switch statement")
switch r.Method {
case http.MethodGet:
// Serve the resource.
log.Printf("handler2 GET")
case http.MethodPost:
// Create a new record.
log.Printf("handler2 POST")
case http.MethodPut:
// Update an existing record.
log.Printf("handler2 PUT")
case http.MethodDelete:
// Remove the record.
log.Printf("handler2 DELETE")
case http.MethodOptions:
// Remove the record.
log.Printf("handler2 OPTIONS")
default:
// Give an error message.
log.Printf("handler2 DEFAULT Method=", r.Method)
spew.Dump(r.Method)
}
}
func main() {
log.Println("listen on :9000")
http.HandleFunc("/", handler)
http.HandleFunc("/email", handler2)
http.ListenAndServe(":9000", nil)
}