This commit is contained in:
wyh 2021-07-19 15:08:26 +08:00
parent 00199743d3
commit ffa09a9337
4 changed files with 58 additions and 2 deletions

24
main.go
View File

@ -9,8 +9,28 @@ func main() {
// c.JSON(200, gin.H{
// "message": "pong",
// })
// c.HTML(200, "index.html", gin.H{})
c.String(200, "hello world", gin.H{})
c.HTML(200, "index.html", gin.H{})
// c.String(200, "hello world", gin.H{})
})
r.GET("/in", func(c *gin.Context) {
c.HTML(200, "data.html", gin.H{
"data": "vaefgood",
})
})
r.GET("form", func(c *gin.Context) {
c.HTML(200, "form.html", gin.H{})
})
r.POST("post", func(c *gin.Context) {
uname := c.PostForm("username")
c.JSON(200, gin.H{
"result": "ok",
"uname": uname,
})
})
r.GET("/user/:name", func(c *gin.Context) {
c.HTML(200, "name.html", gin.H{
"data": c.Param("name"),
})
})
r.Run() // listen and serve on 0.0.0.0:8080
}

11
template/data.html Normal file
View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>真不错</title>
</head>
<body>
{{.data}}
</body>
</html>

14
template/form.html Normal file
View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="/post" method="POST">
<input type="text" name="username" id="">
<input type="submit" value="提交">
</form>
</body>
</html>

11
template/name.html Normal file
View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>真不错</title>
</head>
<body>
hello {{.data}}
</body>
</html>