周威学Go从入门到放弃第十一篇(web服务器简易表单)

package main

import (
	. "fmt"
	"html/template"
	"log"
	"net/http"
)

func main() {
	http.HandleFunc("/", index)
	http.HandleFunc("/login", login)
	err := http.ListenAndServe(":8888", nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}

func index(response http.ResponseWriter, request *http.Request) {
	request.ParseForm()
	if request.Method == "GET" {
		t, err := template.ParseFiles("login.gtpl")
		log.Println(t.Execute(response, err))
	}
}

func login(response http.ResponseWriter, request *http.Request) {
	if request.Method == "POST" {
		request.ParseForm()
		for k, v := range request.Form {

			Println(k, v)

		}
	}
}

 






用户名: 密码:

 

你可能感兴趣的:(Go,GO语言学习)