golang The system cannot find the path specified.

前端之家收集整理的这篇文章主要介绍了golang The system cannot find the path specified.前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

指定的路径有误

  1. package main
  2.  
  3. import (
  4. "net/http"
  5. "fmt"
  6. "strings"
  7. "log"
  8. "html/template"
  9. )
  10.  
  11. func sayHelloName(w http.ResponseWriter,r *http.Request) {
  12. r.ParseForm();
  13. fmt.Println(r.Form)
  14. fmt.Println(r.URL.Path)
  15. fmt.Println(r.URL.Scheme)
  16. fmt.Println(r.Form["url_long"])
  17. for k,v:= range r.Form{
  18. fmt.Println("key: ",k)
  19. fmt.Println("value:",strings.Join(v,""))
  20. }
  21. fmt.Fprintln(w,"hello nihao")
  22.  
  23. }
  24.  
  25. func login(w http.ResponseWriter,r *http.Request) {
  26. fmt.Println("method: ",r.Method)
  27. if r.Method == "GET" {
  28. t,err := template.ParseFiles("src/html/login.gtpl")
  29. if err != nil {
  30. fmt.Println(err)
  31. return
  32. }
  33. t.Execute(w,nil)
  34. } else {
  35. fmt.Println("username: ",r.Form["username"])
  36. fmt.Println("password: ",r.Form["password"])
  37. }
  38. }
  39. func main() {
  40. //http.HandleFunc("/",sayHelloName);
  41. http.HandleFunc("/login",login)
  42. err:= http.ListenAndServe(":9090",nil)
  43. if err != nil {
  44. log.Fatalf("Listen and server",err)
  45. }
  46. }

猜你在找的Go相关文章