web

package module
Version: v0.0.0-...-ccb62fa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package web provides a simple web app framework.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthorized    = ws.Status(http.StatusUnauthorized)
	ErrForbidden       = ws.Status(http.StatusForbidden)
	ErrTooManyRequests = ws.Status(http.StatusTooManyRequests)
	ErrInvalidID       = util.Error("无效的ID")
	ErrInvalidRole     = util.Error("无效的角色")
	ErrInvalidSession  = util.Error("无效的会话")
)

Errors.

View Source
var (
	Addr           string
	CertFile       string
	KeyFile        string
	TokenKey       []byte
	SessionMgr     *token.Manager
	SessionAge     = 60 * 60 * time.Second
	ReadTimeout    = 10000 * time.Millisecond
	WriteTimeout   = 10000 * time.Millisecond
	IdleTimeout    = 10000 * time.Millisecond
	MinRequestDur  = 500 * time.Millisecond
	MaxHeaderBytes = 10 * 1024
	MaxBodyBytes   = int64(1 * 1024 * 1024)
	Modules        = []string{"sys"}
)

Config options.

Functions

func GetTx

func GetTx(ctx *ws.Context) db.Tx

GetTx gets the tx from context.

func Register

func Register(m Module)

Register Registers the module.

func Start

func Start()

Start starts the web app.

func UseTLS

func UseTLS() bool

UseTLS checks if use TLS.

Types

type BaseModule

type BaseModule struct {
	DB   db.DB `json:"-"`
	Key  string
	Name string
	Desc string
	// contains filtered or unexported fields
}

BaseModule represents base module info.

func (*BaseModule) Info

func (a *BaseModule) Info() *BaseModule

Info returns the module info.

func (*BaseModule) Init

func (a *BaseModule) Init(rolekey []byte)

Init initializes the base module.

func (*BaseModule) Load

func (a *BaseModule) Load(ctx *ws.Router) error

Load loads the module.

func (*BaseModule) RTx

func (a *BaseModule) RTx(ctx *ws.Context) error

RTx returns a readonly tx handler.

func (*BaseModule) Role

func (a *BaseModule) Role(id ID) (Role, error)

Role gets the user role by id.

func (*BaseModule) RoleChecker

func (a *BaseModule) RoleChecker(roles ...Role) func(*ws.Context) error

RoleChecker returns a role checker.

func (*BaseModule) Unload

func (a *BaseModule) Unload() error

Unload unloads the module.

func (*BaseModule) WTx

func (a *BaseModule) WTx(ctx *ws.Context) error

WTx returns a read-write tx handler.

type ID

type ID uint64

ID represents a id.

func MakeID

func MakeID(b []byte) (ID, error)

MakeID makes id from bytes.

func NewID

func NewID() ID

NewID creates a new id.

func ParseID

func ParseID(s string) (ID, error)

ParseID parses string to id.

func (ID) Bytes

func (a ID) Bytes() []byte

Bytes returns the id as bytes.

func (ID) MarshalText

func (a ID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (ID) String

func (a ID) String() string

String returns the id as string.

func (*ID) UnmarshalText

func (a *ID) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Module

type Module interface {
	// Info returns the module info.
	Info() *BaseModule
	// Load loads the module.
	Load(*ws.Router) error
	// Unload unloads the module.
	Unload() error
	// Role gets the user role by id.
	Role(id ID) (Role, error)
}

Module represents a module.

type Role

type Role uint64

Role represents a role.

func MakeRole

func MakeRole(b []byte) (Role, error)

MakeRole makes role from bytes.

func ParseRole

func ParseRole(s string) (Role, error)

ParseRole parses string to role.

func (Role) Bytes

func (a Role) Bytes() []byte

Bytes returns the role as bytes.

func (Role) MarshalText

func (a Role) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Role) String

func (a Role) String() string

String returns the role as string.

func (*Role) UnmarshalText

func (a *Role) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Session

type Session struct {
	UID ID
	GID ID
}

Session represents a session.

func GetSession

func GetSession(ctx *ws.Context) Session

GetSession gets the session from context.

func MakeSession

func MakeSession(b []byte) (Session, error)

MakeSession makes session from bytes.

func (*Session) Bytes

func (a *Session) Bytes() []byte

Bytes returns the session as bytes.

Directories

Path Synopsis
db
Package db provides a generic interface around key/value databases.
Package db provides a generic interface around key/value databases.
bolt
Package bolt implements the db interface with boltdb.
Package bolt implements the db interface with boltdb.
Package sys mananges the users, groups and roles.
Package sys mananges the users, groups and roles.
Package util provides some helpers.
Package util provides some helpers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL