serializer

package
v0.0.0-...-746aa3e Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CodeNotFullySuccess 未完全成功
	CodeNotFullySuccess = 203
	// CodeCheckLogin 未登录
	CodeCheckLogin = 401
	// CodeNoPermissionErr 未授权访问
	CodeNoPermissionErr = 403
	// CodeNotFound 资源未找到
	CodeNotFound = 404
	// CodeUploadFailed 上传出错
	CodeUploadFailed = 40002
	// CodeCreateFolderFailed 目录创建失败
	CodeCreateFolderFailed = 40003
	// CodeObjectExist 对象已存在
	CodeObjectExist = 40004
	// CodeSignExpired 签名过期
	CodeSignExpired = 40005
	// CodePolicyNotAllowed 当前存储策略不允许
	CodePolicyNotAllowed = 40006
	// CodeGroupNotAllowed 用户组无法进行此操作
	CodeGroupNotAllowed = 40007
	// CodeAdminRequired 非管理用户组
	CodeAdminRequired = 40008
	// CodeDBError 数据库操作失败
	CodeDBError = 50001
	// CodeEncryptError 加密失败
	CodeEncryptError = 50002
	// CodeIOFailed IO操作失败
	CodeIOFailed = 50004
	// CodeInternalSetting 内部设置参数错误
	CodeInternalSetting = 50005
	// CodeCacheOperation 缓存操作失败
	CodeCacheOperation = 50006
	// CodeCallbackError 回调失败
	CodeCallbackError = 50007
	//CodeParamErr 各种奇奇怪怪的参数错误
	CodeParamErr = 40001
	// CodeNotSet 未定错误,后续尝试从error中获取
	CodeNotSet = -1
)

三位数错误编码为复用http原本含义 五位数错误编码为应用自定义错误 五开头的五位数错误编码为服务器端错误,比如数据库操作失败 四开头的五位数错误编码为客户端错误,有时候是客户端代码写错了,有时候是用户操作错误

Variables

This section is empty.

Functions

func NewRequestSignString

func NewRequestSignString(path, policy, body string) string

NewRequestSignString 返回JSON格式的待签名字符串 TODO 测试

Types

type AppError

type AppError struct {
	Code     int
	Msg      string
	RawError error
}

AppError 应用错误,实现了error接口

func NewError

func NewError(code int, msg string, err error) AppError

NewError 返回新的错误对象 todo:测试 还有下面的

func (AppError) Error

func (err AppError) Error() string

Error 返回业务代码确定的可读错误信息

func (*AppError) WithError

func (err *AppError) WithError(raw error) AppError

WithError 将应用error携带标准库中的error

type DownloadListResponse

type DownloadListResponse struct {
	UpdateTime     int64          `json:"update"`
	UpdateInterval int            `json:"interval"`
	Name           string         `json:"name"`
	Status         int            `json:"status"`
	Dst            string         `json:"dst"`
	Total          uint64         `json:"total"`
	Downloaded     uint64         `json:"downloaded"`
	Speed          int            `json:"speed"`
	Info           rpc.StatusInfo `json:"info"`
}

DownloadListResponse 下载列表响应条目

type FinishedListResponse

type FinishedListResponse struct {
	Name       string         `json:"name"`
	Status     int            `json:"status"`
	Dst        string         `json:"dst"`
	Error      string         `json:"error"`
	Total      uint64         `json:"total"`
	Files      []rpc.FileInfo `json:"files"`
	TaskStatus int            `json:"task_status"`
	TaskError  string         `json:"task_error"`
	CreateTime string         `json:"create"`
	UpdateTime string         `json:"update"`
}

FinishedListResponse 已完成任务条目

type GeneralUploadCallbackFailed

type GeneralUploadCallbackFailed struct {
	Error string `json:"error"`
}

GeneralUploadCallbackFailed 存储策略上传回调失败响应

type ListRequest

type ListRequest struct {
	Path      string `json:"path"`
	Recursive bool   `json:"recursive"`
}

ListRequest 远程策略列文件请求正文

type RemoteDeleteRequest

type RemoteDeleteRequest struct {
	Files []string `json:"files"`
}

RemoteDeleteRequest 远程策略删除接口请求正文

type RequestRawSign

type RequestRawSign struct {
	Path   string
	Policy string
	Body   string
}

RequestRawSign 待签名的HTTP请求

type Response

type Response struct {
	Code  int         `json:"code"`
	Data  interface{} `json:"data,omitempty"`
	Msg   string      `json:"msg"`
	Error string      `json:"error,omitempty"`
}

Response 基础序列化器

func BuildDownloadingResponse

func BuildDownloadingResponse(tasks []model.Download) Response

BuildDownloadingResponse 构建正在下载的列表响应

func BuildFinishedListResponse

func BuildFinishedListResponse(tasks []model.Download) Response

BuildFinishedListResponse 构建已完成任务条目

func BuildShareList

func BuildShareList(shares []model.Share, total int) Response

BuildShareList 构建我的分享列表响应

func BuildSiteConfig

func BuildSiteConfig(settings map[string]string, user *model.User) Response

BuildSiteConfig 站点全局设置

func BuildTaskList

func BuildTaskList(tasks []model.Task, total int) Response

BuildTaskList 构建任务列表响应

func BuildUserResponse

func BuildUserResponse(user model.User) Response

BuildUserResponse 序列化用户响应

func BuildUserStorageResponse

func BuildUserStorageResponse(user model.User) Response

BuildUserStorageResponse 序列化用户存储概况响应

func CheckLogin

func CheckLogin() Response

CheckLogin 检查登录

func DBErr

func DBErr(msg string, err error) Response

DBErr 数据库操作失败

func Err

func Err(errCode int, msg string, err error) Response

Err 通用错误处理

func ParamErr

func ParamErr(msg string, err error) Response

ParamErr 各种参数错误

type Share

type Share struct {
	Key        string        `json:"key"`
	Locked     bool          `json:"locked"`
	IsDir      bool          `json:"is_dir"`
	CreateDate string        `json:"create_date,omitempty"`
	Downloads  int           `json:"downloads"`
	Views      int           `json:"views"`
	Expire     int64         `json:"expire"`
	Preview    bool          `json:"preview"`
	Creator    *shareCreator `json:"creator,omitempty"`
	Source     *shareSource  `json:"source,omitempty"`
}

Share 分享信息序列化

func BuildShareResponse

func BuildShareResponse(share *model.Share, unlocked bool) Share

BuildShareResponse 构建获取分享信息响应

type SiteConfig

type SiteConfig struct {
	SiteName           string `json:"title"`
	SiteICPId          string `json:"siteICPId"`
	LoginCaptcha       bool   `json:"loginCaptcha"`
	RegCaptcha         bool   `json:"regCaptcha"`
	ForgetCaptcha      bool   `json:"forgetCaptcha"`
	EmailActive        bool   `json:"emailActive"`
	Themes             string `json:"themes"`
	DefaultTheme       string `json:"defaultTheme"`
	HomepageViewMethod string `json:"home_view_method"`
	ShareViewMethod    string `json:"share_view_method"`
	Authn              bool   `json:"authn"`
	User               User   `json:"user"`
	UseReCaptcha       bool   `json:"captcha_IsUseReCaptcha"`
	ReCaptchaKey       string `json:"captcha_ReCaptchaKey"`
}

SiteConfig 站点全局设置序列

type UploadCallback

type UploadCallback struct {
	Name       string `json:"name"`
	SourceName string `json:"source_name"`
	PicInfo    string `json:"pic_info"`
	Size       uint64 `json:"size"`
}

UploadCallback 上传回调正文

type UploadCredential

type UploadCredential struct {
	Token     string `json:"token"`
	Policy    string `json:"policy"`
	Path      string `json:"path"` // 存储路径
	AccessKey string `json:"ak"`
	KeyTime   string `json:"key_time,omitempty"` // COS用有效期
	Callback  string `json:"callback,omitempty"` // 回调地址
	Key       string `json:"key,omitempty"`      // 文件标识符,通常为回调key
}

UploadCredential 返回给客户端的上传凭证

type UploadPolicy

type UploadPolicy struct {
	SavePath         string   `json:"save_path"`
	FileName         string   `json:"file_name"`
	AutoRename       bool     `json:"auto_rename"`
	MaxSize          uint64   `json:"max_size"`
	AllowedExtension []string `json:"allowed_extension"`
	CallbackURL      string   `json:"callback_url"`
}

UploadPolicy slave模式下传递的上传策略

func DecodeUploadPolicy

func DecodeUploadPolicy(raw string) (*UploadPolicy, error)

DecodeUploadPolicy 反序列化Header中携带的上传策略

func (*UploadPolicy) EncodeUploadPolicy

func (policy *UploadPolicy) EncodeUploadPolicy() (string, error)

EncodeUploadPolicy 序列化Header中携带的上传策略

type UploadSession

type UploadSession struct {
	Key         string
	UID         uint
	PolicyID    uint
	VirtualPath string
	Name        string
	Size        uint64
	SavePath    string
}

UploadSession 上传会话

type User

type User struct {
	ID             string `json:"id"`
	Email          string `json:"user_name"`
	Nickname       string `json:"nickname"`
	Status         int    `json:"status"`
	Avatar         string `json:"avatar"`
	CreatedAt      int64  `json:"created_at"`
	PreferredTheme string `json:"preferred_theme"`
	Anonymous      bool   `json:"anonymous"`
	Policy         policy `json:"policy"`
	Group          group  `json:"group"`
	Tags           []tag  `json:"tags"`
}

User 用户序列化器

func BuildUser

func BuildUser(user model.User) User

BuildUser 序列化用户

type WebAuthnCredentials

type WebAuthnCredentials struct {
	ID          []byte `json:"id"`
	FingerPrint string `json:"fingerprint"`
}

WebAuthnCredentials 外部验证器凭证

func BuildWebAuthnList

func BuildWebAuthnList(credentials []webauthn.Credential) []WebAuthnCredentials

BuildWebAuthnList 构建设置页面凭证列表

Jump to

Keyboard shortcuts

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