model

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JsonMarshal

func JsonMarshal(v interface{}) (str string)

将数据序列化为JSON字符串

func SendError

func SendError(w http.ResponseWriter)

func SendResult

func SendResult(w http.ResponseWriter, data interface{}, err error)

输出返回结果

Types

type Base

type Base struct {
	ID        uint64     `gorm:"primary_key;AUTO_INCREMENT;column:id" json:"id" valid:"-"`
	CreatedAt time.Time  `gorm:"column:createdAt" json:"createdAt" valid:"-"`
	UpdatedAt time.Time  `gorm:"column:updatedAt" json:"updatedAt" valid:"-"`
	DeletedAt *time.Time `gorm:"column:deletedAt" sql:"index" json:"deletedAt" valid:"-"`
}

type Error

type Error struct {
	// The general error message
	Error string `json:"error"`

	// The http error code.
	ErrorCode int `json:"error_code"`

	// The http error code.
	ErrorDescription string `json:"error_description"`
}

The Error contains error relevant information.

type QueryParam

type QueryParam struct {
	Fields string
	Offset int
	Limit  int
	Order  string
	Where  []WhereParam
}

type Result

type Result struct {
	Code    int         `json:"code"`    // return code, 0 for succ
	Message string      `json:"message"` // message
	Data    interface{} `json:"data"`    // data object
}

Result represents HTTP response body.

type Token

type Token struct {
	Base

	Raw    string `gorm:"type:varchar(100);column:username;not null" json:"username"`
	User   User   `gorm:"save_associations:false"" json:"user"`
	UserID uint   `json:"user_id"`
}

type User

type User struct {
	Base

	Username string `gorm:"type:varchar(100);column:username;not null" json:"username" valid:"-"`
	Password string `gorm:"type:varchar(50);column:password;not null" json:"password" valid:"-"`
	Email    string `gorm:"type:varchar(100);column:email;unique;not null;" json:"email" valid:"email"`
}

创建一个User数据模型

func UserFrom

func UserFrom(str string) (*User, error)

UserFrom, 解析JSON字符串并返回一个 User 实例

func (*User) Compare

func (u *User) Compare(pwd string) (err error)

Compare with the plain text password. Returns true if it's the same as the encrypted one (in the `User` struct).

func (*User) Encrypt

func (u *User) Encrypt() (err error)

Encrypt the user password.

func (*User) Result

func (u *User) Result() *UserResult

Result, 返回一个 UserResult 实例

func (*User) String

func (u *User) String() string

String, 返回一个为JSON 字符串的用户信息

func (*User) TableName

func (u *User) TableName() string

TableName, 获取User表名称

func (*User) Validate

func (u *User) Validate() error

Validate the fields.

type UserResult

type UserResult struct {
	ID        uint64    `json:"id"`
	Username  string    `json:"username"`
	Email     string    `json:"email"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

创建一个脱敏的User数据模型

func (*UserResult) String

func (u *UserResult) String() string

String, 返回一个为JSON 字符串的脱敏用户信息

type WhereParam

type WhereParam struct {
	Field   string
	Tag     string
	Prepare interface{}
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL