Documentation
¶
Overview ¶
Package wa provides a simple web application framework.
Index ¶
- Variables
- 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
- 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
- type Config
- type Date
- type DateTime
- 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) UnmarshalText(text []byte) error
- func (a DateTime) Year() int
- type DictValue
- 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
- type GroupDAO
- type ID
- type Item
- type ListValue
- 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
- type Session
- type SessionMGR
- type User
- type UserDAO
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidGroupName = errors.New("无效的组别名称") ErrInvalidUserCode = errors.New("无效的用户代码") ErrInvalidUserName = errors.New("无效的用户名称") ErrInvalidID = ws.Errorf("无效的ID") ErrAuthFailed = ws.Errorf("用户认证失败") ErrUserLocked = ws.Errorf("用户已经锁定") ErrWeakPassword = ws.Errorf("密码过于简单") )
Errors.
Functions ¶
Types ¶
type AppBIZ ¶
type AppBIZ struct {
// contains filtered or unexported fields
}
AppBIZ represents the app BIZ.
func NewAppBIZ ¶
func NewAppBIZ(config *Config, sessionMGR *SessionMGR) *AppBIZ
NewAppBIZ creates a new app BIZ.
func (*AppBIZ) ChangePassword ¶
func (a *AppBIZ) ChangePassword(session *Session, w http.ResponseWriter, oldPassword, newPassword string) error
ChangePassword changes the user password.
func (*AppBIZ) GetModules ¶
GetModules returns the modules.
type ClaimDAO ¶
type ClaimDAO interface { // Set sets the claim. Set(uid ID, key string, value string) error // Get gets the claim. Get(uid ID, key string) (string, error) // GetKeys gets the claim keys. GetKeys() ([]string, error) // Query queries the claims. Query(uid ID) ([]Item[string, string], error) }
ClaimDAO represents the claim DAO.
type Date ¶
type Date uint32
Date represents a date.
func (Date) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Date) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type DateTime ¶
type DateTime uint64
DateTime represents a datetime.
func NewDateTime ¶
NewDateTime creates a new datetime.
func ParseDateTime ¶
ParseDateTime parses string to datetime.
func (DateTime) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*DateTime) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type DictValue ¶
DictValue represents a dict value for config.
type GroupDAO ¶
type GroupDAO interface { // Create creates a new group. Create(group *Group) (*Group, error) // Delete deletes the group. Delete(gid ID) error // Update updates the group. Update(group *Group) (*Group, error) // Get gets the group by id. Get(gid ID) (*Group, error) // Find finds the group by code. Find(code string) (*Group, error) // Query queries the groups by keyword. Query(gid ID, keyword string) ([]*Group, error) // CheckGroup checks the group. CheckGroup(pid, gid ID) error }
GroupDAO represents the group DAO.
type ID ¶
type ID uint64
ID represents a ID.
func (ID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*ID) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Item ¶
type Item[K comparable, V any] struct { Key K Value V }
Item represents a common value/text item model.
type ListValue ¶
type ListValue []any
ListValue represents a list value for config.
type Module ¶
type Module struct { Code string Name string Text string Load func(*ws.Router) error `json:"-"` Unload func() error `json:"-"` }
Module represents a module.
type Session ¶
type Session struct { UID ID // contains filtered or unexported fields }
Session represents a session.
func NewSession ¶
func NewSession(sessionMGR *SessionMGR, r *http.Request) (*Session, error)
NewSession creates a new session.
func (*Session) CheckGroup ¶
CheckGroup checks the group.
type SessionMGR ¶
type SessionMGR struct {
// contains filtered or unexported fields
}
SessionMGR represents the session manager.
func NewSessionMGR ¶
func NewSessionMGR(config *Config, groupDAO GroupDAO, userDAO UserDAO, claimDAO ClaimDAO) *SessionMGR
NewSessionMGR creates a new session manager.
func (*SessionMGR) Create ¶
func (a *SessionMGR) Create(w http.ResponseWriter, uid ID, keep bool) error
Create creates a new session.
func (*SessionMGR) Delete ¶
func (a *SessionMGR) Delete(w http.ResponseWriter, uid ID) error
Delete deletes the session.
type UserDAO ¶
type UserDAO interface { // Create creates a new user. Create(user *User) (*User, error) // Delete deletes the user. Delete(uid ID) error // Update updates the user. Update(user *User) (*User, error) // Get gets the user by id. Get(uid ID) (*User, error) // Find finds the user by code. Find(code string) (*User, error) // Query queries the users by keyword. Query(gid ID, key string, value string, keyword string) ([]*User, error) // SetAuthToken sets the user auth token. SetAuthToken(uid ID, token []byte) error // GetAuthToken gets the user auth token. GetAuthToken(uid ID) ([]byte, error) // SetSessionToken sets the user session token. SetSessionToken(uid ID, token []byte) error // GetSessionToken gets the user session token. GetSessionToken(uid ID) ([]byte, error) }
UserDAO represents the user DAO.