Documentation ¶
Index ¶
- func GenerateRoutes(controller Controller) map[string]func(w http.ResponseWriter, r *http.Request)
- func GenerateRoutesWithPrefix(controller Controller, prefix string) map[string]func(w http.ResponseWriter, r *http.Request)
- func OpenLog(logPath string) (*os.File, error)
- func SafeHTML(text string) template.HTML
- type Application
- func (app Application) CreateLog(name string) (*os.File, error)
- func (app *Application) Initialize(processName string, port int, verbose, graceful bool) error
- func (app Application) Restart(w http.ResponseWriter, req *http.Request)
- func (app Application) ServeWithAutoRouting(controllers []Controller) error
- func (app Application) ServeWithHandler(handler http.Handler) error
- type BaseController
- type Controller
- type TemplateMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateRoutes ¶
func GenerateRoutes(controller Controller) map[string]func(w http.ResponseWriter, r *http.Request)
GenerateRoutes calls GenerateRoutesWithPrefix, using the spinal-cased controller class name as the prefix.
func GenerateRoutesWithPrefix ¶
func GenerateRoutesWithPrefix(controller Controller, prefix string) map[string]func(w http.ResponseWriter, r *http.Request)
GenerateRoutesWithPrefix generates a map of urls to controller methods, suitable for passing off to http.Handle. It will create one route per public method of controller that is not a method of the embedded GlazeController. Each route will be in the form "/[prefix]/[method-name]", where prefix is preserved exactly, and method names are converted to spinal-case.
Types ¶
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
Application encapsulated all the startup logic for a web app using glaze.
func (Application) CreateLog ¶
func (app Application) CreateLog(name string) (*os.File, error)
CreateLog either opens or creates and opens a log file at the given path, and returns an append handle.
func (*Application) Initialize ¶
func (app *Application) Initialize(processName string, port int, verbose, graceful bool) error
Initialize handles all the pre-launch initialization tasks.
func (Application) Restart ¶
func (app Application) Restart(w http.ResponseWriter, req *http.Request)
Restart performs a graceful restart of the process
func (Application) ServeWithAutoRouting ¶
func (app Application) ServeWithAutoRouting(controllers []Controller) error
ServeWithAutoRouting computes standard paths to every Controller that has been added to the Application, and then starts the application server.
func (Application) ServeWithHandler ¶
func (app Application) ServeWithHandler(handler http.Handler) error
ServeWithHandler starts the server with a client-provided handler. If you want to use glaze's auto-routing, use ServeWithAutoRouting instead.
type BaseController ¶
type BaseController struct { BaseTemplate *template.Template Templates TemplateMap // contains filtered or unexported fields }
BaseController structs hold the data necessary to bind view paths. A Controller can have any number of http handler methods added to it, and calling RenderTemplate from within a controller method will execute the given template.
func NewController ¶
func NewController(templatePath, controllerTemplatePath string, funcMap template.FuncMap) (*BaseController, error)
NewController will create a basic controller. templatePath is the full path to the template root controllerTemplatePath is the relative path from the template root to
this controller's template directory
func (*BaseController) RenderHTML ¶
func (controller *BaseController) RenderHTML(writer http.ResponseWriter, templateName string, data interface{}) error
RenderHTML will execute the named template using the given writer
func (*BaseController) RenderJSON ¶
func (controller *BaseController) RenderJSON(writer http.ResponseWriter, data interface{}) error
RenderJSON will output the contents of data as JSON, setting an appropriate Content-Type header
type Controller ¶
type Controller interface { RenderHTML(writer http.ResponseWriter, templateName string, data interface{}) error RenderJSON(writer http.ResponseWriter, data interface{}) error }
Controller is a convenience interface that allows classes with an embedded BaseController to be passed to various glaze methods.
type TemplateMap ¶
TemplateMap maps string names to parsed html templates