Help us shape the future of Go! Take the 2026 Go Developer Survey

request

package
v0.32.13 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package request 寄件码/反向收件(P2):用户创建投递链接,访客凭链接上传, 文件以链接主人名义成为普通分享(复用分享过期/清理/通知机制)。

设计参照 Gokapi File Requests / Pingvin reverse share:

  • token 32 hex(crypto/rand),链接 /#/request/<token>
  • 约束:单次投递文件数/总大小上限、链接有效期(创建者设定)
  • 访客投递不走 upload.open_upload 总闸(显式受邀上传,与 Gokapi 同策略)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateReq

type CreateReq struct {
	Title       string
	MaxFiles    int
	MaxBytes    int64
	ExpireValue int
	ExpireStyle string // minute/hour/day/week/month/year/forever;空 = 7 天(不支持 count:该通道按时间过期)
}

CreateReq 创建投递链接入参

type NotifySender

type NotifySender interface {
	CreateForUserSimple(ctx context.Context, userID uint, title, content, notifyType, level string) error
}

NotifySender 投递到件通知(notify service 实现)

type PublicView

type PublicView struct {
	Token     string     `json:"token"`
	Title     string     `json:"title"`
	MaxFiles  int        `json:"max_files"`
	MaxBytes  int64      `json:"max_bytes"`
	ExpiredAt *time.Time `json:"expired_at"`
}

PublicView 访客侧链接信息

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service 寄件码服务

func NewService

func NewService(gormDB *gorm.DB, shareSvc ShareGateway, notify NotifySender) *Service

NewService 构建服务。shareSvc 为分享创建网关(未注入时投递创建分享会失败)。

func (*Service) Create

func (s *Service) Create(ctx context.Context, userID uint, req CreateReq) (*model.FileRequest, error)

Create 创建投递链接

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, userID uint, token string) (bool, error)

Delete 撤销链接(仅属主)

func (*Service) GetPublic

func (s *Service) GetPublic(ctx context.Context, token string) (*PublicView, error)

GetPublic 访客取链接信息(过期/撤销 → 错误)

func (*Service) ListForUser

func (s *Service) ListForUser(ctx context.Context, userID uint) ([]*model.FileRequest, error)

ListForUser 用户的投递链接列表

func (*Service) Submit

func (s *Service) Submit(ctx context.Context, token string, entries []storage.StoredFileEntry, guestIP string) (*ShareResult, error)

Submit 访客投递(entries 已落存储;此处做约束校验并创建归属分享)。 失败时调用方负责清理已落盘文件。

type ShareCreateRequest

type ShareCreateRequest struct {
	Entries      []storage.StoredFileEntry
	OwnerID      uint
	OwnerIP      string
	Channel      string
	ExpiredAt    *time.Time
	ExpiredCount int
}

ShareCreateRequest 投递转分享的装配参数(网关实现适配为具体分享域的请求)。

type ShareGateway

type ShareGateway interface {
	CreateFromFileEntries(ctx context.Context, req *ShareCreateRequest) (*ShareResult, error)
}

ShareGateway 分享创建网关(消费侧接口;bootstrap 注入 share 域适配器, 本域不直接依赖 share 包——跨域依赖收口为单一装配点)。

type ShareResult

type ShareResult struct {
	ID         uint
	Code       string
	PickupCode string // 6 位取件码(未铸造为空)
	Size       int64
}

ShareResult 投递落地结果(调用方需要的最小字段)。

Jump to

Keyboard shortcuts

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