model

package
v0.7.48 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CategoryStateAll        CategoryState = "all"
	CategoryStateApproved                 = "approved"
	CategoryStateUnapproved               = "unapproved"
)
View Source
const (
	MessageTypeReply    MessageType = "reply"
	MessageTypeCategory             = "category"
	MessageTypeSystem               = "system"
)
View Source
const (
	PageThemeLight  string = "light"
	PageThemeDark          = "dark"
	PageThemeSystem        = "system"
	PageThemeMatrix        = "matrix"
)
View Source
const (
	PageContentLayoutFull     string = "full"
	PageContentLayoutCentered        = "centered"
)
View Source
const (
	RepliesLayoutTree string = "tree"
	RepliesLayoutTile        = "tile"
)
View Source
const (
	DefaultUserRoleCommon    UserRoleFrontId = "common_user"
	DefaultUserRoleBanned                    = "banned_user"
	DefaultUserRoleModerator                 = "moderator"
	DefaultUserRoleAdmin                     = "admin"
)
View Source
const (
	MAX_ARTICLE_TITLE_LEN, MAX_ARTICLE_CONTENT_LEN int = 255, 24000
)
View Source
const MaxEmailLen = 254
View Source
const MaxUsernameLen = 20
View Source
const PermissionFrontIdMaxLen int = 50
View Source
const PermissionNameMaxLen int = 50
View Source
const ReEmailStr = `` /* 158-byte string literal not displayed */

https://regex101.com/r/RzBwPX/1

View Source
const ReUsernameEdgeStr = `^[a-zA-Z0-9]+$`
View Source
const ReUsernameMiddleStr = `^[a-zA-Z0-9._-]+$`
View Source
const ReUsernameStr = `^[a-zA-Z0-9][a-zA-Z0-9._-]+[a-zA-Z0-9]$`
View Source
const RoleFrontIdMaxLen int = 50
View Source
const RoleNameMaxLen int = 50

Variables

View Source
var (
	AppErrAlreadyRegistered     = NewAppError(AppErrCodeAlreadyRegistered)
	AppErrNotRegistered         = NewAppError(AppErrCodeNotRegistered)
	AppErrUserValidFailed       = NewAppError(AppErrCodeUserValidFailed)
	AppErrArticleValidFailed    = NewAppError(AppErrCodeArticleValidFailed)
	AppErrPermissionValidFailed = NewAppError(AppErrCodePermissionValidFailed)
	AppErrRoleValidFailed       = NewAppError(AppErrCodeRoleValidFailed)
	AppErrActivityValidFailed   = NewAppError(AppErrCodeActivityValidFailed)
	AppErrCategoryValidFailed   = NewAppError(AppErrCodeCategoryValidFailed)
	AppErrUserNotExist          = NewAppError(AppErrCodeUserNotExist)
	AppErrArticleNotExist       = NewAppError(AppErrCodeArticleNotExist)
)
View Source
var AuthTypeNames = map[AuthType]string{
	AuthTypeSelf:      "Self",
	AuthTypeGoogle:    "Google",
	AuthTypeGithub:    "GitHub",
	AuthTypeMicrosoft: "Microsoft",
}
View Source
var DefaultArticleListSortType = ListSortBest
View Source
var DefaultReplyListSortType = ReplySortBest
View Source
var DefaultUiSettings = &UISettings{
	Lang:                   LangEn,
	Theme:                  PageThemeSystem,
	ContentLayout:          PageContentLayoutCentered,
	RepliesLayout:          RepliesLayoutTree,
	FontSize:               14,
	FontSizeCustom:         false,
	ShowEmoji:              true,
	DefaultArticleSortType: DefaultArticleListSortType,
	DefaultReplySortType:   DefaultReplyListSortType,
}
View Source
var ErrEmailValidFailed error
View Source
var ErrInvalidAcAction = fmt.Errorf("not a valid AcAction, try [%s]", strings.Join(_AcActionNames, ", "))
View Source
var ErrInvalidAcModel = fmt.Errorf("not a valid AcModel, try [%s]", strings.Join(_AcModelNames, ", "))
View Source
var ErrInvalidAcType = fmt.Errorf("not a valid AcType, try [%s]", strings.Join(_AcTypeNames, ", "))
View Source
var ErrInvalidAppErrCode = fmt.Errorf("not a valid AppErrCode, try [%s]", strings.Join(_AppErrCodeNames, ", "))
View Source
var ErrInvalidLang = fmt.Errorf("not a valid Lang, try [%s]", strings.Join(_LangNames, ", "))

Functions

func AcActionAddI18nConfigs

func AcActionAddI18nConfigs(ic *i18nc.I18nCustom)

func AcActionNames

func AcActionNames() []string

AcActionNames returns a list of possible string values of AcAction.

func AcModelAddI18nConfigs

func AcModelAddI18nConfigs(ic *i18nc.I18nCustom)

func AcModelNames

func AcModelNames() []string

AcModelNames returns a list of possible string values of AcModel.

func AcTypeAddI18nConfigs

func AcTypeAddI18nConfigs(ic *i18nc.I18nCustom)

func AcTypeNames

func AcTypeNames() []string

AcTypeNames returns a list of possible string values of AcType.

func ActivityValidErr

func ActivityValidErr(str string) error

func AppErrCodeAddI18nConfigs

func AppErrCodeAddI18nConfigs(ic *i18nc.I18nCustom)

func AppErrCodeNames

func AppErrCodeNames() []string

AppErrCodeNames returns a list of possible string values of AppErrCode.

func CalcArticleListWeight

func CalcArticleListWeight(voteUpCount, voteDownCount int, createdAt time.Time) float64

func CalcArticleReplyWeight

func CalcArticleReplyWeight(voteUpCount, voteDownCount int) float64

func CeilInt

func CeilInt(a, b int) int

func DoEncryptPassword

func DoEncryptPassword(pwd string) (string, error)

func ExtractNameFromEmail

func ExtractNameFromEmail(email string) string

func GetSortTypeNames

func GetSortTypeNames(ic *i18nc.I18nCustom) map[ArticleSortType]string

func InitConfidences

func InitConfidences()

func IsValidVoteType

func IsValidVoteType(t VoteType) bool

func LangAddI18nConfigs

func LangAddI18nConfigs(ic *i18nc.I18nCustom)

func LangNames

func LangNames() []string

LangNames returns a list of possible string values of Lang.

func NewAppError

func NewAppError(code AppErrCode) error

func SetupI18n

func SetupI18n(ic *i18nc.I18nCustom)

func UpdateErrI18n

func UpdateErrI18n()

func ValidArticleSort

func ValidArticleSort(sortType string) bool

func ValidPassword

func ValidPassword(pwd string) error

func ValidUsername

func ValidUsername(username string) error

func ValidateEmail

func ValidateEmail(email string) error

Validate email string

Types

type AcAction

type AcAction string

Activity Action

ENUM(

register, // Register
register_verify, // Registration verification
login, // Login
logout, // Logout
update_intro, // Update introduction
create_article, // Create article
reply_article, // Reply to article
edit_article, // Edit article
delete_article, // Delete article
save_article, // Save article
vote_article, // Vote article
react_article, // React to article
set_role, // Set role
add_role, // Add role
edit_role, // Edit role
subscribe_article, // Subscribe article
retrieve_password, // Retrieve password
reset_password, // Reset password
toggle_hide_history, // Toggle hide history
recover, // Recover article
block_regions, // Block regions
lock_article, // Lock article
fade_out_article, // Fade out article
ban_user, // Ban user
unban_user, // Unban user

)

