controller

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: Apache-2.0 Imports: 27 Imported by: 0

README

goliveview/controller

Todos

[] Use layout and partials at controller level [x] Refresh browser when templates are modified [] go stats [] SessionStore implementation using badger [] LiveList: sorting, pagination, patching [] Add unit tests [] Add benchmarks [] Handle user inactivity: delete session store for inactive connections [] Structured logging [] Redirect to error page [] Compile time validation of data attributes: if target == dataset [] Describe dataset as json files in template/partials/target.dataset [] (stimulus)Handle 4XX, 5XX types error to go to a /4xx,5xx page. [] broadcast to clients over pubsusb. [] Support template.ParseFS [] morphdom diffing support [] csrf token https://coletiv.com/blog/using-websockets-with-cookie-based-authentication/ [] set/unset session id on controller level. session id is available to all pages.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultUserErrorMessage = "internal error"

Functions

func DefaultFuncMap

func DefaultFuncMap() template.FuncMap

func UserError added in v0.0.2

func UserError(err error) string

Types

type Context

type Context interface {
	Event() Event
	RequestContext() context.Context
	Session
}

type Controller

type Controller interface {
	NewView(page string, options ...ViewOption) http.HandlerFunc
}

func Websocket

func Websocket(name *string, options ...Option) Controller

type DOM

type DOM interface {
	SetDataset(selector string, data M)
	ToggleClassList(selector string, classList map[string]bool)
	AddClass(selector, class string)
	RemoveClass(selector, class string)
	Morph(selector, template string, data M)
	Reload()
}

type Event

type Event struct {
	ID       string          `json:"id"`
	Selector string          `json:"selector"`
	Template string          `json:"template"`
	Params   json.RawMessage `json:"params"`
}

func (Event) DecodeParams

func (e Event) DecodeParams(v interface{}) error

func (Event) String

func (e Event) String() string

type EventHandler

type EventHandler func(ctx Context) error

type M

type M map[string]interface{}

type OnMount

type OnMount func(w http.ResponseWriter, r *http.Request) (int, M)

type Op

type Op string
const (
	ClassList   Op = "classlist"
	Dataset     Op = "dataset"
	Morph       Op = "morph"
	Reload      Op = "reload"
	AddClass    Op = "addClass"
	RemoveClass Op = "removeClass"
)

type Operation

type Operation struct {
	Op       Op          `json:"op"`
	Selector string      `json:"selector"`
	Value    interface{} `json:"value"`
}

func (*Operation) Bytes

func (m *Operation) Bytes() []byte

type Option

type Option func(*controlOpt)

func DisableTemplateCache

func DisableTemplateCache() Option

func EnableDebugLog

func EnableDebugLog() Option

func EnableHTMLFormatting

func EnableHTMLFormatting() Option

func EnableWatch

func EnableWatch(paths ...string) Option

func WithRequestContext

func WithRequestContext(f func(r *http.Request) context.Context) Option

func WithSubscribeTopic

func WithSubscribeTopic(f func(r *http.Request) *string) Option

func WithUpgrader

func WithUpgrader(upgrader websocket.Upgrader) Option

type Session

type Session interface {
	DOM() DOM
	Store() SessionStore
	Temporary(keys ...string)
}

type SessionStore

type SessionStore interface {
	Set(m M) error
	Decode(key string, data interface{}) error
}

type ViewHandler

type ViewHandler interface {
	OnMount(w http.ResponseWriter, r *http.Request) (int, M)
	EventHandler(ctx Context) error
}

type ViewOption

type ViewOption func(opt *viewOpt)

func WithErrorPage

func WithErrorPage(errorPage string) ViewOption

func WithEventHandlers

func WithEventHandlers(eventHandlers map[string]EventHandler) ViewOption

func WithExtensions

func WithExtensions(extensions ...string) ViewOption

func WithFuncMap

func WithFuncMap(funcMap template.FuncMap) ViewOption

func WithLayout

func WithLayout(layout string) ViewOption

func WithLayoutContentName

func WithLayoutContentName(layoutContentName string) ViewOption

func WithOnMount

func WithOnMount(onMountFunc OnMount) ViewOption

func WithPartials

func WithPartials(partials ...string) ViewOption

func WithViewHandler

func WithViewHandler(viewHandler ViewHandler) ViewOption

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL