app

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2021 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StaticBlacklist = []string{".go"}

StaticBlacklist is the list of file terminators that specify what files we always want to hide from view when a static file directory is searched. The default will always hide .go files. Add to it if you have other kinds of files in your static directories that you do not want to show. Do this only at startup.

View Source
var StaticDirectoryPaths *maps.StringSliceMap

StaticDirectoryPaths is a map of patterns to directory locations to serve statically. These can be registered at the command line or in the application

Functions

func ListenAndServeTLSWithTimeouts added in v0.9.0

func ListenAndServeTLSWithTimeouts(addr, certFile, keyFile string, handler http.Handler) error

ListenAndServeTLSWithTimeouts starts a secure web server with timeouts. The default http server does not have timeouts by default, which leaves the server open to certain attacks that would start a connection, but then very slowly read or write. Timeout values are taken from global variables defined in config, which you can set at init time.

func ListenAndServeWithTimeouts added in v0.9.0

func ListenAndServeWithTimeouts(addr string, handler http.Handler) error

ListenAndServeWithTimeouts starts a web server with timeouts. The default http server does not have timeouts, which leaves the server open to certain attacks that would start a connection, but then very slowly read or write. Timeout values are taken from global variables defined in config, which you can set at init time. This non-secure version is appropriate if you are serving behind another server, like apache or nginx.

func RegisterStaticFileProcessor added in v0.0.9

func RegisterStaticFileProcessor(ending string, processorFunc StaticFileProcessorFunc)

RegisterStaticFileProcessor registers a processor function for static files that have a particular suffix. Do this at init time.

func RegisterStaticPath added in v0.0.9

func RegisterStaticPath(path string, directory string)

RegisterStaticPath registers the given url path such that it points to the given directory. For example, passing "/test", "/my/test/dir" will statically serve everything out of /my/test/dir whenever a url has /test in front of it. You can only call this during application startup. These directory paths take precedence over other similar paths that you have registered through goradd forms or through the html directory.

func WebsocketMessengerHandler added in v0.14.0

func WebsocketMessengerHandler(w http.ResponseWriter, r *http.Request)

Types

type Application

type Application struct {
	base.Base
}

The application base, to be embedded in your application

func (*Application) AccessLogHandler added in v0.5.1

func (a *Application) AccessLogHandler(next http.Handler) http.Handler

AccessLogHandler simply logs requests.

func (*Application) BufferedOutputHandler added in v0.13.8

func (a *Application) BufferedOutputHandler(next http.Handler) http.Handler

BufferedOutputHandler manages the buffering of http output. It will save all output in a buffer, and make sure any and all Header sets can happen before writing the buffer out to the stream.

func (*Application) HSTSHandler added in v0.9.0

func (a *Application) HSTSHandler(next http.Handler) http.Handler

HSTSHandler sets the browser to HSTS mode using the given timeout. HSTS will force a browser to accept only HTTPS connections for everything coming from your domain, if the initial page was served over HTTPS. Many browsers already do this. What this additionally does is prevent the user from overriding this. Also, if your certificate is bad or expired, it will NOT allow the user the option of using your website anyways. This should be safe to send in development mode if your local server is not using HTTPS, since the header is ignored if a page is served over HTTP.

Once the HSTS policy has been sent to the browser, it will remember it for the amount of time specified, even if the header is not sent again. However, you can override it by sending another header, and clear it by setting the timeout to 0. Set the timeout to -1 to turn it off. You can also completely override this by implementing this function in your app.go file.

func (*Application) Init

func (a *Application) Init(self ApplicationI)

func (*Application) InitializeLoggers

func (a *Application) InitializeLoggers()

InitializeLoggers sets up the various types of logs for various types of builds. By default, the DebugLog and FrameworkDebugLogs will be deactivated when the config.Debug variables are false. Otherwise, configure how you want, and simply remove a log if you don't want it to log anything.

func (*Application) MakeAppServer

func (a *Application) MakeAppServer() http.Handler

MakeAppServer creates the handler chain that will handle http requests. There are a ton of ways to do this, 3rd party libraries to help with this, and middlewares you can use. This is a working example, and not a declaration of any "right" way to do this, since it can be very application specific. Generally you must make sure that PutContextHandler is called before ServeAppHandler in the chain.

func (*Application) PutContext

func (a *Application) PutContext(r *http.Request) *http.Request

func (*Application) PutContextHandler

func (a *Application) PutContextHandler(next http.Handler) http.Handler

PutContextHandler is an http handler that adds the application context to the current context.

func (*Application) ServeApiHandler added in v0.0.9

func (a *Application) ServeApiHandler(next http.Handler) http.Handler

ServeApiHandler serves up an http API. This could be a REST api or something else.

func (*Application) ServeApiRequest added in v0.0.9

func (a *Application) ServeApiRequest(w http.ResponseWriter, r *http.Request) bool

ServeApiRequest serves up an http api call. The prefix has been removed, so we just process the URL as if it were the command itself. This is currently just a stub to allow you to implement your own API. Eventually we hope this could be an auto-generated REST api or GraphQL api.

