Created
October 21, 2019 07:12
-
-
Save gaku3601/c9180f43f682d16d8e2cc455728dc3cc to your computer and use it in GitHub Desktop.
golang orm
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 models | |
import ( | |
"github.com/gin-gonic/gin" | |
"github.com/jinzhu/gorm" | |
) | |
//Entry struct | |
type Entry struct { | |
ID int | |
UserID string `json:"user_id"` | |
ImageURL string `json:"image_url"` | |
Comment string `json:"comment"` | |
BodyWeight float32 `json:"body_weight"` | |
BodyFat float32 `json:"body_fat"` | |
IsPublic bool `json:"is_public"` | |
} | |
//CreateEntry create | |
func CreateEntry(c *gin.Context) { | |
var entry Entry | |
c.BindJSON(&entry) | |
entry.UserID = c.MustGet("UID").(string) | |
gdb, _ := c.MustGet("databaseConn").(*gorm.DB) | |
gdb.Create(&entry) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment