Documentation
¶
Overview ¶
Package wa provides a simple web application framework.
Index ¶
- Constants
- Variables
- 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 Register(m *Module)
- func Run(injector *di.Injector) error
- type AppBIZ
- type Bits
- type Config
- type Group
- type GroupDAO
- type ID
- type Item
- type Module
- type ModuleMGR
- type Role
- type RoleDAO
- type Session
- type SessionMGR
- type User
- type UserDAO
Constants ¶
const ( AdminID ID = 1 AdminCode string = "admin" )
Admin.
Variables ¶
var ( ErrInvalidBits = ws.Errorf("wa: invalid bits") ErrInvalidID = ws.Errorf("wa: invalid id") ErrInvalidRole = ws.Errorf("wa: invalid role") )
Errors.
Functions ¶
func GroupPathRange ¶ added in v0.1.2
GroupPathRange returns the group range.
func IsMainGroup ¶ added in v0.1.2
IsMainGroup is a main group filter.
Types ¶
type AppBIZ ¶ added in v0.1.2
type AppBIZ struct {
// contains filtered or unexported fields
}
AppBIZ represents the app BIZ.
func NewAppBIZ ¶ added in v0.1.2
func NewAppBIZ(config *Config, moduleMGR *ModuleMGR, sessionMGR *SessionMGR, userDAO UserDAO) *AppBIZ
NewAppBIZ creates a new app BIZ.
func (*AppBIZ) ChangePassword ¶ added in v0.1.2
ChangePassword changes the user password.
func (*AppBIZ) GetModules ¶ added in v0.1.2
GetModules returns the modules.
type Bits ¶ added in v0.1.2
type Bits uint64
Bits represents a bits value.
func (Bits) MarshalText ¶ added in v0.1.2
MarshalText implements encoding.TextMarshaler.
func (*Bits) UnmarshalText ¶ added in v0.1.2
UnmarshalText implements encoding.TextUnmarshaler.
type Config ¶ added in v0.1.2
type Config struct { Root string Home string Addr string CertFile string KeyFile string SessionName string ReadHeaderTimeout int ReadTimeout int WriteTimeout int IdleTimeout int MaxHeaderBytes int MaxBodyBytes int64 SessionTTL int RoleCacheTTL int UserLockTTL int Modules []string GroupExtra []string UserExtra []string ConfigExtra map[string]any }
Config represents the config infomation.
type GroupDAO ¶ added in v0.1.2
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) error // Get gets the group by id. Get(gid ID) (*Group, error) // Find returns the group by filter. Find(gid ID, filter func(*Group) bool) (*Group, error) // Query queries the groups by keyword. Query(gid ID, keyword string) ([]*Group, error) // CheckGroup checks the group. CheckGroup(sgid, gid ID, strict bool, filter func(*Group) bool) error }
GroupDAO represents the group DAO.
type ID ¶
type ID Bits
ID represents a id.
func (ID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*ID) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Module ¶
type Module struct { Code string Name string Text string Roles []Item[int] `json:",omitempty"` Load func(*di.Injector, *ws.Router) error `json:"-"` Unload func() error `json:"-"` // contains filtered or unexported fields }
Module represents a module.
func (*Module) CheckGroup ¶ added in v0.1.2
CheckGroup checks the group.
func (*Module) CheckRoles ¶ added in v0.1.2
CheckRoles checks the roles.
func (*Module) DeleteRoleCache ¶ added in v0.1.2
DeleteRoleCache deletes the role cache by user id.
type ModuleMGR ¶ added in v0.1.2
type ModuleMGR struct {
// contains filtered or unexported fields
}
ModuleMGR represents the module manager.
func NewModuleMGR ¶ added in v0.1.2
NewModuleMGR creates a new module manager.
func (*ModuleMGR) GetModules ¶ added in v0.1.2
GetModules returns the modules.
type Role ¶
type Role Bits
Role represents a role.
func (Role) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Role) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type RoleDAO ¶ added in v0.1.2
type RoleDAO interface { // Get gets the role by user id. Get(mcode string, uid ID) (Role, error) // Set sets the role by user id. Set(mcode string, uid ID, role Role) error // Delete deletes the user roles. Delete(uid ID) error }
RoleDAO represents the role DAO.
type Session ¶ added in v0.1.2
Session represents a session.
func NewSession ¶ added in v0.1.2
func NewSession(sessionMGR *SessionMGR, w http.ResponseWriter, r *http.Request) (session Session, err error)
NewSession creates a new session.
type SessionMGR ¶ added in v0.1.2
type SessionMGR struct {
// contains filtered or unexported fields
}
SessionMGR represents the session manager.
func NewSessionMGR ¶ added in v0.1.2
func NewSessionMGR(config *Config, userDAO UserDAO) *SessionMGR
NewSessionMGR creates a new session manager.
func (*SessionMGR) Create ¶ added in v0.1.2
func (a *SessionMGR) Create(session Session, w http.ResponseWriter) error
Create creates a new session.
func (*SessionMGR) Delete ¶ added in v0.1.2
func (a *SessionMGR) Delete(session Session)
Delete deletes the session.
type UserDAO ¶ added in v0.1.2
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) 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, keyword string) ([]*User, error) // GetToken gets the user token by id. GetToken(uid ID) ([]byte, error) // UpdateToken updates the user token. UpdateToken(uid ID, token []byte) error // UpdateActiveTime updates the user active time. UpdateActiveTime(uid ID) error }
UserDAO represents the user DAO.