func (*Application) ServeAppHandler

func (a *Application) ServeAppHandler(buf *bytes.Buffer, next http.Handler) http.Handler

ServeAppHandler processes requests for goradd forms

func (*Application) ServeHTTP

func (a *Application) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Application) ServeRequest

func (a *Application) ServeRequest(w http.ResponseWriter, r *http.Request)

ServeRequest is the place to serve up any files that have not been handled in any other way, either by a previously declared handler, or by the goradd app server. ServeRequest is only called when all the other methods have failed. Override it to handle other files, or to change the messaging when a bad url is attempted.

func (*Application) ServeRequestHandler

func (a *Application) ServeRequestHandler(buf *bytes.Buffer) http.Handler

ServeRequestHandler is the last handler on the default call chain. It calls ServeRequest so the sub-class can handle it.

func (*Application) ServeStaticFile

func (a *Application) ServeStaticFile(w http.ResponseWriter, r *http.Request) bool

ServeStaticFile serves up static html and other files found in registered directories. If the file is not found, it will return false.

func (*Application) ServeStaticFileHandler

func (a *Application) ServeStaticFileHandler(buf *bytes.Buffer, next http.Handler) http.Handler

ServeStaticFileHandler serves up static files by calling ServeStaticFile.

func (*Application) ServeWebsocketMessengerHandler added in v0.14.0

func (a *Application) ServeWebsocketMessengerHandler(next http.Handler) http.Handler

ServeWebsocketMessengerHandler is the authorization handler for watcher requests. It uses the pagestate as the client id, verifying the page state is valid

func (*Application) SessionHandler

func (a *Application) SessionHandler(next http.Handler) http.Handler

SessionHandler initializes the global session handler. This default version uses the injected global session handler. Feel free to replace it with the session handler of your choice.

func (*Application) SetupAssetDirectories

func (a *Application) SetupAssetDirectories()

SetupAssetDirectories registers default directories that will contain web assets. These assets are served up in place in development mode, and served from a specified asset directory in release mode. This means the assets will need to be copied to a central location and moved to the release server. See the build directory for info.

func (*Application) SetupCacheBuster added in v0.13.2

func (a *Application) SetupCacheBuster()

SetupCacheBuster sets up the cache busting strategy. Cache busting permits the browser to cache files, but notifies the server when a file has changed without requiring the browser to check the server. The default cache busting strategy is to add a CRC value to the path on all the files in the assets directory. That will cause the file to change its name whenever the file changes, forcing the browser to reload the file.

func (*Application) SetupDatabaseWatcher added in v0.3.1

func (a *Application) SetupDatabaseWatcher()

SetupDatabaseWatcher injects the global database watcher and the database broadcaster which together detect database changes and then draws controls that are watching for those

func (*Application) SetupErrorPageTemplate

func (a *Application) SetupErrorPageTemplate()

SetupErrorPageTemplate sets the template that controls the output when an error happens during the processing of a page request, including any code that panics. By default, in debug mode, it will popup an error message in the browser with debug information when an error occurs. And in release mode it will popup a simple message that an error occurred and will log the error to the error log. You can implement this function in your local application object to override it and do something different.

func (*Application) SetupMessenger added in v0.3.1

func (a *Application) SetupMessenger()

SetupMessenger injects the global messenger that permits pub/sub communication between the server and client.

You can use this mechanism to setup your own messaging system for application use too.

func (*Application) SetupPagestateCaching added in v0.13.2

func (a *Application) SetupPagestateCaching()

SetupPagestateCaching sets up the service that saves pagestate information that reflects the state of a goradd form to our go code. The default sets up a one server-one process cache that does not scale, which works great for development, testing, and for moderate amounts of traffic. Override and replace the page cache with one that serializes the page state and saves it to a database to make it scalable.

func (*Application) SetupSessionManager

func (a *Application) SetupSessionManager()

type ApplicationI

type ApplicationI interface {
	Init()
	ServeHTTP(w http.ResponseWriter, r *http.Request)
	PutContext(*http.Request) *http.Request
	SetupErrorPageTemplate()
	SetupPagestateCaching()
	InitializeLoggers()
	SetupAssetDirectories()
	SetupSessionManager()
	SetupMessenger()
	SetupDatabaseWatcher()
	SetupCacheBuster()
	SessionHandler(next http.Handler) http.Handler
	HSTSHandler(next http.Handler) http.Handler
	ServeRequest(w http.ResponseWriter, r *http.Request)
	ServeStaticFile(w http.ResponseWriter, r *http.Request) bool
	ServeApiRequest(w http.ResponseWriter, r *http.Request) bool
	AccessLogHandler(next http.Handler) http.Handler
}

The application interface. A minimal set of commands that the main routine will ask the application to do. The main routine offers a way of creating mock applications, and alternate versions of the application from the default

type StaticFileProcessorFunc added in v0.0.9

type StaticFileProcessorFunc func(file string, w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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