-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
37 lines (31 loc) · 778 Bytes
/
main.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
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
type book struct {
ID string `json:"id"`
Title string `json:"title"`
Author string `json:"author"`
Quantity int `json:"quantity"`
}
var books = []book{
{ID: "1", Title: "Search of Lost Time", Author: "Marcel Proust", Quantity:2},
{ID: "2", Title: "Great Gatsby", Author: "Scott Fitzgerald", Quantity:5},
{ID: "3", Title: "Atomic Habits", Author: "James Clear", Quantity:9},
}
// get Request
func getBooks(c *gin.Context){
c.IndentedJSON(http.StatusOK, books)
}
// func createBook(c *gin.Context){
// var newBook book
// if err := c.BindJSON(&newBook); err != nil {
// return
// }
// }
func main(){
router := gin.Default()
router.GET("/books" , getBooks)
router.Run("localhost:8080")
}