SHARE
TWEET
Untitled
a guest
Sep 28th, 2018
93
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- package main
- import (
- "github.com/astaxie/beego/orm"
- "./models"
- "github.com/gin-gonic/gin"
- "net/http"
- )
- var ORM orm.Ormer
- func init() {
- models.ConnectToDb()
- ORM = models.GetOrmObject()
- }
- func main () {
- router := gin.Default()
- router.POST("/createShoe", createShoe)
- router.GET("/readShoes", readShoes)
- //router.PUT("/updateShoe", updateShoe)
- router.Run(":8080")
- }
- func createShoe(c *gin.Context) {
- var NewShoe models.Shoes
- c.BindJSON(&NewShoe)
- _, err := ORM.Insert(&NewShoe)
- if err == nil {
- c.JSON(http.StatusOK, gin.H{
- "status": http.StatusOK,
- "shoeName": NewShoe.Name,
- "trueToSizeData": NewShoe.TrueToSizeData,
- "trueToSizeCalc": NewShoe.TrueToSizeCalc})
- } else {
- c.JSON(http.StatusInternalServerError,
- gin.H{"status":http.StatusInternalServerError, "error":"Failed to create the entry"})
- }
- }
- func readShoes(c *gin.Context) {
- var shoe []models.Shoes
- _, err := ORM.QueryTable("Shoes").All(&shoe)
- if err == nil {
- c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "shoes":&shoe})
- } else {
- c.JSON(http.StatusInternalServerError,
- gin.H{"status": http.StatusInternalServerError, "error": "failed to read shoes"})
- }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
