controller

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2022 License: Apache-2.0 Imports: 27 Imported by: 0

README

goliveview/controller

Todos

  • Use layout and partials at controller level
  • 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/

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 {
	Handler(view View) http.HandlerFunc
}

func Websocket

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

type DOM

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

type DefaultErrorView added in v0.0.4

type DefaultErrorView struct{}

func (DefaultErrorView) Content added in v0.0.4

func (d DefaultErrorView) Content() string

func (DefaultErrorView) Extensions added in v0.0.4

func (d DefaultErrorView) Extensions() []string

func (DefaultErrorView) FuncMap added in v0.0.4

func (d DefaultErrorView) FuncMap() template.FuncMap

func (DefaultErrorView) Layout added in v0.0.4

func (d DefaultErrorView) Layout() string

func (DefaultErrorView) LayoutContentName added in v0.0.4

func (d DefaultErrorView) LayoutContentName() string

func (DefaultErrorView) OnEvent added in v0.0.4

func (d DefaultErrorView) OnEvent(ctx Context) error

func (DefaultErrorView) OnMount added in v0.0.4

func (d DefaultErrorView) OnMount(w http.ResponseWriter, r *http.Request) (Status, M)

func (DefaultErrorView) Partials added in v0.0.4

func (d DefaultErrorView) Partials() []string

type DefaultView added in v0.0.3

type DefaultView struct{}

func (DefaultView) Content added in v0.0.3

func (d DefaultView) Content() string

func (DefaultView) Extensions added in v0.0.3

func (d DefaultView) Extensions() []string

func (DefaultView) FuncMap added in v0.0.3

func (d DefaultView) FuncMap() template.FuncMap

func (DefaultView) Layout added in v0.0.3

func (d DefaultView) Layout() string

func (DefaultView) LayoutContentName added in v0.0.3

func (d DefaultView) LayoutContentName() string

func (DefaultView) OnEvent added in v0.0.3

func (d DefaultView) OnEvent(ctx Context) error

func (DefaultView) OnMount added in v0.0.3

func (d DefaultView) OnMount(w http.ResponseWriter, r *http.Request) (Status, M)

func (DefaultView) Partials added in v0.0.3

func (d DefaultView) Partials() []string

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 Op

type Op string
const (
	ClassList        Op = "classlist"
	Dataset          Op = "dataset"
	SetAttributes    Op = "setAttributes"
	RemoveAttributes Op = "removeAttributes"
	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 DevelopmentMode added in v0.0.4

func DevelopmentMode(enable bool) Option

func DisableTemplateCache

func DisableTemplateCache() Option

func EnableDebugLog

func EnableDebugLog() Option

func EnableHTMLFormatting

func EnableHTMLFormatting() Option

func EnableWatch

func EnableWatch(paths ...string) Option

func WithErrorView added in v0.0.4

func WithErrorView(view View) 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 {
	Put(m M) error
	Get(key string, data interface{}) error
}

type Status added in v0.0.4

type Status struct {
	Code    int    `json:"statusCode"`
	Message string `json:"statusMessage"`
}

type View added in v0.0.3

type View interface {
	// Content represents the path to the html page content
	Content() string
	// Layout represents the path to the base layout to be used.
	/*
			layout.html e.g.
			<!DOCTYPE html>
			<html lang="en">
			<head>
				<title>{{.app_name}}</title>
				{{template "header" .}}
			</head>
			<body>
			{{template "navbar" .}}
			<div>
				{{template "content" .}}
			</div>
			{{template "footer" .}}
			</body>
			</html>
		 The {{template "content" .}} directive is replaced by the page in the path exposed by `Content`
	*/
	Layout() string
	OnMount(w http.ResponseWriter, r *http.Request) (Status, M)
	OnEvent(ctx Context) error
	LayoutContentName() string
	Partials() []string
	Extensions() []string
	FuncMap() template.FuncMap
}

Jump to

Keyboard shortcuts

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