File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,22 @@ func addUser(c *gin.Context) {
57
57
58
58
}
59
59
60
+ // / getAlbumByID locates the album whose ID value matches the id
61
+ // parameter sent by the client, then returns that album as a response.
62
+ func getUserByID (c * gin.Context ) {
63
+ id := c .Param ("id" )
64
+
65
+ // Loop over the list of albums, looking for
66
+ // an album whose ID value matches the parameter.
67
+ for _ , a := range users {
68
+ if a .ID == id {
69
+ c .JSON (http .StatusOK , a )
70
+ return
71
+ }
72
+ }
73
+ c .IndentedJSON (http .StatusNotFound , gin.H {"message" : "user not found" })
74
+ }
75
+
60
76
func main () {
61
77
router := gin .Default ()
62
78
@@ -74,6 +90,7 @@ func main() {
74
90
router .GET ("/user/:name" , getUser )
75
91
router .GET ("/user" , getUsers )
76
92
router .POST ("/user" , addUser )
93
+ router .GET ("/userData/:id" , getUserByID )
77
94
78
95
router .Run (":3000" )
79
96
}
You can’t perform that action at this time.
0 commit comments