1234567891011121314151617181920212223242526272829303132333435363738 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package v1
- import "git.getensh.com/common/gopkgsv2/database"
- type UserModel interface {
- Info(username string) (*User, error)
- }
- type User struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- Username string `gorm:"column:username" json:"username" form:"username"`
- Password string `gorm:"column:password" json:"password" form:"password"`
- Status int64 `gorm:"column:status" json:"status" form:"status"`
- }
- type defaultUserModel struct {
- tableName string
- fields string
- }
- func NewUserModel() UserModel {
- return &defaultUserModel{
- "t_user",
- "id, username, password, status",
- }
- }
- func (d *defaultUserModel) Info(username string) (*User, error) {
- var res User
- err := database.Get(database.DB().Where("username = ?", username), &res, database.Option{
- TableName: d.tableName,
- Fields: d.fields,
- })
- return &res, err
- }
|