login.html
复制代码 代码如下:
<html>
<head><title></title></head>
<body>
<form action="http://localhost:9090/login" method="post">
用户名:<input type="text" name="username">
密 码:<input type="text" name="password">
<input type="submit" value="登录">
</form>
</body>
</html>
main.go
复制代码 代码如下:
package main
import (
"fmt"
"html/template"
"log"
"net/http"
"strings"
)
func sayHelloName(w http.ResponseWriter, r *http.Request) {
// 解析url传递的参数
r.ParseForm()
//在服务端打印信息
fmt.Println(r.Form)
fmt.Println("path", r.URL.Path)
fmt.Println("Scheme", r.URL.Scheme)
fmt.Println(r.Form["url_long"])
for k, v := range r.Form {
fmt.Println("key:", k)
// join() 方法用于把数组中的所有元素放入一个字符串。
// 元素是通过指定的分隔符进行分隔的
fmt.Println("val:", strings.Join(v, ""))
}
// 输出到客户端
fmt.Fprintf(w, "hello astaxie!")
}
func login(w http.ResponseWriter, r *http.Request) {
fmt.Println("method:", r.Method)
if r.Method == "GET" {
t, _ := template.ParseFiles("login.html")
// 执行解析模板
// func (t *Template) Execute(wr io.Writer, data interface{}) error {
t.Execute(w, nil)
} else {
r.ParseForm()
fmt.Println("username:", r.Form["username"])
fmt.Println("password:", r.Form["password"])
}
}
func main() {
//设置访问路由
http.HandleFunc("/", sayHelloName)
http.HandleFunc("/login", login)
//设置监听端口
err := http.ListenAndServe(":9090", nil)
if err != nil {
log.Fatal("ListenAndserve:", err)
}
}
以上所述就是本文的全部内容了,希望大家能够喜欢。
go语言,表单
更新日志
- 罗斯特洛波维奇、布里顿《舒伯特-阿佩乔尼奏鸣曲》1995[WAV+CUE]
- 群星《超高品质流行女声大碟 静听女人心 2CD》[WAV+CUE][1.3GB]
- BEYOND《无悔这一生 2023》 [WAV+CUE][690MB]
- 群星《30首最发烧经典老歌 情牵男人心 2CD》[WAV+CUE][1.4GB]
- 群星《不老的情歌-至尊版2CD》WAV分轨
- 岁月留声机群星《七十年代人金曲回顾》(黑胶)2CD[WAV分轨]
- 群星-世纪难忘金曲(迪安唱片)5CD[WAV]
- HenrietteFaure-DebussyEstampesPrludes,LivreI(MonoVersion)[FLAC]
- 吕方1992-弯弯十八首[香港][WAV+CUE]
- 经典歌曲珍藏专辑《民歌30年·真情依旧》3CD[WAV+CUE]
- 群星《时尚流行发烧极品 非同凡响 第一辑 2CD》[WAV/分轨][1.3GB]
- 陈曦《多年以后》HQⅡ头版限量编号[WAV+CUE][520MB]
- 孙露《用情 HQⅡ 2023》[WAV+CUE][380MB]
- 电影原声《速度与激情9电影原声大碟》2021[WAV+CUE]
- 【瑞鸣音乐】群星《伶歌》[XRCD2][WAV+CUE]