Skip to content

Commit 059439e

Browse files
authored
update main.go
1 parent b572ac3 commit 059439e

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

main.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,26 @@ import (
44
"net/http"
55
"github.com/gin-gonic/gin"
66
)
7-
func PostMethod(c *gin.Context) {
8-
fmt.Println("\napi.go 'PostMethod' called")
9-
message := "PostMethod called"
10-
c.JSON(http.StatusOK, message)
11-
}
127
func GetMethod(c *gin.Context) {
13-
fmt.Println("\napi.go 'GetMethod' called")
14-
message := "GetMethod called"
8+
fmt.Println("\n'GetMethod' called")
9+
IdValue := c.Params.ByName("IdValue")
10+
message := "GetMethod Called With Param: " + IdValue
1511
c.JSON(http.StatusOK, message)
12+
ReqPayload := make([]byte, 1024)
13+
ReqPayload, err := c.GetRawData()
14+
if err != nil {
15+
fmt.Println(err)
16+
return
17+
}
18+
fmt.Println("Request Payload Data: ", string(ReqPayload))
1619
}
1720
func main() {
1821
router := gin.Default()
22+
subRouterAuthenticated := router.Group("/api/v1/PersonId", gin.BasicAuth(gin.Accounts{
23+
"admin": "adminpass",
24+
}))
25+
subRouterAuthenticated.GET("/:IdValue", GetMethod)
26+
listenPort := "1357"
1927

20-
router.POST("/", PostMethod)
21-
router.GET("/", GetMethod)
22-
listenPort := "4000"
23-
router.Run(":"+listenPort)
28+
router.Run(":"+listenPort)
2429
}

0 commit comments

Comments
 (0)