const (
	// AcActionRegister is a AcAction of type register.
	// Register
	AcActionRegister AcAction = "register"
	// AcActionRegisterVerify is a AcAction of type register_verify.
	// Registration verification
	AcActionRegisterVerify AcAction = "register_verify"
	// AcActionLogin is a AcAction of type login.
	// Login
	AcActionLogin AcAction = "login"
	// AcActionLogout is a AcAction of type logout.
	// Logout
	AcActionLogout AcAction = "logout"
	// AcActionUpdateIntro is a AcAction of type update_intro.
	// Update introduction
	AcActionUpdateIntro AcAction = "update_intro"
	// AcActionCreateArticle is a AcAction of type create_article.
	// Create article
	AcActionCreateArticle AcAction = "create_article"
	// AcActionReplyArticle is a AcAction of type reply_article.
	// Reply to article
	AcActionReplyArticle AcAction = "reply_article"
	// AcActionEditArticle is a AcAction of type edit_article.
	// Edit article
	AcActionEditArticle AcAction = "edit_article"
	// AcActionDeleteArticle is a AcAction of type delete_article.
	// Delete article
	AcActionDeleteArticle AcAction = "delete_article"
	// AcActionSaveArticle is a AcAction of type save_article.
	// Save article
	AcActionSaveArticle AcAction = "save_article"
	// AcActionVoteArticle is a AcAction of type vote_article.
	// Vote article
	AcActionVoteArticle AcAction = "vote_article"
	// AcActionReactArticle is a AcAction of type react_article.
	// React to article
	AcActionReactArticle AcAction = "react_article"
	// AcActionSetRole is a AcAction of type set_role.
	// Set role
	AcActionSetRole AcAction = "set_role"
	// AcActionAddRole is a AcAction of type add_role.
	// Add role
	AcActionAddRole AcAction = "add_role"
	// AcActionEditRole is a AcAction of type edit_role.
	// Edit role
	AcActionEditRole AcAction = "edit_role"
	// AcActionSubscribeArticle is a AcAction of type subscribe_article.
	// Subscribe article
	AcActionSubscribeArticle AcAction = "subscribe_article"
	// AcActionRetrievePassword is a AcAction of type retrieve_password.
	// Retrieve password
	AcActionRetrievePassword AcAction = "retrieve_password"
	// AcActionResetPassword is a AcAction of type reset_password.
	// Reset password
	AcActionResetPassword AcAction = "reset_password"
	// AcActionToggleHideHistory is a AcAction of type toggle_hide_history.
	// Toggle hide history
	AcActionToggleHideHistory AcAction = "toggle_hide_history"
	// AcActionRecover is a AcAction of type recover.
	// Recover article
	AcActionRecover AcAction = "recover"
	// AcActionBlockRegions is a AcAction of type block_regions.
	// Block regions
	AcActionBlockRegions AcAction = "block_regions"
	// AcActionLockArticle is a AcAction of type lock_article.
	// Lock article
	AcActionLockArticle AcAction = "lock_article"
	// AcActionFadeOutArticle is a AcAction of type fade_out_article.
	// Fade out article
	AcActionFadeOutArticle AcAction = "fade_out_article"
	// AcActionBanUser is a AcAction of type ban_user.
	// Ban user
	AcActionBanUser AcAction = "ban_user"
	// AcActionUnbanUser is a AcAction of type unban_user.
	// Unban user
	AcActionUnbanUser AcAction = "unban_user"
)

func AcActionValues

func AcActionValues() []AcAction

AcActionValues returns a list of the values for AcAction

func ParseAcAction

func ParseAcAction(name string) (AcAction, error)

ParseAcAction attempts to convert a string to a AcAction.

func (AcAction) I18nID

func (x AcAction) I18nID() string

func (AcAction) IsValid

func (x AcAction) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (AcAction) String

func (x AcAction) String() string

String implements the Stringer interface.

func (AcAction) Text

func (x AcAction) Text(upCaseHead bool, i18nCustom *i18nc.I18nCustom) string

type AcModel

type AcModel string

Activity Model

ENUM(
empty, // Empty
user, // User
article, // Article
role, // Role
)
const (
	// AcModelEmpty is a AcModel of type empty.
	// Empty
	AcModelEmpty AcModel = "empty"
	// AcModelUser is a AcModel of type user.
	// User
	AcModelUser AcModel = "user"
	// AcModelArticle is a AcModel of type article.
	// Article
	AcModelArticle AcModel = "article"
	// AcModelRole is a AcModel of type role.
	// Role
	AcModelRole AcModel = "role"
)

func AcModelValues

func AcModelValues() []AcModel

AcModelValues returns a list of the values for AcModel

func ParseAcModel

func ParseAcModel(name string) (AcModel, error)

ParseAcModel attempts to convert a string to a AcModel.

func (AcModel) I18nID

func (x AcModel) I18nID() string

func (AcModel) IsValid

func (x AcModel) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (AcModel) String

func (x AcModel) String() string

String implements the Stringer interface.

