运行报错
# command-line-arguments .\wwww.go:11:8: syntax error: unexpected :=, expecting name .\wwww.go:14:59: syntax error: unexpected type, expecting expression .\wwww.go:15:83: syntax error: unexpected type, expecting expression
把11行的type 改成type0就可以了
package main import "github.com/gin-gonic/gin" import "net/http" import "fmt" func main() { router:= gin.Default() //form router.POST("/form", func(c *gin.Context) { type0 := c.DefaultPostForm("type", "alert")//可设置默认值 msg := c.PostForm("msg") title := c.PostForm("title") fmt.Println("type is '%s', msg is '%s', title is '%s'", type0, msg, title) c.String(http.StatusOK, fmt.Sprintf("type is '%s', msg is '%s', title is '%s'", type0, msg, title)) }) router.Run(":8080") }
