models

package
v0.0.0-...-b7287e2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrNil                = "0"
	ErrInternal           = "1000"
	ErrInvalidAccount     = "2000"
	ErrInvalidPassword    = "2001"
	ErrInvalidToken       = "2002"
	ErrOccupiedAccount    = "2003"
	ErrNilAccount         = "2004"
	ErrInvalidOrgJoinCode = "3001"
	ErrOrgUnActivated     = "3002"
	ErrInvalidOrg         = "3003"
)

common used error code

Variables

View Source
var ErrText = map[string]string{
	ErrNil:                "api call succeeded",
	ErrInvalidAccount:     "invalid account",
	ErrInvalidPassword:    "invalid password",
	ErrInvalidToken:       "invalid token",
	ErrOccupiedAccount:    "account already occupied",
	ErrNilAccount:         "account doesn't exist",
	ErrInvalidOrgJoinCode: "invalid org join code",
	ErrOrgUnActivated:     "org has not been activated yet",
	ErrInvalidOrg:         "org invalid",
}

ErrText error text

Functions

func AutoMigrate

func AutoMigrate(db *gorm.DB) error

AutoMigrate automigrate db, only in dev mode

func Connect

func Connect(conf *conf.DBConfiguration, logger *zap.Logger) (*gorm.DB, error)

Connect connect to db

func SendJSON

func SendJSON(w http.ResponseWriter, apiMsg *APIMessage) error

SendJSON handle rest api returns

Types

type APIMessage

type APIMessage struct {
	HTTPCode        int         `json:"-"`
	Code            string      `json:"code"`
	RequestID       string      `json:"-"`
	Message         string      `json:"message"`
	Payload         interface{} `json:"payload"`
	InternalError   error       `json:"-"`
	InternalMessage string      `json:"-"`
}

APIMessage the rest api response message

func NewAPIError

func NewAPIError(code string, msgFmt string, args ...interface{}) *APIMessage

NewAPIError construct result for a successful api call, but the result is invalid

func NewAPIResult

func NewAPIResult(code string, obj interface{}, msgFmt string, args ...interface{}) *APIMessage

NewAPIResult construct result for a successful api call, but the result is valid

func NewHTTPError

func NewHTTPError(httpCode int, code string, msgFmt string, args ...interface{}) *APIMessage

NewHTTPError construct an api error

func (*APIMessage) Cause

func (e *APIMessage) Cause() error

Cause returns the root cause error

func (*APIMessage) Error

func (e *APIMessage) Error() string

func (*APIMessage) WithInternalError

func (e *APIMessage) WithInternalError(err error) *APIMessage

WithInternalError adds internal error information to the error

func (*APIMessage) WithInternalMessage

func (e *APIMessage) WithInternalMessage(fmtString string, args ...interface{}) *APIMessage

WithInternalMessage adds internal message information to the error

type Auth

type Auth struct {
	UserID     int64
	SignOrg    string `gorm:"-"`
	Provider   string
	UID        string
	Password   string
	ID         int64
	CreateUser int64
	UpdateUser int64
	CreateTime time.Time
	UpdateTime time.Time
	DeleteTime *time.Time
	SignLogs
}

Auth is the persistent model of auth

func (*Auth) Create

func (a *Auth) Create(tx *sqlx.Tx) error

Create create new auth

func (*Auth) TableName

func (a *Auth) TableName() string

TableName db table name

func (Auth) ToClaims

func (a Auth) ToClaims() *claims.Claims

ToClaims convert to access-token Claims

func (Auth) ToRefreshClaims

func (a Auth) ToRefreshClaims() *claims.Claims

ToRefreshClaims convert to refresh-token Claims

type DBLogger

type DBLogger struct {
	*zap.Logger
}

DBLogger logger for database operations

func NewDBLogger

func NewDBLogger(log *zap.Logger) *DBLogger

NewDBLogger create new database logger

func (*DBLogger) Print

func (dbl *DBLogger) Print(params ...interface{})

Print method of the DBLogger

type Org

type Org struct {
	ID         int64
	UID        string
	JoinCode   string
	Nickname   string
	Verified   bool
	Activated  bool
	RealName   string
	CreateUser int64
	UpdateUser int64
	CreateTime time.Time
	UpdateTime time.Time
	DeleteTime *time.Time
}

Org org represents tenant

func (*Org) TableName

func (o *Org) TableName() string

TableName db table name

type OrgApp

type OrgApp struct {
	ID         int64
	AppUID     string
	PackageUID string `gorm:"column:package_uid"`
	UserID     int64
	OrgID      int64 `gorm:"index:ORG_ID"`
	CreateUser int64
	UpdateUser int64
	CreateTime time.Time
	UpdateTime time.Time
	DeleteTime *time.Time
}

OrgApp org-app relations

func (*OrgApp) TableName

func (oa *OrgApp) TableName() string

TableName db table name

type OrgUser

type OrgUser struct {
	ID         int64
	OrgID      int64
	UserID     int64
	RoleCode   string
	CreateUser int64
	UpdateUser int64
	CreateTime time.Time
	UpdateTime time.Time
	DeleteTime *time.Time
}

OrgUser org-user relations

func (*OrgUser) TableName

func (ou *OrgUser) TableName() string

TableName db table name

type SignLog

type SignLog struct {
	Agent  string
	At     *time.Time
	IP     string
	UID    string
	OrgUID string
	ID     int64
}

SignLog signlogs item

type SignLogs

type SignLogs struct {
	Log   string `sql:"-"`
	Count uint
	Logs  []SignLog
}

SignLogs signlog data

func (*SignLogs) Scan

func (signLogs *SignLogs) Scan(data interface{}) (err error)

Scan scan data into sign logs

func (SignLogs) Value

func (signLogs SignLogs) Value() (driver.Value, error)

Value return struct's Value

type User

type User struct {
	ID         int64
	Nickname   string
	RealName   string
	Mail       string
	Phone      string
	Gender     bool
	Dob        *time.Time
	Avatar     string
	CreateUser int64
	UpdateUser int64
	CreateTime time.Time
	UpdateTime time.Time
	DeleteTime *time.Time
}

User model

func (*User) Create

func (u *User) Create(tx *sqlx.Tx) error

Create create new user

func (*User) TableName

func (u *User) TableName() string

TableName db table name

Jump to

Keyboard shortcuts

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