Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Antonio Villanueva Test Restful Server
- package main
- import (
- "net/http"
- //go get github.com/gin-gonic/gin
- "github.com/gin-gonic/gin"
- )
- // Type Structure représentant un salarié
- type employe struct {
- ID int `json:"id"`
- Prenom string `json:"prenom"`
- Nom string `json:"nom"`
- Job string `json:"job"`
- }
- // employés de l'entreprise []
- var employees = []employe{
- {ID:1, Prenom:"Tony", Nom:"Villanueva", Job:"développeur"},
- {ID:2,Prenom:"Gilles", Nom:"Pignatta", Job:"développeur"},
- {ID:3,Prenom:"Frank", Nom:"Clerissi", Job:"chargé d'affaires"},
- {ID:4,Prenom:"Alex", Nom:"Zucarelli", Job:"designer"},
- {ID:5,Prenom:"Damien ", Nom:"LeGoffre", Job:"technique"},
- }
- //Requête GET http://localhost;8080/employees renvoie la liste des employés au format JSON
- func getEmployees(c *gin.Context) {
- c.IndentedJSON(http.StatusOK, employees)
- }
- //Requête GET http://localhost;8080/
- func getDefault(c *gin.Context) {
- c.IndentedJSON(http.StatusOK, "Icaro Restful web")
- }
- func main() {
- router := gin.Default()
- router.GET("/employees", getEmployees)
- router.GET("/", getDefault)
- router.Run("localhost:8080")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement