项目初始化
This commit is contained in:
11
internal/model/admin.go
Normal file
11
internal/model/admin.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Admin struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
PasswordHash string `json:"-"`
|
||||
LastLogin *time.Time `json:"last_login"`
|
||||
}
|
||||
16
internal/model/api_token.go
Normal file
16
internal/model/api_token.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type APIToken struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Name string `json:"name"`
|
||||
TokenHash string `gorm:"uniqueIndex;not null" json:"-"`
|
||||
Scope string `json:"scope"`
|
||||
ExpireAt *time.Time `json:"expire_at"`
|
||||
LastUsedAt *time.Time `json:"last_used_at"`
|
||||
Revoked bool `gorm:"default:false" json:"revoked"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
22
internal/model/file_batch.go
Normal file
22
internal/model/file_batch.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type FileBatch struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
PickupCode string `gorm:"uniqueIndex;not null" json:"pickup_code"`
|
||||
Remark string `json:"remark"`
|
||||
ExpireType string `json:"expire_type"` // time / download / permanent
|
||||
ExpireAt *time.Time `json:"expire_at"`
|
||||
MaxDownloads int `json:"max_downloads"`
|
||||
DownloadCount int `gorm:"default:0" json:"download_count"`
|
||||
Status string `gorm:"default:'active'" json:"status"` // active / expired / deleted
|
||||
FileItems []FileItem `gorm:"foreignKey:BatchID" json:"file_items,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
15
internal/model/file_item.go
Normal file
15
internal/model/file_item.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type FileItem struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
BatchID uint `gorm:"index;not null" json:"batch_id"`
|
||||
OriginalName string `json:"original_name"`
|
||||
StoragePath string `json:"storage_path"`
|
||||
Size int64 `json:"size"`
|
||||
MimeType string `json:"mime_type"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
45
internal/model/response.go
Normal file
45
internal/model/response.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package model
|
||||
|
||||
// Response 统一响应模型
|
||||
type Response struct {
|
||||
Code int `json:"code" example:"200"`
|
||||
Msg string `json:"msg" example:"success"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
// 错误码定义
|
||||
const (
|
||||
CodeSuccess = 200
|
||||
CodeBadRequest = 400
|
||||
CodeUnauthorized = 401
|
||||
CodeForbidden = 403
|
||||
CodeNotFound = 404
|
||||
CodeGone = 410
|
||||
CodeInternalError = 500
|
||||
)
|
||||
|
||||
// NewResponse 创建响应
|
||||
func NewResponse(code int, msg string, data interface{}) Response {
|
||||
return Response{
|
||||
Code: code,
|
||||
Msg: msg,
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
// SuccessResponse 成功响应
|
||||
func SuccessResponse(data interface{}) Response {
|
||||
return Response{
|
||||
Code: CodeSuccess,
|
||||
Msg: "success",
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
// ErrorResponse 错误响应
|
||||
func ErrorResponse(code int, msg string) Response {
|
||||
return Response{
|
||||
Code: code,
|
||||
Msg: msg,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user