spa

package
v0.0.0-...-e98364e Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package spa implements a single-page application used on the dmitri.shuralyov.com website.

It is capable of serving page HTML on the frontend and backend, and setting page state on the frontend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewApp

func NewApp(
	codeService interface {
		// ListDirectories lists directories in sorted order.
		ListDirectories(ctx context.Context) ([]*code.Directory, error)

		// GetDirectory looks up a directory by specified import path.
		// If the directory doesn't exist, os.ErrNotExist is returned.
		GetDirectory(ctx context.Context, importPath string) (*code.Directory, error)
	},
	issueService issues.Service,
	changeService change.Service,
	notifService notification.Service,
	userService users.Service,
	redirect func(*url.URL),
) *app

Types

type App

type App interface {
	// ServePage renders the page HTML for reqURL to w,
	// and returns the state it computed.
	//
	// It returns an error of OutOfScopeError type
	// if reqURL is out of scope for the app.
	//
	// The returned state must implement the PageState interface.
	ServePage(ctx context.Context, w io.Writer, reqURL *url.URL) (interface{}, error)

	// SetupPage sets up the frontend page state,
	// using state returned from ServePage.
	SetupPage(ctx context.Context, state interface{})
}

An App is a single-page application.

type OutOfScopeError

type OutOfScopeError struct {
	// URL is the URL of the requested page.
	URL *url.URL
}

OutOfScopeError is an error returned when the requested page is out of scope for the single-page application and therefore cannot be served by it directly.

func IsOutOfScope

func IsOutOfScope(err error) (OutOfScopeError, bool)

IsOutOfScope reports whether err is an OutOfScopeError error.

func (OutOfScopeError) Error

func (o OutOfScopeError) Error() string

type PageState

type PageState interface {
	// RequestURL returns the request URL for the page.
	RequestURL() *url.URL
}

Jump to

Keyboard shortcuts

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