func (AcModel) Text

func (x AcModel) Text(upCaseHead bool, i18nCustom *i18nc.I18nCustom) string

type AcType

type AcType string

Activity Type

ENUM(
user, // User
manage, // Management
anonymous, // Anonymous
dev, // Development
)
const (
	// AcTypeUser is a AcType of type user.
	// User
	AcTypeUser AcType = "user"
	// AcTypeManage is a AcType of type manage.
	// Management
	AcTypeManage AcType = "manage"
	// AcTypeAnonymous is a AcType of type anonymous.
	// Anonymous
	AcTypeAnonymous AcType = "anonymous"
	// AcTypeDev is a AcType of type dev.
	// Development
	AcTypeDev AcType = "dev"
)

func AcTypeValues

func AcTypeValues() []AcType

AcTypeValues returns a list of the values for AcType

func ParseAcType

func ParseAcType(name string) (AcType, error)

ParseAcType attempts to convert a string to a AcType.

func (AcType) I18nID

func (x AcType) I18nID() string

func (AcType) IsValid

func (x AcType) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (AcType) String

func (x AcType) String() string

String implements the Stringer interface.

func (AcType) Text

func (x AcType) Text(upCaseHead bool, i18nCustom *i18nc.I18nCustom) string

type Activity

type Activity struct {
	Id            int
	UserId        int
	UserName      string
	Type          AcType
	Action        string
	TargetId      string
	TargetModel   string
	CreatedAt     *time.Time
	IpAddr        string
	DeviceInfo    string
	Details       string
	FormattedText string
}

func (*Activity) Format

func (act *Activity) Format(i18nCustom *i18nc.I18nCustom)

type AppErrCode

type AppErrCode int

App Error

ENUM(
AlreadyRegistered = 1000, // already registered
NotRegistered, // not registered

UserValidFailed, // user data validation failed
ArticleValidFailed, // article data validation failed
PermissionValidFailed, // permission data validation failed
RoleValidFailed, // role data validation failed
ActivityValidFailed, // activity data validation failed
CategoryValidFailed, // category data validation failed

UserNotExist, // user dose not exist
ArticleNotExist, // article dose not exist
)
const (
	// AppErrCodeAlreadyRegistered is a AppErrCode of type AlreadyRegistered.
	// already registered
	AppErrCodeAlreadyRegistered AppErrCode = iota + 1000
	// AppErrCodeNotRegistered is a AppErrCode of type NotRegistered.
	// not registered
	AppErrCodeNotRegistered
	// AppErrCodeUserValidFailed is a AppErrCode of type UserValidFailed.
	// user data validation failed
	AppErrCodeUserValidFailed
	// AppErrCodeArticleValidFailed is a AppErrCode of type ArticleValidFailed.
	// article data validation failed
	AppErrCodeArticleValidFailed
	// AppErrCodePermissionValidFailed is a AppErrCode of type PermissionValidFailed.
	// permission data validation failed
	AppErrCodePermissionValidFailed
	// AppErrCodeRoleValidFailed is a AppErrCode of type RoleValidFailed.
	// role data validation failed
	AppErrCodeRoleValidFailed
	// AppErrCodeActivityValidFailed is a AppErrCode of type ActivityValidFailed.
	// activity data validation failed
	AppErrCodeActivityValidFailed
	// AppErrCodeCategoryValidFailed is a AppErrCode of type CategoryValidFailed.
	// category data validation failed
	AppErrCodeCategoryValidFailed
	// AppErrCodeUserNotExist is a AppErrCode of type UserNotExist.
	// user dose not exist
	AppErrCodeUserNotExist
	// AppErrCodeArticleNotExist is a AppErrCode of type ArticleNotExist.
	// article dose not exist
	AppErrCodeArticleNotExist
)

func AppErrCodeValues

func AppErrCodeValues() []AppErrCode

AppErrCodeValues returns a list of the values for AppErrCode

func ParseAppErrCode

func ParseAppErrCode(name string) (AppErrCode, error)

ParseAppErrCode attempts to convert a string to a AppErrCode.

func (AppErrCode) I18nID

func (x AppErrCode) I18nID() string

func (AppErrCode) IsValid

func (x AppErrCode) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (AppErrCode) String

func (x AppErrCode) String() string

String implements the Stringer interface.

func (AppErrCode) Text

func (x AppErrCode) Text(upCaseHead bool, i18nCustom *i18nc.I18nCustom) string

type AppError

type AppError struct {
	ErrCode AppErrCode
}

func (AppError) Error

func (x AppError) Error() string

type Article

type Article struct {
	Id                        int
	Title                     string
	Link                      string
	NullTitle                 pgtype.Text
	AuthorName                string
	AuthorId                  int
	Content                   string
	Summary                   string
	CreatedAt                 time.Time
	UpdatedAt                 time.Time
	CreatedAtStr              string
	UpdatedAtStr              string
	ReplyToId                 int
	ReplyToArticle            *Article
	Deleted                   bool
	Replies                   *ArticleList
	ReplyDepth                int
	ReplyRootArticleId        int
	NullReplyRootArticleTitle pgtype.Text
	ReplyRootArticleTitle     string
	DisplayTitle              string // only for display
	TotalReplyCount           int
	ChildrenCount             int
	VoteUp                    int
	VoteDown                  int
	VoteScore                 int
	Weight                    float64 // weight in replise
	ListWeight                float64 // weight in list page
	ParticipateCount          int
	CurrUserState             *CurrUserState
	Reacts                    []*ArticleReact
	ReactCounts               ArticleReactCounts
	ShowScore                 bool
	TmpParent                 *Article // Only for temporary use, to avoid circular reference errors
	CategoryFrontId           string
	Category                  *Category
	Locked                    bool
	Pinned                    bool
	NullPinnedExpireAt        pgtype.Timestamp
	PinnedExpireAt            time.Time
	BlockedRegionsISOCode     []string
	Blocked                   bool
	FadeOut                   bool
}

func (*Article) CalcScore

func (a *Article) CalcScore()

func (*Article) CalcWeight

func (a *Article) CalcWeight()

func (*Article) CheckShowScore

func (a *Article) CheckShowScore(loginedUserId int)

func (*Article) FormatDeleted

func (a *Article) FormatDeleted()

func (*Article) FormatNullValues

func (a *Article) FormatNullValues()

func (*Article) FormatReactCounts

func (a *Article) FormatReactCounts()

func (*Article) FormatTimeStr

func (a *Article) FormatTimeStr()

func (*Article) GenSummary

func (a *Article) GenSummary(strLen int)

func (*Article) Sanitize

func (a *Article) Sanitize(p *bluemonday.Policy)

func (*Article) TrimSpace

func (a *Article) TrimSpace()

func (*Article) UpdateBlockedState

func (a *Article) UpdateBlockedState(requestRegionISOCode string)

func (*Article) UpdateDisplayTitle

func (a *Article) UpdateDisplayTitle()

func (*Article) UpdatePinnedState

func (a *Article) UpdatePinnedState()

func (*Article) Valid

func (a *Article) Valid(isUpdate bool) error

type ArticleList

type ArticleList struct {
	List      []*Article
	SortType  ArticleSortType
	CurrPage  int
	PageSize  int
	Total     int
	TotalPage int
}

func NewArticleList

func NewArticleList(list []*Article, sortType ArticleSortType, currPage, pageSize, total int) *ArticleList

func (*ArticleList) Len

func (al *ArticleList) Len() int

func (*ArticleList) Less

func (al *ArticleList) Less(i, j int) bool

func (*ArticleList) PagingList

func (al *ArticleList) PagingList(page, pageSize int) []*Article

func (*ArticleList) Remove

func (al *ArticleList) Remove(id int)

func (*ArticleList) Sort

func (al *ArticleList) Sort(sortType ArticleSortType) []*Article

func (*ArticleList) Swap

func (al *ArticleList) Swap(i, j int)

type ArticleLog

type ArticleLog struct {
	Id                      int
	PrimaryArticleId        int
	CreatedAt               time.Time
	OperatorId              int
	Operator                *User
	CurrEditTime            time.Time
	PrevEditTime            time.Time
	PrevArticle             *Article
	CurrArticle             *Article
	VersionNum              int
	TitleDelta              string
	URLDelta                string
	ContentDelta            string
	CategoryFrontIdDelta    string
	TitleDiffHTML           string
	URLDiffHTML             string
	ContentDiffHTML         string
	CategoryFrontIdDiffHTML string
	IsHidden                bool
}

func GenArticleDiffsFromDelta

func GenArticleDiffsFromDelta(dmp *diffmatchpatch.DiffMatchPatch, headArticle *Article, list []*ArticleLog) ([]*ArticleLog, error)

type ArticleLogList

type ArticleLogList struct {
	List []*ArticleLog
}

func (*ArticleLogList) Len

func (all *ArticleLogList) Len() int

func (*ArticleLogList) Less

func (all *ArticleLogList) Less(i, j int) bool

func (*ArticleLogList) Swap

func (all *ArticleLogList) Swap(i, j int)

type ArticleReact

type ArticleReact struct {
	Id        int
	Emoji     string
	FrontId   string
	Describe  string
	CreatedAt time.Time
}

type ArticleReactCounts

type ArticleReactCounts map[string]int

type ArticleSortType

type ArticleSortType string
const (
	ReplySortBest  ArticleSortType = "best"
	ListSortOldest ArticleSortType = "oldest"
	ListSortLatest ArticleSortType = "latest"
	ListSortBest   ArticleSortType = "list_best"
	ListSortHot    ArticleSortType = "list_hot"
)

func GetSortTypeList

func GetSortTypeList(isReply bool, defaultSortType ArticleSortType) []ArticleSortType

type AuthType

type AuthType string
const (
	AuthTypeSelf      AuthType = "self"
	AuthTypeGoogle    AuthType = "google"
	AuthTypeGithub    AuthType = "github"
	AuthTypeMicrosoft AuthType = "microsoft"
)

func GetAuthTypeList

func GetAuthTypeList() []AuthType
type BreadCrumb struct {
	Path string
	Name string
}

type Category

type Category struct {
	Id                int
	FrontId           string
	Name              string
	Describe          string
	AuthorId          string
	CreatedAt         time.Time
	Approved          bool
	ApprovalComment   string
	UserState         *CategoryUserState
	TotalArticleCount int
}

func (*Category) TrimSpace

func (p *Category) TrimSpace()

func (*Category) Valid

func (p *Category) Valid() error

type CategoryState

type CategoryState string

type CategoryUserState

type CategoryUserState struct {
	Subscribed bool
}

type CurrUserState

type CurrUserState struct {
	VoteType     VoteType
	NullVoteType pgtype.Text
	Saved        bool
	ReactFrontId string
	Subscribed   bool
}

func (*CurrUserState) FormatNullValues

func (cus *CurrUserState) FormatNullValues()

type Lang

type Lang string

Language list

ENUM(
en, // English
zh-Hans, // 简体中文
zh-Hant, // 繁體中文
ja, // 日本語
)
const (
	// LangEn is a Lang of type en.
	// English
	LangEn Lang = "en"
	// LangZhHans is a Lang of type zh-Hans.
	// 简体中文
	LangZhHans Lang = "zh-Hans"
	// LangZhHant is a Lang of type zh-Hant.
	// 繁體中文
	LangZhHant Lang = "zh-Hant"
	// LangJa is a Lang of type ja.
	// 日本語
	LangJa Lang = "ja"
)

func LangValues

func LangValues() []Lang

LangValues returns a list of the values for Lang

func ParseLang

func ParseLang(name string) (Lang, error)

ParseLang attempts to convert a string to a Lang.

func (Lang) I18nID

func (x Lang) I18nID() string

func (Lang) IsValid

func (x Lang) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (Lang) String

func (x Lang) String() string

String implements the Stringer interface.

func (Lang) Text

func (x Lang) Text(upCaseHead bool, i18nCustom *i18nc.I18nCustom) string

type Message

type Message struct {
	Id               int
	Content          string
	SenderUserId     int
	SenderUserName   string
	RecieverUserId   int
	RecieverUserName string
	SourceArticle    *Article
	SourceCategory   *Category
	ContentArticle   *Article
	IsRead           bool
	CreatedAt        *time.Time
	Type             MessageType
}

type MessageType

type MessageType string

type OptionItem

type OptionItem struct {
	Value any
	Name  string
}

func ConvertEnumToOPtions

