windows下操作与视频中稍有不同,第一记得切换目录,切到router_assets目录下,然后 go build main.go,然后你就会看到生成的main.exe,然后再go build -o router_assets,然后你就会看到生成的router_assets文件,还打了一个问号,最后重点,window10下go build -o router_assets;.\main.exe就好了
2023-03-25
url -H "content-Type:application/json" -X POST "http://127.0.0.1:8080/testing" -d '{"name":"jack","address":"weifang","birthday":"2023-03-12T00:00:00Z"}'
{jack weifang 2023-03-12 00:00:00 +0000 UTC}%
{jack weifang 2023-03-12 00:00:00 +0000 UTC}%
2023-03-09
//获取post请求参数
func main() {
r := gin.Default()
r.POST("/test", func(c *gin.Context) {
firstName := c.PostForm("first_name")
lastName := c.DefaultPostForm("last_name", "defaultLastName")
c.String(http.StatusOK, "%s,%s", firstName, lastName)
})
r.Run(":80")
}
func main() {
r := gin.Default()
r.POST("/test", func(c *gin.Context) {
firstName := c.PostForm("first_name")
lastName := c.DefaultPostForm("last_name", "defaultLastName")
c.String(http.StatusOK, "%s,%s", firstName, lastName)
})
r.Run(":80")
}
2023-02-27
感觉自定义校验方法有些鸡肋,自己把业务逻辑校验都写到service层不就行了。自定义校验方法反而多写代码了,而且抛出的错误信息不易读,还得转换。
2022-05-07
测试的时候用127.0.0.1:8080/test就可以正常显示hello world, 用localhost:8080/test就会提示::1 is not in iplist
2021-12-23