Ai
681 Star 7.8K Fork 3.4K

陌溪/LearningNotes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 755 Bytes
一键复制 编辑 原始数据 按行查看 历史
陌溪 提交于 2020-09-17 18:38 +08:00 . docs:增加Gin框架学习笔记和代码
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func f1(w http.ResponseWriter, r *http.Request) {
index, err := ioutil.ReadFile("./index.html")
if err != nil {
w.Write([]byte(fmt.Sprintf("%v", err)))
}
w.Write([]byte(index))
}
func f2(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.URL)
fmt.Println(r.URL.Query()) // 识别URL中的参数
queryParams := r.URL.Query()
name := queryParams.Get("name")
age := queryParams.Get("age")
fmt.Println("传递来的name:", name)
fmt.Println("传递来的age:", age)
fmt.Println(r.Method)
fmt.Println(ioutil.ReadAll(r.Body))
}
func main() {
http.HandleFunc("/index", f1)
http.HandleFunc("/query", f2)
http.HandleFunc("/about", f1)
http.ListenAndServe("127.0.0.1:9090", nil)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/moxi159753/LearningNotes.git
git@gitee.com:moxi159753/LearningNotes.git
moxi159753
LearningNotes
LearningNotes
master

搜索帮助