models

package
v0.0.0-...-1fbbad1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2016 License: GPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PostStatusPublished string = "published"
	PostStatusDraft     string = "draft"
)
View Source
const APP_VERSION = "0.1.0"
View Source
const CacheKeyAppSettings string = "cache_app_settings"
View Source
const (
	SiteOwner string = "owner"
)

Variables

View Source
var ApiMsg = apiMsg{
	Success: ApiErr{Code: 0, Message: ""},
	Created: ApiErr{Code: 0, Message: "msg.created"},
	Saved:   ApiErr{Code: 0, Message: "msg.saved"},
	Deleted: ApiErr{Code: 0, Message: "msg.deleted"},

	DatabaseFailed: ApiErr{Code: 1, Message: "msg.db_initialization_failed"},
	NeedToSignIn:   ApiErr{Code: 2, Message: "msg.need_to_sign_in"},
	NoPermission:   ApiErr{Code: 9, Message: "msg.no_permission"},
	SaveFail:       ApiErr{Code: 10, Message: "msg.save_fail"},
	LoadFail:       ApiErr{Code: 10, Message: "msg.load_fail"},

	ErrRoleNameCanNotBeEmpty:        ApiErr{Code: 101, Message: "msg.role_name_not_be_empty"},
	ErrRoleNameTooLong:              ApiErr{Code: 102, Message: "msg.role_name_too_long"},
	ErrNotSupportNumericRole:        ApiErr{Code: 103, Message: "msg.not_support_numeric_role"},
	ErrRoleDescriptionTooLong:       ApiErr{Code: 104, Message: "msg.role_description_too_long"},
	ErrRoleCanNotBeEmpty:            ApiErr{Code: 105, Message: "msg.role_not_be_empty"},
	ErrRoleAlreadyExist:             ApiErr{Code: 106, Message: "msg.role_exist"},
	ErrRoleNotFound:                 ApiErr{Code: 107, Message: "msg.role_not_found"},
	ErrRoleHaveUsersCanNotBeDeleted: ApiErr{Code: 108, Message: "msg.role_have_users_not_be_deleted"},
	ErrPermissionCanNotBeEmpty:      ApiErr{Code: 109, Message: "msg.perm_not_be_empty"},
	ErrPermissionAlreadyExist:       ApiErr{Code: 110, Message: "msg.perm_exist"},

	ErrUserNameCanNotBeEmpty:     ApiErr{Code: 201, Message: "msg.user_name_not_be_empty"},
	ErrUserNameTooLong:           ApiErr{Code: 202, Message: "msg.user_name_too_long"},
	ErrNotSupportNumericUser:     ApiErr{Code: 203, Message: "msg.not_support_numeric_user"},
	ErrUserPasswordCanNotBeEmpty: ApiErr{Code: 204, Message: "msg.user_password_not_be_empty"},
	ErrUserPasswordTooLong:       ApiErr{Code: 205, Message: "msg.user_password_too_long"},
	ErrUserAlreadyExist:          ApiErr{Code: 206, Message: "msg.user_exist"},
	ErrUserNotFound:              ApiErr{Code: 207, Message: "msg.user_not_found"},
	ErrPasswordIncorrect:         ApiErr{Code: 208, Message: "msg.password_incorrect"},
	ErrPasswordNotMatch:          ApiErr{Code: 209, Message: "msg.passwords_not_match"},
	ErrPasswordRequired:          ApiErr{Code: 210, Message: "msg.password_required"},
	ErrPasswordTooShort:          ApiErr{Code: 211, Message: "msg.password_at_least_8_char"},

	ErrPostTitleTooLong:           ApiErr{Code: 301, Message: "msg.post_title_too_long"},
	ErrPostSlugTooLong:            ApiErr{Code: 302, Message: "msg.post_slug_too_long"},
	ErrPostMetaTitleTooLong:       ApiErr{Code: 303, Message: "msg.post_meta_title_too_long"},
	ErrPostMetaDescriptionTooLong: ApiErr{Code: 304, Message: "msg.post_meta_description_too_long"},
	ErrPostSlugAlreadyExist:       ApiErr{Code: 305, Message: "msg.post_slug_exist"},
	ErrPostNotFound:               ApiErr{Code: 306, Message: "msg.post_not_found"},

	ErrFileNotSupported: ApiErr{Code: 901, Message: "msg.file_not_supported"},
	ErrFileTooLarge:     ApiErr{Code: 902, Message: "msg.file_too_large"},
}
View Source
var (
	HasEngine bool
)

Functions

func GetPermissions

func GetPermissions(opts *Options) ([]*Permission, ApiErr)

GetPermissions returns all permissions

func GetPermissionsByIds

func GetPermissionsByIds(ids []string) ([]*Permission, ApiErr)

GetPermissionsByIds returns all permissions by given ids

func GetPost

func GetPost(opts *Options) (*Post, ApiErr)

func GetPostById

func GetPostById(id uint32, opts *Options) (*Post, ApiErr)

func GetPosts

func GetPosts(opts *Options) ([]*Post, uint32, ApiErr)

func GetRole

