model

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// global data storage instance
	Storage *jsonStorage
	// global tmp data storage instance. Temp data are generated for special usages, will not backup.
	TmpStorage *jsonStorage
)

Functions

func All added in v0.1.5

func All()

All loads all data from storage to memory. Start timers for content, comment and message.

func ChangeTimerFunc added in v0.2.5

func ChangeTimerFunc(name string, ticker int, fn func())

ChangeTimerFunc can change timer func by given name. If the func of name is none, do not change anything, print error message.

func CleanTokens

func CleanTokens()

clean all expired tokens in memory. do not write to json.

func CreateComment

func CreateComment(cid int, c *Comment)

CreateComment creates a comment and links it to the cid content.

func CreateFilePath

func CreateFilePath(dir string, f *File) string

func CreateReader

func CreateReader(c *Comment)

CreateReader creates a reader from a comment.

func CreateUser

func CreateUser(u *User) error

create new user.

func DefaultNavigators added in v0.2.0

func DefaultNavigators()

func DelTimerFunc added in v0.2.5

func DelTimerFunc(name string)

DelTimerFunc deletes timer func.

func GetCustomSettings

func GetCustomSettings() map[string]string

func GetNavigators added in v0.2.0

func GetNavigators() []*navItem

func GetSetting

func GetSetting(key string) string

func GetTimerFuncs added in v0.2.5

func GetTimerFuncs() map[string]int

GetTimerFuncs returns registered timer func with its name and ticker int.

func GetVersion added in v0.1.5

func GetVersion() *version

func Init

func Init(v int)

Init does model initialization. If first run, write default data. v means app.Version number. It's needed for version data.

func LoadComments

func LoadComments()

LoadComments loads all comments from contents.

func LoadContents

func LoadContents()

LoadContents loads all contents, then generates indexes.

func LoadFiles

func LoadFiles()

func LoadMessages added in v0.2.0

func LoadMessages()

func LoadNavigators added in v0.2.0

func LoadNavigators()

func LoadReaders

func LoadReaders()

LoadReaders loads all readers from storage json.

func LoadSettings

func LoadSettings()

func LoadTokens

func LoadTokens()

load all tokens from json.

func LoadUsers

func LoadUsers()

func RecycleComments added in v0.2.0

func RecycleComments()

RecycleComments cleans removable comments.

func RecycleMessages added in v0.2.0

func RecycleMessages()

func RemoveComment

func RemoveComment(cid int, id int)

RemoveComment removes a comment by id and updates content iten by cid.

func RemoveContent

func RemoveContent(c *Content)

RemoveContent removes a content. Not delete file really, just change status to DELETE. This content can't be loaded in memory from storage json.

func RemoveFile

func RemoveFile(id int)

func RemoveReader added in v0.2.5

func RemoveReader(email string)

RemoveReader removes a reader by his email.

func RemoveToken

func RemoveToken(v string)

remove a token by token value.

func RemoveUser

func RemoveUser(u *User)

remove a user.

func SaveComment

func SaveComment(c *Comment)

SaveComment saves a comment and related updates content and reader data.

func SaveContent

func SaveContent(c *Content)

SaveContent saves changed content. It will re-generate related indexes.

func SaveMessageRead added in v0.2.0

func SaveMessageRead(m *Message)

func SetMessageGenerator added in v0.2.0

func SetMessageGenerator(name string, fn func(v interface{}) string)

func SetNavigators added in v0.2.0

func SetNavigators(order []string, text []string, title []string, link []string)

func SetSetting

func SetSetting(key string, v string)

func SetTimerFunc added in v0.2.5

func SetTimerFunc(name string, ticker int, fn func())

SetTimerFunc adds timer func for time ticker. Ticker means step time, after ticker size step passed, do function. Name is unique name of func.If set same name func, use the last one.

func SortNavigators added in v0.2.0

func SortNavigators()

func StartModelTimer added in v0.2.5

func StartModelTimer()

StartModelTimer adds models' timer and starts time ticker. The default step is 10 min once.

func SyncAll added in v0.2.0

func SyncAll()

SyncAll writes all current memory data to storage files.

func SyncContent

func SyncContent(c *Content)

SyncContent writes a content to storage json.

func SyncContents

func SyncContents()

SyncContents writes all contents to storage json.

func SyncFiles

func SyncFiles()

func SyncIndexes added in v0.2.5

func SyncIndexes()

func SyncMessages added in v0.2.0

func SyncMessages()

func SyncNavigators added in v0.2.0

func SyncNavigators()

func SyncReaders

func SyncReaders()

SyncReaders writes all readers data.

func SyncSettings

func SyncSettings()

func SyncTokens

func SyncTokens()

write tokens to json. it calls CleanTokens before writing.

func SyncUsers

func SyncUsers()

write users to json.

func SyncVersion added in v0.1.5

func SyncVersion()

func UpdateCommentAdmin added in v0.2.0

func UpdateCommentAdmin(user *User)

UpdateCommentAdmin updates comment author data if admin user data updated. It only updates admin comments.

Types

type Comment

type Comment struct {
	Id         int
	Author     string
	Email      string
	Url        string
	Avatar     string
	Content    string
	CreateTime int64
	// Content id
	Cid int
	// Parent Comment id
	Pid       int
	Status    string
	Ip        string
	UserAgent string
	// Is comment of admin
	IsAdmin bool
}

Comment struct defines a comment item data.

func GetCommentById

func GetCommentById(id int) *Comment

GetCommentById returns a comment by id.

func GetCommentList

func GetCommentList(page, size int) ([]*Comment, *utils.Pager)

GetCommentList returns a comments list and pager. This list scans all comments no matter its status.

func GetCommentRecentList added in v0.2.5

func GetCommentRecentList(size int) []*Comment

GetCommentRecentList returns a comments list of recent comments. Recent comments are approved and no parent and not admin comment. It's ordered by comment id desc.

func (*Comment) GetContent

func (c *Comment) GetContent() *Content

GetContent returns the content item of this comment.

func (*Comment) GetReader

func (c *Comment) GetReader() *Reader

GetReader returns the reader item of this comment.

func (*Comment) IsRemovable added in v0.2.0

func (c *Comment) IsRemovable() bool

IsRemovable returns whether this comment can remove. If content or parent comment of this comment is removed, return true.

func (*Comment) IsValid

func (c *Comment) IsValid() bool

IsValid returns whether this comment is valid to show. If this comment is not approved or its parent is missing, return false.

func (*Comment) ParentMd

func (c *Comment) ParentMd() string

ParentMd returns parent comment simple message as markdown text.

func (*Comment) ToJson

func (c *Comment) ToJson() map[string]interface{}

ToJson converts comment struct to public json map. It can hide some private fields, such as email.

type Content

type Content struct {
	Id    int
	Title string
	Slug  string
	Text  string

	//Category   string
	Tags []string

	CreateTime int64
	EditTime   int64
	UpdateTime int64

	// IsComment opens or closes comment
	IsComment bool
	// IsLinked makes pager link as top level link /link.html
	IsLinked bool

	AuthorId int

	// Template makes pager use own template file
	Template string

	Type   string
	Status string

	// Format defines the content text format type. Now only support markdown.
	Format string

	Comments []*Comment
	Hits     int
	// contains filtered or unexported fields
}

Content instance, defines content data items.

func CreateContent

func CreateContent(c *Content, t string) (*Content, error)

CreateContent creates new content. t means content type, article or page.

func GetArticleList

func GetArticleList(page, size int) ([]*Content, *utils.Pager)

GetArticleList gets articles list and pager no matter article status.

func GetContentById

func GetContentById(id int) *Content

GetContentById gets a content by given id.

func GetContentBySlug

func GetContentBySlug(slug string) *Content

GetContentBySlug gets a content by given slug.

func GetPageList

func GetPageList(page, size int) ([]*Content, *utils.Pager)

GetPageList gets pages list and pager no matter page status. In common cases, no need to get a list or pagers for public page.

func GetPopularArticleList added in v0.2.5

func GetPopularArticleList(size int) []*Content

GetPopularArticleList returns popular articles list. Popular articles are ordered by comment number.

func GetPublishArticleList added in v0.2.0

func GetPublishArticleList(page, size int) ([]*Content, *utils.Pager)

GetPublishArticleList gets published article list and pager.

func GetTaggedArticleList added in v0.2.5

func GetTaggedArticleList(tag string, page, size int) ([]*Content, *utils.Pager)

GetTaggedArticleList returns tagged articles list. These articles contains same one tag.

func (*Content) ChangeSlug

func (cnt *Content) ChangeSlug(slug string) bool

ChangeSlug changes content's slug. It checks whether this slug is unique.

func (*Content) CommentNum

func (cnt *Content) CommentNum() int

CommentNum returns content comments number. If comment are checking or, its parent are lost, do not count it.

func (*Content) Content

func (cnt *Content) Content() string

Content returns whole content text. If enable go-markdown, return markdown-rendered content.

func (*Content) GetTags added in v0.2.5

func (cnt *Content) GetTags() []*Tag

GetTags returns tags struct in this content.

func (cnt *Content) Link() string

Link returns content link as {type}/{id}/{slug}.html. If content isn't published, return "#". If content is page and top linked, return {slug}.html as top level link.

func (*Content) Summary

func (cnt *Content) Summary() string

Summary returns content summary. Summary text means the part before page-break <!--more-->. It can be go-markdown rendered.

func (*Content) TagString

func (cnt *Content) TagString() string

TagString returns content tags in a string that's joined by ",".

func (*Content) User

func (cnt *Content) User() *User

User returns content author user instance.

type File

type File struct {
	Id          int
	Name        string
	UploadTime  int64
	Url         string
	ContentType string
	Author      int
	IsUsed      bool
	Size        int64
	Type        string
	Hits        int
}

func CreateFile

func CreateFile(f *File) *File

func GetFileList

func GetFileList(page, size int) ([]*File, *utils.Pager)

type Message added in v0.2.0

type Message struct {
	Id         int
	Type       string
	CreateTime int64
	Data       string
	IsRead     bool
}

func CreateMessage added in v0.2.0

func CreateMessage(tp string, data interface{}) *Message

func GetMessage added in v0.2.0

func GetMessage(id int) *Message

func GetMessages added in v0.2.0

func GetMessages() []*Message

func GetTypedMessages added in v0.2.0

func GetTypedMessages(tp string, unread bool) []*Message

func GetUnreadMessages added in v0.2.0

func GetUnreadMessages() []*Message

type Reader

type Reader struct {
	Author   string
	Email    string
	Url      string
	Active   bool
	Comments int
	Rank     int
}

Comment Reader struct. Saving comment reader for visiting wall usage or other statics.

func GetReaders added in v0.2.5

func GetReaders() []*Reader

GetReaders returns slice of all readers

func (*Reader) Dec

func (r *Reader) Dec()

Dec decreases Reader's rank.

func (*Reader) Inc

func (r *Reader) Inc()

Inc increases Reader's rank.

type Statis added in v0.1.5

type Statis struct {
	Comments int
	Articles int
	Pages    int
	Files    int
	Version  int
	Readers  int
}

func NewStatis added in v0.1.5

func NewStatis() *Statis

type Tag added in v0.2.5

type Tag struct {
	Name string
	Cid  []int
}

Content Tag struct. It convert tag string to proper struct or link.

func GetContentTags added in v0.2.5

func GetContentTags() []*Tag

GetContentTags returns all tags.

func (t *Tag) Link() string

Link returns tag name url-encoded link.

type Token

type Token struct {
	Value      string
	UserId     int
	CreateTime int64
	ExpireTime int64
}

func CreateToken

func CreateToken(u *User, context *GoInk.Context, expire int64) *Token

create new token from user and context.

func GetTokenByValue

func GetTokenByValue(v string) *Token

get token by token value.

func GetTokensByUser

func GetTokensByUser(u *User) []*Token

get tokens of given user.

func (*Token) IsValid

func (t *Token) IsValid() bool

check token is valid or expired.

type User

type User struct {
	Id            int
	Name          string
	Password      string
	Nick          string
	Email         string
	Avatar        string
	Url           string
	Bio           string
	CreateTime    int64
	LastLoginTime int64
	Role          string
}

func GetUserByEmail

func GetUserByEmail(email string) *User

get a user by given email.

func GetUserById

func GetUserById(id int) *User

get a user by given id.

func GetUserByName

func GetUserByName(name string) *User

get a user by given name.

func GetUsersByRole

func GetUsersByRole(role string) []*User

get users of given role.

func (*User) ChangeEmail

func (u *User) ChangeEmail(email string) bool

change user email. check unique.

func (*User) ChangePassword

func (u *User) ChangePassword(pwd string)

change user password.

func (*User) CheckPassword

func (u *User) CheckPassword(pwd string) bool

check user password.

Jump to

Keyboard shortcuts

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