Created
April 25, 2012 21:29
-
-
Save jaybill/2493596 to your computer and use it in GitHub Desktop.
Trailing slash forces GET method on request?
This file contains 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" | |
"log" | |
"fmt" | |
) | |
func route(pattern string, fn func(*http.Request) string){ | |
http.HandleFunc(pattern,makeHandler(fn)) | |
} | |
func makeHandler(fn func(*http.Request) (string)) http.HandlerFunc { | |
return func(w http.ResponseWriter, r *http.Request) { | |
log.Printf("Request method: %q",r.Method) // Method is always get, regardless of what request actually was | |
h := fn(r) | |
fmt.Fprintf(w,"Handler said: %q",h) | |
} | |
} | |
func helloHandler(r *http.Request) (view string){ | |
view = "Hello, World!" | |
return | |
} | |
func main(){ | |
route("/hello/",helloHandler) | |
log.Fatal(http.ListenAndServe(":8080", nil)) | |
} |
This file contains 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
<form action="http://localhost:8080/hello" method="post"> | |
<input type="hidden" name="testkey" val="testval"/> | |
<button type="submit">TEST</button> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment