model

package
v0.0.0-...-e0636f1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GosendZip 是自定义的文件类型,表示自动打包的文件,避免重复打包。
	GosendZip = "gosend/zip"

	// GosendAnchor 是自定义的文件类型,但不用于文件,而是用于 TextMsg,
	// 表示该文本内容是网址 (html 的 a 标签)
	GosendAnchor = "gosend/anchor"
)
View Source
const (
	// FileNameMinLength 规定包括后缀名在内文件名长度不可小于 5.
	FileNameMinLength = 3
)
View Source
const ISO8601 = "2006-01-02T15:04:05.999+00:00"

ISO8601 需要根据服务器的具体时区来设定正确的时区

Variables

This section is empty.

Functions

This section is empty.

Types

type ClipText

type ClipText struct {
	ID        string // primary key
	Type      MsgType
	TextMsg   string
	FileName  string `storm:"index"`
	FileSize  int64
	FileType  string // MIME
	Checksum  string `storm:"unique"` // hex(sha256)
	CreatedAt string `storm:"index"`  // ISO8601
	UpdatedAt string `storm:"index"`
	DeletedAt string `storm:"index"`
}

ClipText 表示剪贴板文本消息,创建新的类型只是为了方便在数据库里创建一个独立的 bucket, 结构与 Message 一样。

func NewClipText

func NewClipText(id string, msgType MsgType) *ClipText

NewClipText .

func (*ClipText) SetTextMsg

func (clip *ClipText) SetTextMsg(textMsg string) error

SetTextMsg .

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 Message

type Message struct {
	ID        string // primary key
	Type      MsgType
	TextMsg   string
	FileName  string `storm:"index"`
	FileSize  int64
	FileType  string // MIME
	Checksum  string `storm:"unique"` // hex(sha256)
	CreatedAt string `storm:"index"`  // ISO8601
	UpdatedAt string `storm:"index"`
	DeletedAt string `storm:"index"`
}

Message 表示一个数据表。 本来想过用 Note 来命名,但考虑到不管是熟人间互传还是个人设备间互传, 也不管互传文件还是互传文本信息,都更适合用 “消息、信息” 而不是 “笔记”。

func NewMessage

func NewMessage(id string, msgType MsgType) *Message

NewMessage .

func (*Message) IsImage

func (message *Message) IsImage() bool

IsImage .

func (*Message) SetFileNameType

func (message *Message) SetFileNameType(filename string) error

SetFileNameType 同时设置 FileName 和 FileType. 注意不可直接设置 FileName, 每次都应该使用 SetFileNameType 以确保同时设置 FileType.

func (*Message) SetTextMsg

func (message *Message) SetTextMsg(textMsg string) error

SetTextMsg 同时更新 TextMsg 和 FileSize, 注意不可直接设置 TextMsg, 每次都应该使用 SetTextMsg 以确保同时设置 FileSize.

type MsgType

type MsgType string

MsgType 是一个枚举类型,用来区分 Message 的类型。

const (
	// TextMsg 是文本信息,不带文件。
	TextMsg MsgType = "TextMsg"

	// FileMsg 是文件信息,带有文件。
	FileMsg MsgType = "FileMsg"
)

Jump to

Keyboard shortcuts

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