func GetRole(opts *Options) (*Role, ApiErr)

func GetRoleById

func GetRoleById(id uint32, opts *Options) (*Role, ApiErr)

func GetRoles

func GetRoles(opts *Options) ([]*Role, ApiErr)

func GetSetting

func GetSetting(opts *Options) (*JsonSetting, ApiErr)

func GetUser

func GetUser(opts *Options) (*User, ApiErr)

func GetUserById

func GetUserById(id uint32, opts *Options) (*User, ApiErr)

func GetUserByName

func GetUserByName(name string, opts *Options) (*User, ApiErr)

func GetUsers

func GetUsers(opts *Options) ([]*User, uint32, ApiErr)

func IsRoleExist

func IsRoleExist(name string) (bool, *Role, ApiErr)

func NewEngine

func NewEngine() (err error)

func UserSignin

func UserSignin(u *User, opts *Options) (*User, ApiErr)

Types

type ApiErr

type ApiErr struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func ChangePassword

func ChangePassword(oldPassword, newPassword, verifyPassword string, userId uint32, opts *Options) (bool, ApiErr)

func CreatePermission

func CreatePermission(perm *Permission, opts *Options) ApiErr

CreatePermission creates a permission

func CreatePost

func CreatePost(post *Post, opts *Options) ApiErr

func CreateRole

func CreateRole(role *Role, opts *Options) ApiErr

func CreateSettings

func CreateSettings(settings []*Setting) ApiErr

func CreateUser

func CreateUser(u *User, opts *Options) ApiErr

func DeletePost

func DeletePost(id uint32, opts *Options) ApiErr

func DeleteRole

func DeleteRole(id uint32, opts *Options) ApiErr

func EditPost

func EditPost(post *Post, opts *Options) ApiErr

func EditRole

func EditRole(role *Role, opts *Options) ApiErr

func EditSetting

func EditSetting(setting *JsonSetting, opts *Options) ApiErr

func EditUser

func EditUser(u *User, opts *Options) ApiErr

func InitialDatabase

func InitialDatabase() ApiErr

func UnknowError

func UnknowError(msg string) ApiErr

func (*ApiErr) IsSuccess

func (c *ApiErr) IsSuccess() bool

type GormAdapter

type GormAdapter struct {
	Columns []string
	Query   interface{}
	Args    []interface{}
	Map     map[string]interface{}
	OrderBy string
	Joins   string
}

GormAdapter

  • models.Options{
  • GormAdp: &models.GormAdapter{Query: "column=value1"}},
  • }
  • models.Options{
  • GormAdp: &models.GormAdapter{Query: "column=?", Args: []interface{}{"column-value"}},
  • }
  • models.Options{
  • GormAdp: &models.GormAdapter{Map: map[string]interface{}{"column1": "value1", "column2": "value2"}},
  • }

type JsonSetting

type JsonSetting struct {
	AppUrl       string        `json:"app_url`
	Title        string        `json:"title"`
	Description  string        `json:"description"`
	Cover        string        `json:"cover"`
	Language     string        `json:"language"`
	PostsPerPage uint32        `json:"posts_per_page"`
	ForceI18n    bool          `json:"force_i18n"`
	ActiveApps   []string      `json:"active_apps"`
	InstallApps  []string      `json:"install_apps"`
	AntHead      string        `json:"ant_head"`
	AntFoot      string        `json:"ant_foot"`
	Navigation   []*Navigation `json:"navigation"`
	Permalink    string        `json:"permalink"`
	ActiveTheme  string        `json:"active_theme"`
	IsPrivate    bool          `json:"is_private"`
	Password     string        `json:"password"`
	Version      string        `json:"version"`
}

func GetAppSetting

func GetAppSetting() *JsonSetting

GetAppSetting get setting from cache

func (*JsonSetting) NavigationSerialize

func (c *JsonSetting) NavigationSerialize() string
type Menu struct {
	Name  string
	URL   string
	Label string
	Icon  string
	List  []Menu
}
type Navigation struct {
	Label string `json:"label"`
	Url   string `json:"url"`
}

type Options

type Options struct {
	User        *User
	Role        *Role
	Permission  *Permission
	Permissions []*Permission

	Limit   uint32
	Page    uint32
	Offset  uint32
	Include string
	GormAdp *GormAdapter
}

Model Assistant

func (*Options) IsInclude

func (c *Options) IsInclude(name string) bool

type Pagination

type Pagination struct {
	PerPage    uint32 `json:"per_page"`
	Page       uint32 `json:"page"`
	TotalPages uint32 `json:"total"`
}

type Permission

type Permission struct {
	Id         uint32 `json:"id" gorm:"primary_key"`
	Name       string `json:"name" sql:"not null;type:varchar(20)"`
	Slug       string `json:"slug" sql:"not null;type:varchar(20)"`
	ObjectType string `json:"-" sql:"not null;type:varchar(20)"`
	IsCore     bool   `json:"is_core" sql:"not null;type:tinyint(1)"`
}

type Post

