-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain_test.go
48 lines (36 loc) · 951 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"net/http"
"github.com/gin-gonic/gin"
about "github.com/krishpranav/gorestapi/api/aboutapi"
)
var aboutrestapi = []about.Aboutapi{
{App: "gorestapi", Author: "Krishpranav", Github: "https://github.com/krishpranav/gorestapi", Version: 2},
}
/* perform post request */
func maintest() {
router := gin.Default()
testapi := router.Group("/testapi")
{
router.GET("/test,", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "test",
})
})
router.GET("/aboutest", getAboutApi)
/* testapi router only for post functions */
testapi.POST("/aboutest", postAboutApi)
router.Run()
}
}
func getAboutApi(c *gin.Context) {
c.IndentedJSON(http.StatusOK, aboutrestapi)
}
func postAboutApi(c *gin.Context) {
var newAboutApi about.Aboutapi
if err := c.BindJSON(&newAboutApi); err != nil {
return
}
aboutrestapi = append(aboutrestapi, newAboutApi)
c.IndentedJSON(http.StatusCreated, newAboutApi)
}