func ConvertEnumToOPtions(values []StringEnum, upCaseHead bool, enumName string, i18nCustom *i18nc.I18nCustom) []*OptionItem

type PageData

type PageData struct {
	Title                 string
	Description           string
	Data                  any
	TipMsg                []string
	LoginedUser           *User
	JSONStr               string
	CSRFField             string
	UISettings            *UISettings
	RoutePath             string
	RouteQuery            url.Values
	RouteRawQuery         string
	Debug                 bool
	DebugUsers            []*User
	BreadCrumbs           []*BreadCrumb
	BrandName             string
	BrandDomainName       string
	Slogan                string
	PermissionEnabledList []string
	MessageCount          int
	RespStart             time.Time
	RenderStart           time.Time
	Host                  string
	CFSiteKey             string
}

type Permission

type Permission struct {
	Id        int
	FrontId   string
	Name      string
	CreatedAt time.Time
	// Module    PermissionModule
	Module string
}

func (*Permission) TrimSpace

func (p *Permission) TrimSpace()

func (*Permission) Valid

func (p *Permission) Valid() error

type PermissionListItem

type PermissionListItem struct {
	Module string
	List   []*Permission
}

type ReputationChangeType

type ReputationChangeType string
const (
	RPCTypeUpvoted   ReputationChangeType = "upvoted"
	RPCTypeDownvoted ReputationChangeType = "downvoted"
	RPCTypeThanked   ReputationChangeType = "thanked"
	RPCTypeLaughed   ReputationChangeType = "laughed"
	RPCTypeFadeOut   ReputationChangeType = "fade_out"

	RPCTypeBanned ReputationChangeType = "banned"
	RPCTypeOther  ReputationChangeType = "other"
)

type Role

type Role struct {
	Id                   int
	FrontId              string
	Name                 string
	CreatedAt            time.Time
	IsDefault            bool
	Permissions          []*Permission
	FormattedPermissions []*PermissionListItem
}

func (*Role) TrimSpace

func (r *Role) TrimSpace()

func (*Role) Valid

func (r *Role) Valid(isUpdate bool) error

type StringEnum

type StringEnum interface {
	Text(upCaseHead bool, i18nCustom *i18nc.I18nCustom) string
}

type UISettings

type UISettings struct {
	Lang                   Lang            `json:"lang"`
	Theme                  string          `json:"theme"`
	ContentLayout          string          `json:"content_layout"`
	RepliesLayout          string          `json:"replies_layout"`
	FontSize               int             `json:"font_size"`
	FontSizeCustom         bool            `json:"font_size_custom"`
	ShowEmoji              bool            `json:"show_emoji"`
	DefaultArticleSortType ArticleSortType `json:"default_article_sort_type"`
	DefaultReplySortType   ArticleSortType `json:"default_reply_sort_type"`
}

type User

type User struct {
	Id                int
	Name              string
	Email             string
	Password          string
	RegisteredAt      time.Time
	RegisteredAtStr   string
	NullIntroduction  pgtype.Text
	Introduction      string
	Deleted           bool
	Banned            bool
	PasswordHased     bool
	RoleName          string
	RoleFrontId       string
	Permissions       []*Permission
	Super             bool
	AuthFrom          AuthType
	Reputation        int
	NullBannedStartAt pgtype.Timestamp
	BannedStartAt     time.Time
	BannedEndAt       time.Time
	BannedDayNum      int
	BannedCount       int
}

func (*User) EncryptPassword

func (u *User) EncryptPassword() error

func (*User) FormatNullVals

func (u *User) FormatNullVals()

func (*User) Sanitize

func (u *User) Sanitize(p *bluemonday.Policy)

func (*User) TrimSpace

func (u *User) TrimSpace()

func (*User) UpdateBannedState

func (u *User) UpdateBannedState()

func (*User) Valid

func (u *User) Valid(withPassword bool) error

type UserRoleFrontId

type UserRoleFrontId string

type VerificationCode

type VerificationCode struct {
	Email     string
	Code      string
	CreatedAt *time.Time
	IsUsed    bool
}

type VoteType

type VoteType string
const (
	VoteTypeUp   VoteType = "up"
	VoteTypeDown VoteType = "down"
)

Jump to

Keyboard shortcuts

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