model

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleSuperAdmin = "superadmin"
	RoleAdmin      = "admin"
	RoleUser       = "user"
)

RBAC roles

View Source
const (
	ObjectAny     = "*"
	ObjectUser    = "user"
	ObjectCountry = "country"
)

RBAC objects

View Source
const (
	ActionAny       = "*"
	ActionViewAll   = "view_all"
	ActionView      = "view"
	ActionCreateAll = "create_all"
	ActionCreate    = "create"
	ActionUpdateAll = "update_all"
	ActionUpdate    = "update"
	ActionDeleteAll = "delete_all"
	ActionDelete    = "delete"
)

RBAC actions

Variables

View Source
var AvailableRoles = []string{RoleAdmin, RoleUser}

AvailableRoles for validation

Functions

This section is empty.

Types

type Auth

type Auth interface {
	User(echo.Context) *AuthUser
}

Auth represents auth interface

type AuthToken

type AuthToken struct {
	AccessToken  string `json:"access_token,omitempty"`
	TokenType    string `json:"token_type,omitempty"`
	ExpiresIn    int    `json:"expires_in,omitempty"`
	RefreshToken string `json:"refresh_token,omitempty"`

} // @name AuthToken

AuthToken holds authentication token details with refresh token

type AuthUser

type AuthUser struct {
	ID       int
	Username string
	Email    string
	Role     string
}

AuthUser represents data stored in JWT token for user

type Base

type Base struct {
	// ID of the record
	ID int `json:"id" gorm:"primary_key"`
	// The time that record is created
	CreatedAt time.Time `json:"created_at"`
	// The latest time that record is updated
	UpdatedAt time.Time `json:"updated_at"`
	// DeletedAt *time.Time `json:"deleted_at" sql:"index"`
	DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`

} // @name Base

Base contains common fields for all models Do not use gorm.Model because of uint ID

type Country

type Country struct {
	Base
	Name      string `json:"name" gorm:"type:varchar(255)"`
	Code      string `json:"code" gorm:"type:varchar(10)"`
	PhoneCode string `json:"phone_code" gorm:"type:varchar(10)"`

} // @name Country

Country represents the country model

type User

type User struct {
	Base
	FirstName string `json:"first_name" gorm:"type:varchar(255)"`
	LastName  string `json:"last_name" gorm:"type:varchar(255)"`
	Email     string `json:"email" gorm:"type:varchar(255)"`
	Mobile    string `json:"mobile,omitempty" gorm:"type:varchar(255)"`

	Username     string     `json:"username" gorm:"type:varchar(255);unique_index;not null"`
	Password     string     `json:"-" gorm:"type:varchar(255);not null"`
	LastLogin    *time.Time `json:"last_login,omitempty"`
	Blocked      bool       `json:"blocked" gorm:"not null;default:false"`
	RefreshToken string     `json:"-" gorm:"type:varchar(255);unique_index"`

	Role string `json:"role" gorm:"varchar(255)"`

} // @name User

User represents the user model

Jump to

Keyboard shortcuts

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