Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 53 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top