29 lines
643 B
Go
29 lines
643 B
Go
package main
|
|
|
|
import "net/http"
|
|
import "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: "1", Title: "Blue Train", Artist: "John Coltrane", Price: 56.99},
|
|
{Id: "2", Title: "Jeru", Artist: "Gerry Mulligan", Price: 17.99},
|
|
{Id: "3", Title: "Sarah Vaughan and Clifford Brown", Artist: "Sarah Vaughan", Price: 39.99},
|
|
}
|
|
|
|
func getAlbums(c *gin.Context) {
|
|
c.JSON(http.StatusOK, albums)
|
|
}
|
|
|
|
func main() {
|
|
router := gin.Default()
|
|
router.GET("/albums", getAlbums)
|
|
|
|
router.Run("localhost:4500")
|
|
}
|