Versions in this module Expand all Collapse all v0 v0.1.2 Aug 25, 2022 Changes in this version + var ErrInvalidBits = ws.Errorf("wa: invalid bits") + func GenToken(uid ID, password string) []byte + func GroupPathRange(path []byte, strict bool) (pmin, pmax []byte) + func IsMainGroup(g *Group) bool + func NewLogger(config *Config) (*log.Logger, di.CleanUp, error) + func Run(injector *di.Injector) error + type AppBIZ struct + func NewAppBIZ(config *Config, moduleMGR *ModuleMGR, sessionMGR *SessionMGR, userDAO UserDAO) *AppBIZ + func (a *AppBIZ) ChangePassword(session Session, oldPassword, newPassword string) error + func (a *AppBIZ) GetModules(session Session) []*Module + func (a *AppBIZ) Login(w http.ResponseWriter, code string, password string) (*User, error) + func (a *AppBIZ) Logout(session Session) + type Bits uint64 + func MakeBits(b []byte) (Bits, error) + func ParseBits(s string) (Bits, error) + func (a *Bits) UnmarshalText(text []byte) error + func (a Bits) Bytes() []byte + func (a Bits) MarshalText() ([]byte, error) + func (a Bits) String() string + type Config struct + Addr string + CertFile string + ConfigExtra map[string]any + GroupExtra []string + Home string + IdleTimeout int + KeyFile string + MaxBodyBytes int64 + MaxHeaderBytes int + Modules []string + ReadHeaderTimeout int + ReadTimeout int + RoleCacheTTL int + Root string + SessionName string + SessionTTL int + UserExtra []string + UserLockTTL int + WriteTimeout int + func NewConfig() (*Config, error) + func (a *Config) Bool(key string) bool + func (a *Config) Float(key string) float64 + func (a *Config) Int(key string) int + func (a *Config) String(key string) string + func (a *Config) Value(key string) any type Group + GID ID + PID ID + type GroupDAO interface + CheckGroup func(sgid, gid ID, strict bool, filter func(*Group) bool) error + Create func(group *Group) (*Group, error) + Delete func(gid ID) error + Find func(gid ID, filter func(*Group) bool) (*Group, error) + Get func(gid ID) (*Group, error) + Query func(gid ID, keyword string) ([]*Group, error) + Update func(group *Group) error + type Item struct + Text string + Value T type Module + Roles []Item[int] + func (a *Module) CheckGroup(session Session, gid ID, strict bool, filter func(*Group) bool) error + func (a *Module) CheckRoles(session Session, roles ...Role) (err error) + func (a *Module) DeleteRoleCache(uid ID) + type ModuleMGR struct + func NewModuleMGR(config *Config) (mgr *ModuleMGR, err error) + func (a *ModuleMGR) GetModule(code string) *Module + func (a *ModuleMGR) GetModules() []*Module + type RoleDAO interface + Delete func(uid ID) error + Get func(mcode string, uid ID) (Role, error) + Set func(mcode string, uid ID, role Role) error + type Session struct + GID ID + UID ID + func NewSession(sessionMGR *SessionMGR, w http.ResponseWriter, r *http.Request) (session Session, err error) + type SessionMGR struct + func NewSessionMGR(config *Config, userDAO UserDAO) *SessionMGR + func (a *SessionMGR) Create(session Session, w http.ResponseWriter) error + func (a *SessionMGR) Delete(session Session) type User + GID ID + UID ID + type UserDAO interface + Create func(user *User) (*User, error) + Delete func(uid ID) error + Find func(code string) (*User, error) + Get func(uid ID) (*User, error) + GetToken func(uid ID) ([]byte, error) + Query func(gid ID, keyword string) ([]*User, error) + Update func(user *User) error + UpdateActiveTime func(uid ID) error + UpdateToken func(uid ID, token []byte) error v0.1.1 Sep 24, 2021 v0.0.7 Sep 23, 2021 v0.0.6 Sep 18, 2021 v0.0.5 Sep 17, 2021 v0.0.4 Sep 16, 2021 v0.0.3 Sep 16, 2021 v0.0.2 Sep 6, 2021 Changes in this version type Group + Extra map[string]string type User + Extra map[string]string v0.0.1 Aug 6, 2021 Changes in this version + const AdminCode + const AdminID + const AdminName + var ErrAuthFailed = Error("身份认证失败") + var ErrBadRequest = ws.Status(http.StatusBadRequest) + var ErrForbidden = ws.Status(http.StatusForbidden) + var ErrGroupNotEmpty = Error("用户组非空") + var ErrGroupTooDeep = Error("用户组层次太深") + var ErrInvalidExtra = Error("无效的扩展数据") + var ErrInvalidID = Error("无效的ID") + var ErrInvalidRole = Error("无效的角色") + var ErrModuleNotExist = Error("模块不存在") + var ErrUnauthorized = ws.Status(http.StatusUnauthorized) + var ErrUserLocked = Error("用户已锁定") + var ErrWeakPassword = Error("密码过于简单") + func Backup(w io.Writer) error + func MainGroup(g *Group) bool + func Register(m *Module) + func SetDB(database db.DB) + func Start() + func Tx(ctx *ws.Context) db.Tx + type API struct + func SYS(ctx *ws.Context) *API + func (a *API) CheckGroup(gid ID, filter func(*Group) bool) error + func (a *API) CheckPermission(gid ID, filter func(*Group) bool, roles ...Role) error + func (a *API) CheckRoles(roles ...Role) error + func (a *API) CreateSession(uid ID) error + func (a *API) CreateUser(u *User) error + func (a *API) DeleteSession(uid ID) error + func (a *API) DeleteUser(uid ID) error + func (a *API) FindGroup(code string) (*Group, error) + func (a *API) FindGroupID(code string) (ID, error) + func (a *API) FindUser(code string) (*User, error) + func (a *API) FindUserID(code string) (ID, error) + func (a *API) GetGroup(gid ID) (*Group, error) + func (a *API) GetGroupExtra(gid ID) (map[string]string, error) + func (a *API) GetGroupLevel(rid, gid ID) (int, error) + func (a *API) GetParentGroup(gid ID) (*Group, error) + func (a *API) GetSession() (ID, error) + func (a *API) GetUser(uid ID) (*User, error) + func (a *API) GetUserExtra(uid ID) (map[string]string, error) + func (a *API) GetUserGroup(uid ID) (*Group, error) + func (a *API) HasGroup(gid ID) (bool, error) + func (a *API) HasUser(uid ID) (bool, error) + func (a *API) SearchGroup(gid ID, filter func(*Group) bool) (*Group, error) + func (a *API) SearchUserGroup(uid ID, filter func(*Group) bool) (*Group, error) + func (a *API) SwitchUser(uid ID) + func (a *API) UpdateUser(u *User) error + func (a *API) UpdateUserExtra(uid ID, e map[string]string) error + type Error = util.Error + type Group struct + Code string + ID ID + Name string + Parent ID + Type string + func (a *Group) Check() error + type ID util.Bits + func MakeID(b []byte) (ID, error) + func NewID() ID + func ParseID(s string) (ID, error) + func (a *ID) UnmarshalBinary(data []byte) error + func (a *ID) UnmarshalText(text []byte) error + func (a ID) Bytes() []byte + func (a ID) MarshalBinary() ([]byte, error) + func (a ID) MarshalText() ([]byte, error) + func (a ID) String() string + type Module struct + Code string + Load func(*ws.Router) error + Name string + RoleName func(Role) string + Text string + Unload func() error + func (a *Module) Backup(w io.Writer) error + func (a *Module) Root() string + func (a *Module) SYS(writable bool) func(*ws.Context) error + func (a *Module) SetDB(database db.DB) + func (a *Module) Tx(writable bool) func(*ws.Context) error + type Role util.Bits + const RoleGroupMgr + const RoleRoleMgr + const RoleUserMgr + const RoleUserTokenMgr + func MakeRole(b []byte) (Role, error) + func ParseRole(s string) (Role, error) + func (a *Role) UnmarshalBinary(data []byte) error + func (a *Role) UnmarshalText(text []byte) error + func (a Role) Bytes() []byte + func (a Role) MarshalBinary() ([]byte, error) + func (a Role) MarshalText() ([]byte, error) + func (a Role) String() string + type User struct + Code string + Group ID + ID ID + Name string + Type string + func (a *User) Check() error