Created
January 20, 2023 20:09
-
-
Save disegmvm/199eb6a726a8eef0ab836c0db01c9e9d to your computer and use it in GitHub Desktop.
Declaring slice of car structs you’ll use to start.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
type Car struct { | |
ID string `json:"id"` | |
Title string `json:"title"` | |
Color string `json:"color"` | |
} | |
var Cars []Car | |
func main() { | |
Cars = []Car{ | |
{ID: "1", Title: "BMW", Color: "Black"}, | |
{ID: "2", Title: "Tesla", Color: "Red"}, | |
} | |
router := gin.Default() | |
router.GET("/cars", getCars) | |
router.GET("/cars/:id", getCarByID) | |
router.POST("/cars", createCar) | |
router.DELETE("/cars/:id", deleteCar) | |
router.Run("localhost:8080") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment