model

package
v0.0.0-...-2ce84b7 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NextTimeID

func NextTimeID() string

func RandomID

func RandomID() string

RandomID 返回一个随机字符串,与 IncreaseID 无关。

func TimeID

func TimeID() string

TimeID 返回一个基于时间的 ID, 与 IncreaseID 无关。

func TimeNow

func TimeNow() string

TimeNow .

Types

type IncreaseID

type IncreaseID struct {
	Year  int
	Count int
}

IncreaseID 用来记录自动生成 ID 的状态,便于生成特有的自增 ID. 该 ID 由年份与自增数两部分组成,分别取两个部分的 36 进制, 转字符串后拼接而成。

func FirstID

func FirstID() IncreaseID

FirstID 生成初始 id, 当且仅当程序每一次使用时(数据库为空时)使用该函数, 之后应使用 Increase 函数来获得新 id.

func ParseID

func ParseID(strID string) (id IncreaseID, err error)

ParseID 把字符串形式的 id 转换为 IncreaseID. (有“万年虫”问题,但是当然,这个问题可以忽略。)

func (IncreaseID) Increase

func (id IncreaseID) Increase() IncreaseID

Increase 使 id 自增一次,输出自增后的新 id. 如果当前年份大于 id 中的年份,则年份进位,Count 重新计数。 否则,年份不变,Count 加一。

func (IncreaseID) String

func (id IncreaseID) String() string

String 返回 id 的字符串形式。

type Note

type Note struct {
	ID        string // primary key
	Type      NoteType
	Title     string
	Patches   []string
	Size      int
	Tags      []tagset.Tag
	Deleted   bool
	RemindAt  string // ISO8601
	CreatedAt string
	UpdatedAt string
}

func NewNote

func NewNote(id, title, patch, remindAt string, noteType NoteType, tagNames []string) (
	*Note, error)

NewNote .

func NoteFrom

func NoteFrom(oldNote OldNote) Note

func (*Note) AddPatch

func (note *Note) AddPatch(patch string) error

AddPatch 填充内容,同时设置 size。 请总是使用 AddPatch 而不要直接操作 note.Patches, 以确保体积和标题正确。

func (*Note) AddPatchNow

func (note *Note) AddPatchNow(patch, contents string) error

AddPatchNow combines AddPatchSetTitle and UpdatedAtNow.

func (*Note) AddPatchSetTitle

func (note *Note) AddPatchSetTitle(patch, contents string) error

AddPatchSetTitle .

func (*Note) SetNewTags

func (note *Note) SetNewTags(tagNames []string) error

SetNewTags 对标签进行一些验证和处理(例如除重和排序)。 尽量不要直接操作 note.Tags

func (*Note) SetTitle

func (note *Note) SetTitle(contents string)

SetTitle 设置限定长度的标题,其中 contents 必须事先 TrimSpace 并确保不是空字串。

func (*Note) UpdateTitleSizeNow

func (note *Note) UpdateTitleSizeNow(title string, patchSize int) error

type NoteType

type NoteType string

NoteType 是一个枚举类型,用来区分 Note 的类型。

const (
	Plaintext NoteType = "Plaintext"
	Markdown  NoteType = "Markdown"
)

func NewNoteType

func NewNoteType(noteType string) NoteType

NewNoteType .

type OldNote

type OldNote struct {
	ID        string // primary key
	Type      NoteType
	Title     string
	Patches   []string
	Size      int
	Tags      []string
	Deleted   bool
	RemindAt  string `storm:"index"`
	CreatedAt string `storm:"index"` // ISO8601
	UpdatedAt string `storm:"index"`
}

type Patch

type Patch = diffmatchpatch.Patch

type Tag

type Tag struct {
	ID        string
	Name      string
	Count     int
	CreatedAt string // ISO8601
}

Tag .

func NewTag

func NewTag(name string) *Tag

NewTag .

type TagGroup

type TagGroup struct {
	ID        string // primary key, random
	Tags      []string
	Protected bool
	CreatedAt string // ISO8601
	UpdatedAt string
}

TagGroup 标签组,其中 Tags 应该除重和排序。

func NewTagGroup

func NewTagGroup(tags []string) *TagGroup

NewTagGroup .

func (*TagGroup) RenameTag

func (group *TagGroup) RenameTag(oldName, newName string)

RenameTag .

Jump to

Keyboard shortcuts

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