Versions in this module Expand all Collapse all v0 v0.1.1 Nov 10, 2022 Changes in this version + var ErrAuthFailed = ws.Errorf("用户认证失败") + var ErrInvalidGroupName = errors.New("无效的组别名称") + var ErrInvalidID = ws.Errorf("无效的ID") + var ErrInvalidUserCode = errors.New("无效的用户代码") + var ErrInvalidUserName = errors.New("无效的用户名称") + var ErrUserLocked = ws.Errorf("用户已经锁定") + var ErrWeakPassword = ws.Errorf("密码过于简单") + func GenKey() ([]byte, error) + func GenToken(key []byte, password string) []byte + func NewLogger(config *Config) (*log.Logger, di.CleanUp, error) + func Register(m *Module) + func Run(injector *di.Injector) (err error) + type AppBIZ struct + func NewAppBIZ(config *Config, sessionMGR *SessionMGR) *AppBIZ + func (a *AppBIZ) ChangePassword(session *Session, w http.ResponseWriter, oldPassword, newPassword string) error + func (a *AppBIZ) GetClaim(session *Session, key string) (string, error) + func (a *AppBIZ) GetClaims(session *Session) ([]Item[string, string], error) + func (a *AppBIZ) GetModules(session *Session) []*Module + func (a *AppBIZ) Login(w http.ResponseWriter, code string, password string, keep bool) (*User, error) + func (a *AppBIZ) Logout(session *Session, w http.ResponseWriter) error + type ClaimDAO interface + Get func(uid ID, key string) (string, error) + GetKeys func() ([]string, error) + Query func(uid ID) ([]Item[string, string], error) + Set func(uid ID, key string, value string) error + type Config struct + Home string + Root string + func NewConfig() (*Config, error) + type Date uint32 + func NewDate(year, month, day int) Date + func ParseDate(s string) (Date, error) + func Today() Date + func (a *Date) UnmarshalText(text []byte) error + func (a Date) Day() int + func (a Date) MarshalText() ([]byte, error) + func (a Date) Month() int + func (a Date) String() string + func (a Date) Time() time.Time + func (a Date) Year() int + type DateTime uint64 + func NewDateTime(year, month, day, hour, minute, second int) DateTime + func Now() DateTime + func ParseDateTime(s string) (DateTime, error) + func (a *DateTime) UnmarshalText(text []byte) error + func (a DateTime) Day() int + func (a DateTime) Hour() int + func (a DateTime) MarshalText() ([]byte, error) + func (a DateTime) Minute() int + func (a DateTime) Month() int + func (a DateTime) Second() int + func (a DateTime) String() string + func (a DateTime) Time() time.Time + func (a DateTime) Year() int + type DictValue map[string]any + func (a DictValue) Bool(k string, xs ...bool) bool + func (a DictValue) Dict(k string, xs ...DictValue) DictValue + func (a DictValue) Float(k string, xs ...float64) float64 + func (a DictValue) Int(k string, xs ...int) int + func (a DictValue) List(k string, xs ...ListValue) ListValue + func (a DictValue) String(k string, xs ...string) string + type Group struct + Code string + GID ID + Name string + PID ID + func (a *Group) Check() error + type GroupDAO interface + CheckGroup func(pid, gid ID) error + Create func(group *Group) (*Group, error) + Delete func(gid ID) error + Find func(code string) (*Group, error) + Get func(gid ID) (*Group, error) + Query func(gid ID, keyword string) ([]*Group, error) + Update func(group *Group) (*Group, error) + type ID uint64 + func MakeID(b []byte) (ID, error) + func ParseID(s string) (ID, error) + func (a *ID) UnmarshalText(text []byte) error + func (a ID) Bytes() []byte + func (a ID) MarshalText() ([]byte, error) + func (a ID) String() string + type Item struct + Key K + Value V + type ListValue []any + func (a ListValue) Bool(i int, xs ...bool) bool + func (a ListValue) Dict(i int, xs ...DictValue) DictValue + func (a ListValue) Float(i int, xs ...float64) float64 + func (a ListValue) Int(i int, xs ...int) int + func (a ListValue) List(i int, xs ...ListValue) ListValue + func (a ListValue) String(i int, xs ...string) string + type Module struct + Code string + Load func(*ws.Router) error + Name string + Text string + Unload func() error + type Session struct + UID ID + func NewSession(sessionMGR *SessionMGR, r *http.Request) (*Session, error) + func (a *Session) CheckGroup(gid ID, strict bool) error + func (a *Session) GetClaim(key string) (string, error) + func (a *Session) GetClaims() ([]Item[string, string], error) + func (a *Session) GetUser() (*User, error) + func (a *Session) HasClaim(key string) (bool, error) + type SessionMGR struct + func NewSessionMGR(config *Config, groupDAO GroupDAO, userDAO UserDAO, claimDAO ClaimDAO) *SessionMGR + func (a *SessionMGR) Create(w http.ResponseWriter, uid ID, keep bool) error + func (a *SessionMGR) Delete(w http.ResponseWriter, uid ID) error + type User struct + Code string + GID ID + Locked bool + Name string + UID ID + func (a *User) Check() error + 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) + GetAuthToken func(uid ID) ([]byte, error) + GetSessionToken func(uid ID) ([]byte, error) + Query func(gid ID, key string, value string, keyword string) ([]*User, error) + SetAuthToken func(uid ID, token []byte) error + SetSessionToken func(uid ID, token []byte) error + Update func(user *User) (*User, error)