Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ** controller
- type User struct { // example user fields
- gorm.Model
- Id int64
- Name string
- EncryptedPassword []byte
- Password string `sql:"-"`
- CreatedAt time.Time `gorm:"type:timestamp"`
- UpdatedAt time.Time `gorm:"type:timestamp"`
- DeletedAt time.Time `gorm:"type:timestamp"` // for soft delete
- }
- func (c App) Index() revel.Result {
- // user := []models.Users{}
- p := models.User{}
- res := c.Txn.First(&p)
- log.Printf("%+v", p)
- return c.RenderJSON(SendResponse{
- Status: http.StatusCreated,
- Message: "Success",
- Data: &res,
- })
- }
- **
- **Gorm.go
- func initDb(){
- var err error
- username := r.Config.StringDefault("newtry.mysql_cred_u", "root")
- password := r.Config.StringDefault("newtry.mysql_cred_p", "")
- Gdb, err = gorm.Open("mysql", username+":"+password+"@tcp(127.0.0.1:3306)/revelapi?charset=utf8&parseTime=True&loc=Local")
- if err != nil {
- panic(err)
- }
- Gdb.AutoMigrate(&models.User{})
- }
- **
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement