app

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: MIT Imports: 32 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 PutAppContextHandler is called before ServeAppHandler in the chain.

func (*Application) PutAppContextHandler added in v0.15.0

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

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

func (*Application) PutContext

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

func (*Application) PutDbContextHandler added in v0.15.0

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

PutDbContextHandler is an http handler that adds the database context to the current context.

This allows the context to be used by various pieces of the app further down the chain. The default assumes a SQL database. Override it to change it.

func (*Application) ServeAppHandler

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

ServeAppHandler processes requests for goradd forms

func (*Application) ServeAppMuxHandler added in v0.17.0

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

ServeAppMuxHandler serves up the AppMuxHandler, which handles REST calls, and dynamically created files.

To use your own AppMuxer, simply set a new http.AppMuxer. To register additional handlers, override this.

func (*Application) ServeHTTP

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

func (*Application) ServeRequestHandler

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

ServeRequestHandler is the last handler on the default call chain. It returns a simple not found error by default.

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
	ServeStaticFile(w http.ResponseWriter, r *http.Request) bool
	AccessLogHandler(next http.Handler) http.Handler
	PutDbContextHandler(next http.Handler) http.Handler
	ServeAppMuxHandler(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