Created
April 17, 2019 08:56
-
-
Save evangwt/b371a7bdd7e1bee56ed89efd5654ba2d to your computer and use it in GitHub Desktop.
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 model | |
import ( | |
"strings" | |
uuid "github.com/satori/go.uuid" | |
) | |
// BaseUUID auto gen uuid xorm base model | |
type BaseUUID struct { | |
Id string `xorm:"pk not null 'id'" json:"id"` | |
} | |
// BeforeInsert auto gen uuid while id is empty | |
func (b *BaseUUID) BeforeInsert() { | |
if len(b.Id) == 0 { | |
id, _ := uuid.NewV4() | |
b.Id = strings.Replace(id.String(), "-", "", -1) | |
} | |
} | |
// MyTable BaseUUID usage | |
type MyTable struct { | |
BaseUUID `xorm:"extends"` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment