triton

package module
v0.0.0-...-76eea69 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2016 License: MIT Imports: 13 Imported by: 0

README

Triton

Triton is a cache-enabled static web muxer written in Go. It watches the filesystem for changes, updates its internal cache, and continues to deliver the static site. It defers doing any sort of content management to another solution.

Installation

Install golang.

go get github.com/cjslep/triton

Read some documentation

Write your custom code setting up your familiar http.Server and mapping any assets you have to their mime-type.

Example

Introducing Triton (hosted on a triton-based web server)

Contributing

Triton is licensed under the MIT Expat License. Please feel free to contribute!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecursivelyWatch

func RecursivelyWatch(root string, ignoreIfInPath []string) (*fsnotify.Watcher, error)

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

func (s *Server) ListenAndServe() error

ListenAndServe initializes the Server before using the WebHost to serve http requests.

func (*Server) ListenAndServeTLS

func (s *Server) ListenAndServeTLS(certFile string, keyFile string) error

ListenAndServeTLS initializes the Server before using the WebHost to serve http over TLS.

Jump to

Keyboard shortcuts

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