Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "html/template"
- "net/http"
- )
- var tpl *template.Template
- func init() {
- tpl = template.Must(template.ParseGlob("templates/*.gohtml"))
- }
- func main() {
- http.HandleFunc("/", foo)
- http.HandleFunc("/bar", bar)
- http.Handle("/favicon.ico", http.NotFoundHandler())
- http.ListenAndServe(":8080", nil)
- }
- func foo(res http.ResponseWriter, req *http.Request) {
- fmt.Print("Your request method at foo: ", req.Method)
- }
- func bar(res http.ResponseWriter, req *http.Request) {
- fmt.Println("Your request method at bar: ", req.Method)
- http.Redirect(res, req, "/", http.StatusMovedPermanently)
- }
- /* html
- <html>
- <head>
- </head>
- <body>
- <form method="POST" action="/bar">
- <input type="text" name="fname" title="fname">
- <input type="submit">
- </form>
- </body>
- </html>
- */
- // go to localhost:8080/bar
- // fill up form
- //Your request method at bar: GET
- //Your request method at foo: GET
- //Your request method at foo: GET browser atceras ka ir pernamaent moved tapec nav 2x bar get
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement