model

package
v0.0.0-...-a5018ba Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FileNameMinLength 规定包括后缀名在内文件名长度不可小于 5.
	FileNameMinLength = 3
)

Variables

This section is empty.

Functions

func RandomID

func RandomID() string

RandomID 返回一个上升趋势的随机 id, 由时间戳与随机数组成。 时间戳确保其上升趋势(大致有序),随机数确保其随机性(防止被穷举, 防冲突)。 RandomID 考虑了 “生成 id 的速度”、 “并发防冲突” 与 “id 长度” 这三者的平衡,适用于大多数中、小规模系统(当然,不适用于大型系统)。

func TimeNow

func TimeNow() int64

Types

type File

type File struct {
	ID      string
	Name    string
	Count   int // how many files with the same name
	Size    int64
	Type    string
	Thumb   bool   // has a thumbnail or not
	Hash    string // checksum
	Like    int64  // 点赞
	CTime   int64  // created at
	UTime   int64  // updated at
	Checked int64  // checked at 上次校验时间
	Damaged bool   // 上次校验结果(文件是否损坏)
	Deleted bool
	Tags    []string // 该项目不在数据库中,放在这里只是为了方便
}

File 文件

func NewFile

func NewFile(id string) *File

func (*File) SetNameType

func (file *File) SetNameType(filename string) error

SetNameType 同时设置 Name 和 Type. 使用 SetNameType 可确保正确设置 Type.

func (*File) SetTags

func (file *File) SetTags(names []string) error

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

type ShortID

type ShortID struct {
	Prefix string
	Year   int64
	Count  int64
}

ShortID 用来生成 “可爱” 的自增 ID. 说它可爱是因为它的字符串形式: 1.短 2.由数字和字母组成,不分大小写,且确保以字母开头 3.趋势自增,但又不明显自增 4.可利用前缀分类 该 ID 由前缀、年份与自增数三部分组成,年份与自增数分别转 36 进制字符。 前缀只能是单个字母,因为 ID 还是短一些的好。 注意:前缀不分大小写, ShortID 本身也不分大小写。

func FirstID

func FirstID(prefix string) (id ShortID, err error)

FirstID 生成对应前缀的初始 id, 后续使用 Next 函数来获取下一个 id. prefix 只能是单个英文字母。

func ParseID

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

ParseID 把字符串形式的 id 转换为 IncreaseID. (有“万年虫”问题,大概公元五万年时本算法会出错,当然,这个问题可以忽略。)

func (ShortID) Next

func (id ShortID) Next() ShortID

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

func (ShortID) String

func (id ShortID) String() string

String 返回 id 的字符串形式。

type Tag

type Tag struct {
	ID    string
	CTime int64 // created at
	Count int64 // 该项目不在数据库中,放在这里只是为了方便
}

Tag 标签

func NewTag

func NewTag(id string) *Tag

type TagGroup

type TagGroup struct {
	ID        string // primary key, random
	Tags      []string
	Protected bool
	UTime     int64 // updated at
}

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

func NewTagGroup

func NewTagGroup() *TagGroup

NewTagGroup .

func (*TagGroup) Blob

func (group *TagGroup) Blob() []byte

func (*TagGroup) SetTags

func (group *TagGroup) SetTags(tags []string)

Jump to

Keyboard shortcuts

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