app

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package app glues your routes together to generate files concurrently or host them in a server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLog

func DefaultLog() logrus.FieldLogger

DefaultLog returns the default log used for the App

func SettingsFromFile

func SettingsFromFile(path string, settings interface{}, log logrus.FieldLogger)

SettingsFromFile loads settings from the given file path into the given Settings

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App is a wrapper around the router, to provide the functionality of the cli.App interface. Provides defaults to give the app structure and connects things together to generate route responses concurrently.

See cli.App interface for core functions.

func NewApp

func NewApp(routeSetter Setter, settings *Settings, log logrus.FieldLogger) *App

NewApp returns a new instance of App

func (*App) FileServerPort

func (app *App) FileServerPort() int

FileServerPort returns the port of the file server

func (*App) Generate

func (app *App) Generate() error

Generate generates the static web pages concurrently.

For speed and concurrency reasons (like file/map read/writing), this is done in two stages: First, the Tracker.IndependentURLs routes are generated. After, the Tracker.DependentURLs.

Use Tracker.AddDependentURL to generate the route's file during the second stage.

func (*App) GeneratedPath

func (app *App) GeneratedPath() string

GeneratedPath returns the path of the generates files of the static web page

func (*App) Host

func (app *App) Host() error

Host runs a web application server that computes the route responses in real time

func (*App) RunFileServer

func (app *App) RunFileServer() error

RunFileServer runs the server to host the generated files of the static web page

func (*App) ServerPort

func (app *App) ServerPort() int

ServerPort returns the port of the web application server

type GeneratorSettings

type GeneratorSettings struct {
	Concurrency int `json:"concurrency,omitempty"`
}

GeneratorSettings represents the settings for Generating files

type Setter

type Setter interface {
	// SetRoutes is where you set the routes
	SetRoutes(r router.Router, tracker *Tracker) error
	// AssetsURL is the URL path prefix of all your assets, so the server can redirect this prefix to your assets
	AssetsURL() string
	// GeneratedAssetsPath is the local file path of the generated assets
	GeneratedAssetsPath() string
}

Setter is an interface for App to talk to your code and set routes.

type Settings

type Settings struct {
	GeneratedPath     string             `json:"generated_path,omitempty"`
	ServerPort        int                `json:"server_port,omitempty"`
	FileServerPort    int                `json:"file_server_port,omitempty"`
	GeneratorSettings *GeneratorSettings `json:"generator_settings,omitempty"`

	Content interface{} `json:"content,omitempty"`
}

Settings represents the settings of App

func DefaultSettings

func DefaultSettings() *Settings

DefaultSettings returns the default settings of the App

type Tracker

type Tracker struct {
	// contains filtered or unexported fields
}

Tracker tracks all the routes/URLs of the static site, so that App knows to generate them

func NewTracker

func NewTracker(urls func() []string) *Tracker

NewTracker returns a new instance of Tracker

func (*Tracker) AddDependentURL

func (tracker *Tracker) AddDependentURL(url string)

AddDependentURL adds a dependent url, so the url route runs in the second batch.

When generating the static website files (App.Generate), App works in 2 batches. First, the IndependentURLs() routes are run, then the DependentURLs() are run.

func (*Tracker) DependentURLs

func (tracker *Tracker) DependentURLs() []string

DependentURLs returns a slice of urls provided by AddDependentURL

func (*Tracker) IndependentURLs

func (tracker *Tracker) IndependentURLs() ([]string, error)

IndependentURLs = AllURLs - DependentURLs (see AddDependentURL)

Jump to

Keyboard shortcuts

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