user.go 976 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package v1
  4. import "git.getensh.com/common/gopkgsv2/database"
  5. type UserModel interface {
  6. Info(username string) (*User, error)
  7. }
  8. type User struct {
  9. ID int64 `gorm:"column:id" json:"id" form:"id"`
  10. Username string `gorm:"column:username" json:"username" form:"username"`
  11. Password string `gorm:"column:password" json:"password" form:"password"`
  12. Status int64 `gorm:"column:status" json:"status" form:"status"`
  13. }
  14. type defaultUserModel struct {
  15. tableName string
  16. fields string
  17. }
  18. func NewUserModel() UserModel {
  19. return &defaultUserModel{
  20. "t_user",
  21. "id, username, password, status",
  22. }
  23. }
  24. func (d *defaultUserModel) Info(username string) (*User, error) {
  25. var res User
  26. err := database.Get(database.DB().Where("username = ?", username), &res, database.Option{
  27. TableName: d.tableName,
  28. Fields: d.fields,
  29. })
  30. return &res, err
  31. }