Post Reqeust via HTML FORM GinGonic golang framework 11

Post Reqeust via HTML FORM GinGonic golang framework 11

 

 

Source Code

[sourcecode lang=”go” autolinks=”false” classname=”myclass” collapse=”false” firstline=”1″ gutter=”true” highlight=”1-3,6,9″ htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false” title=”Source Code main.go”]

// POST Request via HTML Form
package main
import "github.com/gin-gonic/gin"
func main() {
// create new router/server
r := gin.Default()
// register root folder for HTML Form file
r.Static("/", "./")
// post request
r.POST("/post", func(c *gin.Context) {
name := c.PostForm("name") // is the name of field
// send back data received or show success
c.String(200, "Hi %s", name)
// lets create html form
})
r.Run()
}
[/sourcecode]

Source Code – Index.html

[sourcecode]

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML POST REQ FORM</title>
</head>
<body>
<form action="/post" method="post">
<input type="text" name="name" id="">
<button type="submit">submit</button>
</form>
</body>
</html>

[/sourcecode]

 

TAGS#

gin gonic tutorial
gin-gonic / examples
gin-gonic documentation
gin framework tutorial
gin web framework
gin router
golang gin context
gin router group

Tony BB
 

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: