feat: add s3 blob handler(by readll all :( )

This commit is contained in:
loveuer
2024-05-05 19:11:57 +08:00
parent 410a4c0d8d
commit 105d26efe4
30 changed files with 1483 additions and 19 deletions

View File

@ -0,0 +1,55 @@
package enums
import (
"encoding/json"
"fmt"
"nf-repo/internal/interfaces"
)
type Privilege uint64
const (
PrivilegeUserManage Privilege = iota + 1
PrivilegeUpload
)
func (p Privilege) Value() int64 {
return int64(p)
}
func (p Privilege) Code() string {
switch p {
case PrivilegeUserManage:
return "user_manage"
case PrivilegeUpload:
return "image_upload"
default:
panic(fmt.Sprintf("unknown privilege: %d", p))
}
}
func (p Privilege) Label() string {
switch p {
case PrivilegeUserManage:
return "用户管理"
case PrivilegeUpload:
return "上传镜像"
default:
panic(fmt.Sprintf("unknown privilege: %d", p))
}
}
func (p Privilege) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]any{
"code": p.Code(),
"value": p.Value(),
"label": p.Label(),
})
}
func (p Privilege) All() []interfaces.Enum {
return []interfaces.Enum{
PrivilegeUserManage,
PrivilegeUpload,
}
}

View File

@ -0,0 +1,72 @@
package enums
import (
"encoding/json"
"fmt"
"gorm.io/gorm"
"nf-repo/internal/interfaces"
"nf-repo/internal/opt"
)
type Role uint8
var _ interfaces.Enum = (*Role)(nil)
func (u Role) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]any{
"code": u.Code(),
"value": u.Value(),
"label": u.Label(),
})
}
const (
RoleRoot Role = 255
RoleAdmin Role = 254
RoleUser Role = 100
)
func (u Role) Code() string {
switch u {
case RoleRoot:
return "root"
case RoleAdmin:
return "admin"
case RoleUser:
return "user"
default:
panic(fmt.Sprintf("unknown role: %d", u))
}
}
func (u Role) Label() string {
switch u {
case RoleRoot:
return "根用户"
case RoleAdmin:
return "管理员"
case RoleUser:
return "用户"
default:
panic(fmt.Sprintf("unknown role: %d", u))
}
}
func (u Role) Value() int64 {
return int64(u)
}
func (u Role) All() []interfaces.Enum {
return []interfaces.Enum{
RoleAdmin,
RoleUser,
}
}
func (u Role) Where(db *gorm.DB) *gorm.DB {
if opt.RoleMustLess {
return db.Where("users.role < ?", u.Value())
} else {
return db.Where("users.role <= ?", u.Value())
}
}

View File

@ -0,0 +1,54 @@
package enums
import (
"encoding/json"
"nf-repo/internal/interfaces"
)
type Status uint64
const (
StatusNormal Status = iota
StatusFrozen
)
func (s Status) Value() int64 {
return int64(s)
}
func (s Status) Code() string {
switch s {
case StatusNormal:
return "normal"
case StatusFrozen:
return "frozen"
default:
return "unknown"
}
}
func (s Status) Label() string {
switch s {
case StatusNormal:
return "正常"
case StatusFrozen:
return "冻结"
default:
return "异常"
}
}
func (s Status) All() []interfaces.Enum {
return []interfaces.Enum{
StatusNormal,
StatusFrozen,
}
}
func (s Status) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]any{
"value": s.Value(),
"code": s.Code(),
"label": s.Label(),
})
}