gorm gen使用
1.安裝
git clone github.com/olongfen/gormgen
cd cmd/gormgen/
go build -o gormgen main.go
mv gormgen /usr/local/bin/
2.使用
在結構體模型加對應的注解,//go:generate
// 用戶Demo表
//go:generate gormgen -structs User -output user_gen.go
type User struct {
Id int32 // 主鍵
UserName string // 用戶名
NickName string // 昵稱
Mobile string // 手機號
IsDeleted int32 // 是否刪除 1:是 -1:否
CreatedAt time.Time `gorm:"time"` // 創建時間
UpdatedAt time.Time `gorm:"time"` // 更新時間
}
3.執行生成命令
go generate ./...
相關鏈接
https://my.oschina.net/olongfen/blog/4676482
github.com/MohamedBassem/gormgen
https://segmentfault.com/a/1190000039300764
http://www.systonsoft.com/article/237686.html
