diff --git a/controllers/postController.go b/controllers/postController.go index 5a03866..839b37b 100644 --- a/controllers/postController.go +++ b/controllers/postController.go @@ -25,8 +25,19 @@ func PostsCreate(c *gin.Context) { } //Return it - c.JSON(200, gin.H{ "post": post, }) } + +func PostsIndex(c *gin.Context) { + // Get the post + var posts []models.Post + initializers.DB.Find(&posts) + + // Respond with them + c.JSON(200, gin.H{ + "posts": posts, + }) + +} diff --git a/go-crud b/go-crud deleted file mode 100755 index 8389744..0000000 Binary files a/go-crud and /dev/null differ diff --git a/main.go b/main.go index 940d37b..1196c19 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ func main() { r := gin.Default() r.POST("/posts", controllers.PostsCreate) + r.GET("/posts", controllers.PostsIndex) r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080") }