Advertisement
Guest User

Untitled

a guest
Jun 14th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.05 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "html/template"
  6.     "net/http"
  7. )
  8.  
  9. var tpl *template.Template
  10.  
  11. func init() {
  12.     tpl = template.Must(template.ParseGlob("templates/*.gohtml"))
  13. }
  14.  
  15. func main() {
  16.     http.HandleFunc("/", foo)
  17.     http.HandleFunc("/bar", bar)
  18.     http.Handle("/favicon.ico", http.NotFoundHandler())
  19.     http.ListenAndServe(":8080", nil)
  20. }
  21.  
  22. func foo(res http.ResponseWriter, req *http.Request) {
  23.     fmt.Print("Your request method at foo: ", req.Method)
  24. }
  25.  
  26. func bar(res http.ResponseWriter, req *http.Request) {
  27.     fmt.Println("Your request method at bar: ", req.Method)
  28.     http.Redirect(res, req, "/", http.StatusMovedPermanently)
  29. }
  30.  
  31. /* html
  32. <html>
  33.   <head>
  34.   </head>
  35.   <body>
  36.     <form method="POST" action="/bar">
  37.       <input type="text" name="fname" title="fname">
  38.       <input type="submit">
  39.     </form>
  40.   </body>
  41. </html>
  42. */
  43.  
  44. // go to localhost:8080/bar
  45. // fill up form
  46.  
  47. //Your request method at bar: GET
  48. //Your request method at foo: GET
  49.  
  50. //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