Skip to content

Instantly share code, notes, and snippets.

@gaku3601
Created October 21, 2019 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaku3601/c9180f43f682d16d8e2cc455728dc3cc to your computer and use it in GitHub Desktop.
Save gaku3601/c9180f43f682d16d8e2cc455728dc3cc to your computer and use it in GitHub Desktop.
golang orm
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