-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (48 loc) · 1.42 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"example/web-service-gin/api"
"example/web-service-gin/database"
"example/web-service-gin/middleware"
"net/http"
"github.com/gin-gonic/gin"
)
type Album struct {
ID string `json:"id"`
Title string `json:"title"`
Artist string `json:"artist"`
Price float64 `json:"price"`
}
// var albums = []album{
// {ID: Helper.generateUID(), Title: "Blue Train", Artist: "John Coltrane", Price: 56.99},
// {ID: Helper.generateUID(), Title: "Jeru", Artist: "Gerry Mulligan", Price: 17.99},
// {ID: Helper.generateUID(), Title: "Sarah Vaughan and Clifford Brown", Artist: "Sarah Vaughan", Price: 39.99},
// }
func main() {
router := gin.Default()
router.Use(middleware.CORSMiddleware())
router.GET("/albums", api.GetAlbums)
router.POST("/albums", api.AddAlbums)
router.GET("/albums/:id", getAlbumByID)
database.ConnectDatabase()
router.Run("localhost:8080")
}
// func postAlbum(c *gin.Context) {
// var newAlbum album
// data, err := c.GetRawData()
// if err := c.BindJSON(&newAlbum); err != nil {
// return
// }
// newAlbum.ID = Helper.generateUID()
// albums = append(albums, newAlbum)
// c.IndentedJSON(http.StatusCreated, newAlbum)
// }
func getAlbumByID(c *gin.Context) {
// id := c.Param("id")
// for _, a := range albums {
// if a.ID == id {
// c.IndentedJSON(http.StatusOK, a)
// return
// }
// }
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "album not found"})
}