Skip to content

Commit 6733b03

Browse files
go api return array of object
1 parent c392065 commit 6733b03

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

gin-web-app/main.go

+18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import (
66
"github.com/gin-gonic/gin"
77
)
88

9+
// album represents data about a record album.
10+
type userDetail struct {
11+
ID string `json:"id"`
12+
Name string `json:"name"`
13+
Age int `json:"age"`
14+
}
15+
916
func helloCall(c *gin.Context) {
1017
c.JSON(http.StatusOK, gin.H{"message": "Hello, You created a Web App!"})
1118
}
@@ -22,6 +29,16 @@ func getUser(c *gin.Context) {
2229
c.JSON(http.StatusOK, gin.H{"message": "Hello, " + name + "!"})
2330
}
2431

32+
func getUsers(c *gin.Context) {
33+
var users = []userDetail{
34+
{ID: "1", Name: "Blue Train", Age: 56},
35+
{ID: "2", Name: "Akash", Age: 11},
36+
{ID: "3", Name: "pradip", Age: 56},
37+
}
38+
39+
c.JSON(http.StatusOK, users)
40+
}
41+
2542
func main() {
2643
router := gin.Default()
2744

@@ -37,6 +54,7 @@ func main() {
3754
// Add this route handler
3855
// with param
3956
router.GET("/user/:name", getUser)
57+
router.GET("/user", getUsers)
4058

4159
router.Run(":3000")
4260
}

0 commit comments

Comments
 (0)