type Post struct {
	Id              uint32    `json:"id" gorm:"primary_key"`
	Title           string    `json:"title" sql:"not null;type:varchar(150);"`
	Slug            string    `json:"slug" sql:"not null;type:varchar(200);"`
	Markdown        string    `json:"markdown" sql:"not null;type:text;"`
	Html            string    `json:"html" sql:"not null;type:text;"`
	Cover           string    `json:"cover" sql:"type:varchar(150)"`
	Language        string    `json:"language" sql:"type:varchar(6)"`
	Page            bool      `json:"page" sql:"not null;type:tinyint(1)"`
	Featured        bool      `json:"featured" sql:"not null;type:tinyint(1)"`
	Status          string    `json:"status" sql:"not null;type:varchar(20)"`
	MetaTitle       string    `json:"meta_title" sql:"type:varchar(150)"`
	MetaDescription string    `json:"meta_description" sql:"type:varchar(200)"`
	AuthorId        uint32    `json:"-" sql:"not null;type:bigint unsigned;"`
	PublishedAt     time.Time `json:"published_at" sql:"not null;type:datetime;"`
	PublishedBy     uint32    `json:"-" sql:"not null;type:bigint unsigned;"`
	CreatedAt       time.Time `json:"-" sql:"not null;type:datetime;"`
	CreatedBy       uint32    `json:"-" sql:"not null;type:bigint unsigned;"`
	UpdatedAt       time.Time `json:"-" sql:"type:datetime;"`
	UpdatedBy       uint32    `json:"-" sql:"type:bigint unsigned;"`

	Author *User `json:"author,omitempty"`
}

func (*Post) GetAuthor

func (c *Post) GetAuthor()

func (*Post) GetPageMeta

func (c *Post) GetPageMeta() map[string]string

func (*Post) GetURL

func (c *Post) GetURL() string

type RestApi

type RestApi struct {
	Data       interface{} `json:"data"`
	Error      ApiErr      `json:"error"`
	Pagination *Pagination `json:"pagination"`
}

type Role

type Role struct {
	Id          uint32    `json:"id" gorm:"primary_key"`
	Name        string    `json:"name" sql:"not null;type:varchar(50);"`
	Description string    `json:"description" sql:"type:varchar(150)"`
	Slug        string    `json:"slug" sql:"type:varchar(100);"`
	CreatedAt   time.Time `json:"created_at" sql:"type:datetime;"`
	CreatedBy   uint32    `json:"-" sql:"type:bigint unsigned;"`
	UpdatedAt   time.Time `json:"updated_at" sql:"type:datetime;"`
	UpdatedBy   uint32    `json:"-" sql:"type:bigint unsigned;"`

	Permissions []Permission `json:"permissions" gorm:"many2many:permissions_roles;"`
}

func (*Role) GetPermissions

func (c *Role) GetPermissions()

type Setting

type Setting struct {
	Id        uint32    `gorm:"primary_key"`
	Key       string    `sql:"not null;type:varchar(50);"`
	Value     string    `sql:"type:text"`
	Type      string    `sql:"type:varchar(20);"`
	CreatedAt time.Time `sql:"not null;type:datetime;"`
	CreatedBy uint32    `sql:"not null;type:bigint unsigned;"`
	UpdatedAt time.Time `sql:"type:datetime;"`
	UpdatedBy uint32    `sql:"type:bigint unsigned;"`
}

type User

type User struct {
	Id        uint32    `json:"id" gorm:"primary_key"`
	Name      string    `json:"name" sql:"type:varchar(50);"`
	Password  string    `json:"-" sql:"type:char(40);"`
	Slug      string    `json:"slug" sql:"type:varchar(100);unique_index;"`
	Email     string    `json:"email" sql:"type:varchar(50);"`
	Bio       string    `json:"bio" sql:"type:varchar(200);"`
	Avatar    string    `json:"avatar" sql:"type:varchar(200);"`
	Cover     string    `json:"cover" sql:"type:varchar(200);"`
	Website   string    `json:"website" sql:"type:varchar(200);"`
	Location  string    `json:"location" sql:"type:varchar(200);"`
	Language  string    `json:"language" sql:"type:varchar(6);"`
	Salt      string    `json:"-" sql:"type:char(10);"`
	LastLogin time.Time `json:"last_login" sql:"type:datetime;"`
	Status    string    `json:"status" sql:"type:varchar(20);"`
	CreatedAt time.Time `json:"-" sql:"type:datetime;"`
	CreatedBy uint32    `json:"-" sql:"type:bigint unsigned;"`
	UpdatedAt time.Time `json:"-" sql:"type:datetime;"`
	UpdatedBy uint32    `json:"-" sql:"type:bigint unsigned;"`

	Roles []Role `json:"roles" gorm:"many2many:roles_users;"`
}

func (*User) EncodePassword

func (c *User) EncodePassword()

EncodePassword encodes password to safe format.

func (*User) GetRole

func (c *User) GetRole() Role

func (*User) IsGranted

func (c *User) IsGranted(permission string, assert rbac.AssertionFunc) bool

IsGranted check if user has permission

func (*User) IsOwner

func (c *User) IsOwner() bool

Jump to

Keyboard shortcuts

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