Documentation ¶
Index ¶
- Variables
- func DeleteSessions(uid []uuid.UUID) error
- func FindSessions(uid []uuid.UUID) (map[string]*SessionData, error)
- func GetCTXSession(c *gin.Context) (*sessions.Session, error)
- func GetDefaultID(index DefaultIDIndex) uuid.UUID
- func NewDB()
- func NewRedis()
- func NewSession()
- func ParseCondition(cond *Condition, tx *gorm.DB) *gorm.DB
- func SaveCTXSession(c *gin.Context) error
- func SetDefaultID(index DefaultIDIndex, value uuid.UUID)
- type Condition
- type DBStruct
- type DefaultIDIndex
- type GeneralFields
- type Notification
- type NotifyLevel
- type ORM
- func (o *ORM[T]) Cond(cond *Condition) *ORM[T]
- func (o *ORM[T]) Count(cond *Condition) (int64, error)
- func (o *ORM[T]) Create(value *T) error
- func (o *ORM[T]) Creates(value []*T) error
- func (o *ORM[T]) Delete(conds ...any) (int64, error)
- func (o *ORM[T]) DeleteAll() (int64, error)
- func (o *ORM[T]) DeleteID(id uuid.UUID) (bool, error)
- func (o *ORM[T]) Find(conds ...any) (ret []*T, err error)
- func (o *ORM[T]) ID(id uuid.UUID) *ORM[T]
- func (o *ORM[T]) Joins(query string, args ...any) *ORM[T]
- func (o *ORM[T]) Save(value *T) error
- func (o *ORM[T]) TX() *gorm.DB
- func (o *ORM[T]) Take(conds ...any) (ret *T, err error)
- func (o *ORM[T]) Update(column string, value any) error
- func (o *ORM[T]) Updates(column []string, value *T) error
- func (o *ORM[T]) Where(query any, args ...any) *ORM[T]
- type Permission
- type PermissionList
- type RedisConfig
- type SessionConfig
- type SessionData
- type Setting
- type User
- type UserGroup
- type UserGroupLink
- type UserPerm
Constants ¶
This section is empty.
Variables ¶
View Source
var DB *gorm.DB
View Source
var DefaultID []uuid.UUID // skynet default id
View Source
var ErrSessionInvalid = tracerr.New("session invalid")
View Source
var Redis *redis.Client
View Source
var Session *redisstore.RedisStore
Functions ¶
func DeleteSessions ¶
DeleteSessions deletes all sessions by uid. This equals kick user operation.
If uid=nil, delete all sessions.
func FindSessions ¶
func FindSessions(uid []uuid.UUID) (map[string]*SessionData, error)
FindSessionsByID find all sessions associate to user by uid. When uid = nil, return all sessions.
func GetCTXSession ¶
GetCTXSession gets session object from gin context.
func GetDefaultID ¶
func GetDefaultID(index DefaultIDIndex) uuid.UUID
func ParseCondition ¶
ParseCondition parse Condition to gorm.DB object.
func SaveCTXSession ¶
SaveCTXSession saves session object to gin context.
func SetDefaultID ¶
func SetDefaultID(index DefaultIDIndex, value uuid.UUID)
Types ¶
type Condition ¶
Condition limit condition search, however, sqli is not protected.
Unprotected fields: Order, Distinct, Where(when not use ? as argument form)
Warning: Caller should check user input on their OWN!
type DefaultIDIndex ¶
type DefaultIDIndex int32
const ( GroupRootID DefaultIDIndex = iota // root user group PermAllID // full permission PermUserID // login user permission PermGuestID // guest permission PermManageUserID // manage user PermManageUserPermID // manage user permission PermManageGroupID // manage user group PermManageGroupPermID // manage user group PermManageNotificationID // manage notification PermManageSystemID // manage system PermManagePluginID // manage plugin DefaultIDMax // max id count )
type GeneralFields ¶
type GeneralFields struct { ID uuid.UUID `gorm:"type:uuid;primaryKey;not null" json:"id"` CreatedAt int64 `gorm:"autoCreateTime:milli" json:"created_at"` // create time UpdatedAt int64 `gorm:"autoUpdateTime:milli" json:"updated_at"` // update time }
func (*GeneralFields) BeforeCreate ¶
func (u *GeneralFields) BeforeCreate(tx *gorm.DB) error
func (GeneralFields) ValidDBStruct ¶
func (u GeneralFields) ValidDBStruct()
type Notification ¶
type Notification struct { GeneralFields Level NotifyLevel `gorm:"default:0;not null" json:"level"` Name string `gorm:"type:varchar(256)" json:"name"` Message string `gorm:"type:varchar(256)" json:"message"` Detail string `gorm:"type:string" json:"detail"` }
type NotifyLevel ¶
type NotifyLevel = int32
const ( NotifyInfo NotifyLevel = iota NotifySuccess NotifyWarning NotifyError NotifyFatal )
type Permission ¶
type Permission struct { GeneralFields UID uuid.UUID `gorm:"column:uid;type:uuid;uniqueIndex:perm_link" json:"uid"` GID uuid.UUID `gorm:"column:gid;type:uuid;uniqueIndex:perm_link" json:"gid"` PID uuid.UUID `gorm:"column:pid;type:uuid;uniqueIndex:perm_link;not null" json:"pid"` Perm UserPerm `gorm:"default:0;not null" json:"perm"` User *User `gorm:"foreignKey:UID" json:"-"` UserGroup *UserGroup `gorm:"foreignKey:GID" json:"-"` PermissionList *PermissionList `gorm:"foreignKey:PID" json:"-"` }
func (*Permission) BeforeCreate ¶
func (u *Permission) BeforeCreate(tx *gorm.DB) error
func (*Permission) BeforeUpdate ¶
func (u *Permission) BeforeUpdate(tx *gorm.DB) error
type PermissionList ¶
type PermissionList struct { GeneralFields Name string `gorm:"uniqueIndex;type:varchar(128);not null" json:"name"` Note string `gorm:"type:varchar(256)" json:"note"` }
type RedisConfig ¶
type RedisConfig struct { Address string // redis address Password string // redis password DB int // redis db }
RedisConfig is connection config for redis.
type SessionConfig ¶
type SessionConfig struct { RedisClient *redis.Client // redis client for session Prefix string // session prefix in redis }
SessionConfig is connection config for session.
type SessionData ¶
func LoadSession ¶
func LoadSession(session *sessions.Session) (*SessionData, error)
func LoadSessionString ¶
func LoadSessionString(s string) (*SessionData, error)
func (*SessionData) SaveSession ¶
func (s *SessionData) SaveSession(session *sessions.Session)
type Setting ¶
type Setting struct { GeneralFields Name string `gorm:"uniqueIndex;type:varchar(256);not null" json:"name"` Value string `gorm:"type:string" json:"value"` }
type User ¶
type User struct { GeneralFields Username string `gorm:"uniqueIndex;type:varchar(32);not null" json:"username"` Password string `gorm:"type:char(32);not null" json:"-"` Avatar []byte `gorm:"type:bytes;not null" json:"avatar"` LastLogin int64 `json:"last_login"` LastIP string `gorm:"type:varchar(64)" json:"last_ip"` }
type UserGroup ¶
type UserGroup struct { GeneralFields Name string `gorm:"type:varchar(32);uniqueIndex;not null" json:"name"` Note string `gorm:"type:varchar(256)" json:"note"` }
type UserGroupLink ¶
type UserGroupLink struct { GeneralFields UID uuid.UUID `gorm:"column:uid;type:uuid;uniqueIndex:ugid_link;not null" json:"uid"` GID uuid.UUID `gorm:"column:gid;type:uuid;uniqueIndex:ugid_link;not null" json:"gid"` User *User `gorm:"foreignKey:UID" json:"-"` UserGroup *UserGroup `gorm:"foreignKey:GID" json:"-"` }
type UserPerm ¶
type UserPerm = int32
const ( PermNone UserPerm = 0 // PermNone is default, no permission PermExecute UserPerm = 1 // PermExecute can execute PermWrite UserPerm = 1 << 1 // PermWrite can write database PermRead UserPerm = 1 << 2 // PermRead can read PermAll UserPerm = 1<<3 - 1 // PermAll give all permission PermWriteExecute UserPerm = PermWrite | PermExecute // PermWriteExecute can write and execute )
Click to show internal directories.
Click to hide internal directories.