model

package module
v0.0.0-...-c6fc58e Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorSerializer schema.SerializerInterface = Serializer[error, string]{
	Scanner: errors.New,
	Valuer:  error.Error,
}

ErrorSerializer 用来序列化和反序列化错误接口

View Source
var URLSerializer schema.SerializerInterface = Serializer[*url.URL, string]{
	Scanner: req.MustParseURL,
	Valuer:  (*url.URL).String,
}

URLSerializer 用来序列化和反序列化 *url.URL

Functions

func ToHTTPCookies

func ToHTTPCookies(models []Cookie) []*http.Cookie

ToHTTPCookies 将 GORM 模型切片转换成 *http.Cookie 切片

Types

type Blog

type Blog struct {
	ID         uint64    `json:"id" gorm:"primaryKey;autoIncrement"`                                   // 数据库内标识符
	UID        string    `json:"uid" gorm:"index:idx_blogs;index:idx_type_blogs"`                      // 博主标识符
	Name       string    `json:"name"`                                                                 // 博主昵称
	Desc       string    `json:"desc"`                                                                 // 个人简介
	Avatar     string    `json:"avatar"`                                                               // 头像链接
	Banner     string    `json:"banner"`                                                               // 头图链接
	Follower   string    `json:"follower"`                                                             // 粉丝数量
	Following  string    `json:"following"`                                                            // 关注数量
	MID        string    `json:"mid" gorm:"column:mid;index:idx_match"`                                // 博文标识符
	URL        string    `json:"url"`                                                                  // 博文链接
	Site       string    `json:"site" gorm:"index:idx_blogs;index:idx_type_blogs;index:idx_match"`     // 发布网站
	Type       string    `json:"type" gorm:"index:idx_type_blogs;index:idx_match"`                     // 博文类型
	Time       time.Time `json:"time" gorm:"index:idx_blogs,sort:desc;index:idx_type_blogs,sort:desc"` // 发布时间
	Title      string    `json:"title"`                                                                // 博文标题
	Source     string    `json:"source"`                                                               // 博文来源
	Version    string    `json:"version" gorm:"index:idx_match"`                                       // 编辑版本
	Content    string    `json:"content"`                                                              // 原始内容
	Plaintext  string    `json:"plaintext"`                                                            // 纯文本内容
	Assets     []string  `json:"assets" gorm:"serializer:json"`                                        // 资源链接
	Reply      *Blog     `json:"reply"`                                                                // 被本文回复的博文
	ReplyID    *uint64   `json:"-"`                                                                    // 被本文回复的博文的数据库标识符
	Comments   []*Blog   `json:"comments"`                                                             // 本文的所有评论,包括二级评论
	BlogID     *uint64   `json:"-"`                                                                    // 如果本文是评论,则为根博文的数据库标识符
	Uploader   *User     `json:"uploader"`                                                             // 上传者
	UploaderID string    `json:"-" gorm:"index:idx_match"`                                             // 上传者标识符
	Extra      Extra     `json:"extra" gorm:"serializer:json"`                                         // 扩展字段
	Created    time.Time `json:"created" gorm:"autoCreateTime"`                                        // 博文创建时间
}

Blog 博文模型

func (*Blog) BeforeCreate

func (b *Blog) BeforeCreate(tx *gorm.DB) error

func (*Blog) Match

func (b *Blog) Match(tx *gorm.DB) *gorm.DB

Match 匹配当前博文

func (Blog) String

func (b Blog) String() string
type Cookie struct {
	Name        string
	Value       string
	Quoted      bool
	CreatedAt   time.Time
	CookieJarID uint64
}

Cookie 是用于 GORM 存取的 Cookie 模型

func FromHTTPCookies

func FromHTTPCookies(cookies []*http.Cookie) []Cookie

FromHTTPCookies 将 *http.Cookie 切片转换成 GORM 模型切片

func (*Cookie) From

func (c *Cookie) From(cookie *http.Cookie)

From 将 *http.Cookie 转换成 GORM 模型

func (*Cookie) To

func (c *Cookie) To() *http.Cookie

To 将 GORM 模型转换成 *http.Cookie

type CookieJar

type CookieJar struct {
	ID        uint64         `gorm:"primaryKey;autoIncrement"`
	URL       *url.URL       `gorm:"serializer:url"`
	Jar       http.CookieJar `gorm:"-"`
	Cookies   []Cookie
	CreatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

CookieJar 是用于 GORM 存取 http.CookieJar 的模型

func (*CookieJar) AfterFind

func (c *CookieJar) AfterFind(*gorm.DB) error

AfterFind 在查询后将数据写入 http.CookieJar

func (*CookieJar) BeforeSave

func (c *CookieJar) BeforeSave(*gorm.DB) error

BeforeSave 在保存前读取 http.CookieJar 中数据

func (*CookieJar) ReadFrom

func (c *CookieJar) ReadFrom(jar http.CookieJar)

ReadFrom 从 http.CookieJar 中读取 Cookies 到刷新器

func (*CookieJar) WriteTo

func (c *CookieJar) WriteTo(jar http.CookieJar)

WriteTo 将刷新器中的 Cookies 写入 http.CookieJar

type Database

type Database string

func (Database) Open

func (d Database) Open(dst ...any) (*gorm.DB, error)

type Extra

type Extra map[string]any

Extra 扩展字段

type Filter

type Filter struct {
	Contributor string `json:"contributor" form:"contributor"` // 博文贡献者
	Platform    string `json:"platform" form:"platform"`       // 发布平台
	Type        string `json:"type" form:"type"`               // 博文类型
	UID         string `json:"uid" form:"uid"`                 // 账户序号
	TaskID      uint64 `json:"-" form:"-"`                     // 外键
}

博文筛选条件,用来描述一类博文,例如:

filter1 表示所有平台为 "weibo"、类型为 "comment" 的博文

filter2 表示所有由 "114" 提交的用户 "514" 的博文

var filter1 = Filter{
	Platform: "weibo",
	Type: "comment",
}

var filter2 = Filter{
	Contributor: "114",
	UID: "514",
}

func (Filter) IsValid

func (f Filter) IsValid() bool

func (Filter) IsZero

func (f Filter) IsZero() bool

type RequestLog

type RequestLog struct {
	StartedAt time.Time `json:"started_at"`
	CreatedAt time.Time `json:"created_at"`
	BlogID    uint64    `json:"blog_id"`
	Result    any       `json:"result" gorm:"serializer:json"` // 响应为 JSON 会自动解析
	Error     error     `json:"error"`                         // 请求过程中发生的错误
	TaskID    uint64    `json:"-" gorm:"index:idx_logs_query"` // 外键
}

请求记录

type Role

type Role uint64

Role 用户权限

const (
	Invalid Role = iota // 无效
	Normal              // 普通
	Trusted             // 信任
	Admin               // 管理员
	Owner               // 所有者
)

func (Role) IsAdmin

func (r Role) IsAdmin() bool

IsAdmin 判断是否有管理权

func (Role) IsOwner

func (r Role) IsOwner() bool

IsOwner 判断是否为所有者

type Serializer

type Serializer[T any, V driver.Value] struct {
	Scanner func(V) T
	Valuer  func(T) V
}

Serializer 在数据库读写时用来序列化和反序列化

func (Serializer[T, V]) Scan

func (s Serializer[T, V]) Scan(ctx context.Context, field *schema.Field, dst reflect.Value, dbValue any) error

Scan implements serializer interface

func (Serializer[T, V]) Value

func (s Serializer[T, V]) Value(ctx context.Context, field *schema.Field, dst reflect.Value, fieldValue any) (any, error)

Value implements serializer interface

type Task

type Task struct {
	ID        uint64         `json:"id" gorm:"primaryKey;autoIncrement"`
	CreatedAt time.Time      `json:"created_at"`
	DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`

	Public bool `json:"public"` // 是否公开
	Enable bool `json:"enable"` // 是否启用

	Name        string `json:"name"`        // 任务名称
	Description string `json:"description"` // 任务简介

	Icon   string `json:"icon"`   // 任务图标
	Banner string `json:"banner"` // 任务头图
	Readme string `json:"readme"` // 任务描述

	ForkID    uint64 `json:"fork_id"`             // 复刻来源
	ForkCount uint64 `json:"fork_count" gorm:"-"` // 被复刻次数

	UserID string `json:"user_id"` // 外键

	Template string `json:"templates"` // 请求模板

	Filters []Filter     `json:"filters"` // 筛选条件
	Logs    []RequestLog `json:"logs"`    // 请求记录
}

任务

func (*Task) AfterFind

func (t *Task) AfterFind(tx *gorm.DB) error

func (*Task) BeforeCreate

func (t *Task) BeforeCreate(*gorm.DB) error

type User

type User struct {
	UID      string    `json:"uid" gorm:"primaryKey"`         // 用户标识符
	Name     string    `json:"name"`                          // 用户名
	Role     Role      `json:"role"`                          // 权限
	Title    string    `json:"title"`                         // 头衔
	Password string    `json:"-"`                             // 密码
	Created  time.Time `json:"created" gorm:"autoCreateTime"` // 建号时间
	Issued   time.Time `json:"-"`                             // 签发时间
	Unban    time.Time `json:"unban"`                         // 解封时间
	Extra    Extra     `json:"-" gorm:"serializer:json"`      // 扩展字段
}

User 用户模型

Jump to

Keyboard shortcuts

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