Documentation
¶
Index ¶
- Constants
- func CheckImageType(filename string) (string, error)
- func CreateOrSave(entity *Entity) int64
- type Entity
- func Get(id any) (entity Entity)
- func GetByName(name string) (entity Entity)
- func GetFile(id uint64) (*Entity, error)
- func GetFileByName(name string) (*Entity, error)
- func SaveAvatar(userId uint64, fileData []byte, filename string) (*Entity, error)
- func SaveFile(userId uint64, name string, fileType string, data []byte) (*Entity, error)
- func SaveFileFromUpload(userId uint64, fileData []byte, filename string, customPath string) (*Entity, error)
Constants ¶
View Source
const ( MaxFileSize = 2 * 1024 * 1024 // 2MB AvatarPath = "avatars" )
在 supportedImageTypes 映射后添加新的常量
Variables ¶
This section is empty.
Functions ¶
func CheckImageType ¶
CheckImageType 检查文件类型是否支持,返回对应的 Content-Type
func CreateOrSave ¶
Types ¶
type Entity ¶
type Entity struct {
Id uint64 `gorm:"primaryKey;column:id;autoIncrement;not null;" json:"id"` // 主键
Name string `gorm:"column:name;uniqueIndex;type:varchar(256);not null;" json:"name"` // 添加唯一索引
Type string `gorm:"column:assert_type;index;type:varchar(64);not null;" json:"type"` //
Data []byte `gorm:"column:content;type:BLOB;" json:"data"` // 内容
UserId uint64 `gorm:"column:user_id;index;type:bigint unsigned;not null;default:0;" json:"userId"` //
CreatedAt time.Time `gorm:"column:created_at;index;autoCreateTime;<-:create;" json:"createdAt"` //
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime;" json:"updatedAt"`
}
func GetFileByName ¶
func SaveAvatar ¶
SaveAvatar 现在可以基于通用方法实现
Click to show internal directories.
Click to hide internal directories.