Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RecursivelyWatch ¶
RecursivelyWatch returns a *fsnotify.Watcher that is watching all subdirectories under the given path root. The watcher is invalid if a non-nil error is returned.
Types ¶
type Server ¶
type Server struct { // WebHost is used to handle http requests. Do not call // the WebHost's ListenAndServe nor ListenAndServeTLS functions. Call // the triton Server's variants instead for proper setup to occur. // // If only http.Server had a function for setting its http.Handler in // addition to its exported field, then an interface could be used here // instead. WebHost *http.Server // ErrChan can be provided by the client, or is created after the // server starts listening for requests. The client must listen to // the channel for errors, and a closed channel indicates that the server is // no longer properly updating its content and must be restarted. ErrChan chan error // AssetFileExtensions is a map of file extensions to treat as static // assets when encountered in non-dot-directories. The values of the // map are the MIME type. This can be nil. AssetFileExtensionsToMIME map[string]string // GitDirectories are directories that are not cached in RAM. The // directory is to be read and served as a publicly accessible // repository. This should generally be set as: // []string{".git"} GitDirectories []string // contains filtered or unexported fields }
Server provides static cached web hosting. It searches the current working directory of execution recursively for .tmpl files containing valid html/templates. It also caches assets whose file extension matches the extensions specified by the client using triton. It watches the file system for changes and updates the static site accordingly without restarting.
Template files provide two different, but simple, behaviors depending whether they are located in dot-directories.
If a .tmpl file is within a dot directory, it is parsed and added to the master static Template for use by other templates.
If a .tmpl file is not within a dot directory, it is parsed and added to the master static Template. Additionally, a URL entry to that file location and template filename (without the extension) is created for web clients to visit. The template executed to create that particular page will be the template filename (again, without extension). A quick example:
If the Server was executed at <ROOT>, hosting at SITE.com, and a template file is located at <ROOT>/foo/bar/baz.tmpl, then a web client can go to SITE.com/foo/bar/baz.tmpl and the server will execute the template named "baz" and serve it.
The special case is the file "#.tmpl", which will serve and match the directory it is contained in. So if <ROOT> hosting SITE.com has <ROOT>/#.tmpl, then the client can go to SITE.com (the home page!) and be served template "/".
Static asset files behave as expected with the caveat that they must not be located in any dot-directories.
func (*Server) ListenAndServe ¶
ListenAndServe initializes the Server before using the WebHost to serve http requests.