Advertisement
Guest User

Untitled

a guest
Apr 12th, 2019
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ** controller
  2. type User struct { // example user fields
  3.     gorm.Model
  4.     Id                int64
  5.     Name              string
  6.     EncryptedPassword []byte
  7.     Password          string    `sql:"-"`
  8.     CreatedAt         time.Time `gorm:"type:timestamp"`
  9.     UpdatedAt         time.Time `gorm:"type:timestamp"`
  10.     DeletedAt         time.Time `gorm:"type:timestamp"` // for soft delete
  11. }
  12.  
  13. func (c App) Index() revel.Result {
  14.     // user := []models.Users{}
  15.  
  16.     p := models.User{}
  17.     res := c.Txn.First(&p)
  18.  
  19.     log.Printf("%+v", p)
  20.     return c.RenderJSON(SendResponse{
  21.         Status:  http.StatusCreated,
  22.         Message: "Success",
  23.         Data:    &res,
  24.     })
  25. }
  26. **
  27.  
  28. **Gorm.go
  29. func initDb(){
  30.     var err error
  31.     username := r.Config.StringDefault("newtry.mysql_cred_u", "root")
  32.     password := r.Config.StringDefault("newtry.mysql_cred_p", "")
  33.  
  34.     Gdb, err = gorm.Open("mysql", username+":"+password+"@tcp(127.0.0.1:3306)/revelapi?charset=utf8&parseTime=True&loc=Local")
  35.     if err != nil {
  36.         panic(err)
  37.     }
  38.     Gdb.AutoMigrate(&models.User{})
  39. }
  40. **
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement