Documentation ¶
Index ¶
- Constants
- Variables
- func GetApplicationPath() string
- func GetLogDateFormat() string
- func GetLogFilename() string
- func GetLogLevel() int
- func LogError(message string) error
- func LogErrorf(message string, args ...interface{}) error
- func LogMessage(message string) error
- func LogMessagef(message string, args ...interface{}) error
- func LogTrace(message string) error
- func LogTracef(message string, args ...interface{}) error
- func LogWarning(message string) error
- func LogWarningf(message string, args ...interface{}) error
- func MakeTemplateList(controllerName string, templates []string) []string
- func RandomString(length int) string
- func RawHTML(data string) template.HTML
- func SetLogDateFormat(format string)
- func SetLogFilename(filename string)
- func SetLogLevel(level int)
- func TemplateExists(controllerName string, template string) bool
- type ActionMap
- func NewActionMap(httpVerb string, actionName string, actionMethod ActionMethod) *ActionMap
- func NewDeleteActionMap(actionName string, actionMethod ActionMethod) *ActionMap
- func NewGetActionMap(actionName string, actionMethod ActionMethod) *ActionMap
- func NewPostActionMap(actionName string, actionMethod ActionMethod) *ActionMap
- func NewPutActionMap(actionName string, actionMethod ActionMethod) *ActionMap
- type ActionMethod
- type ActionResult
- type Application
- func (app *Application) RedirectSecure(w http.ResponseWriter, req *http.Request)
- func (app *Application) RedirectSecureJS(w http.ResponseWriter, req *http.Request)
- func (app *Application) Run() error
- func (app *Application) RunForcedSecure(certFile string, keyFile string) error
- func (app *Application) RunForcedSecureJS(certFile string, keyFile string) error
- func (app *Application) RunSecure(certFile string, keyFile string) error
- func (app *Application) Stop() error
- type BundleManager
- func (bundleManager *BundleManager) BuildAllBundles() error
- func (bundleManager *BundleManager) BuildBundle(bundleName string) error
- func (bundleManager *BundleManager) CreateBundle(bundleName string, mimeType string, bundledFiles []string) error
- func (bundleManager *BundleManager) RebuildAllBundles() error
- func (bundleManager *BundleManager) RebuildBundle(bundleName string) error
- func (bundleManager *BundleManager) RemoveBundle(bundleName string) error
- type BundleMap
- type ConfigurationManager
- type Controller
- func (controller *Controller) DefaultErrorPage(err error) *ActionResult
- func (controller *Controller) DefaultNotFoundPage() *ActionResult
- func (controller *Controller) DeleteCookie(cookieName string)
- func (controller *Controller) Execute() (*ActionResult, error)
- func (controller *Controller) GetCookie(name string) *http.Cookie
- func (controller *Controller) JSON(payload interface{}) *ActionResult
- func (controller *Controller) RedirectJS(url string) error
- func (controller *Controller) RegisterAction(verb string, name string, method ActionMethod)
- func (controller *Controller) Result(data []byte) *ActionResult
- func (controller *Controller) SetCookie(cookie *http.Cookie)
- func (controller *Controller) SimpleView(templates ...string) *ActionResult
- func (controller *Controller) ToController() *Controller
- func (controller *Controller) View(templates []string, model interface{}) *ActionResult
- func (controller *Controller) WriteResponse(result *ActionResult) error
- type ControllerCallback
- type ControllerCreator
- type EmailConnector
- type EmailMessage
- type ErrorResultCallback
- type IController
- type NotFoundResultCallback
- type RouteManager
- func (manager *RouteManager) GetController(response http.ResponseWriter, request *http.Request) (IController, *Controller)
- func (manager *RouteManager) HandleFile(response http.ResponseWriter, request *http.Request) bool
- func (manager *RouteManager) HandleRequest(response http.ResponseWriter, request *http.Request)
- func (manager *RouteManager) ParseControllerName(path string) string
- func (manager *RouteManager) RegisterController(name string, creator ControllerCreator)
- func (manager *RouteManager) ServeFile(response http.ResponseWriter, request *http.Request) bool
- func (manager *RouteManager) SetControllerSessions(controller *Controller) error
- func (manager *RouteManager) ToQueryStringMap(queryString string) map[string]string
- func (manager *RouteManager) ValidPath(path string) bool
- type RouteMap
- type Session
- type SessionManager
- func (manager *SessionManager) CleanSessions()
- func (manager *SessionManager) Contains(id string) bool
- func (manager *SessionManager) CreateSession(id string) *Session
- func (manager *SessionManager) DropSession(id string)
- func (manager *SessionManager) GetSession(id string) *Session
- func (manager *SessionManager) SetSession(session *Session)
Constants ¶
const ( // LogLevelNone is wreckless... LogLevelNone = 0 // LogLevelError is the default, only critical errors are reported LogLevelError = 1 // LogLevelWarning is a bit more verbose and will report errors that were handled internally LogLevelWarning = 2 // LogLevelInfo is more verbose and will report generic workflow status as it goes LogLevelInfo = 3 // LogLevelTrace is the most verbose and should only be used when debugging or troubleshooting LogLevelTrace = 4 )
Defines our Loging Levels, these are used to filter what is written to file allowing the calling application to easily switch the verbosity of logging at runtime
Variables ¶
var LogDateFormat = "1/2/2006 15:04:05 -07:00"
LogDateFormat is the golang time formatting string used when rendering the date and time portion of logging methods
var LogFilename = ""
LogFilename is used internally to hold the name of the file that holds our application logs
var LogLevel = LogLevelError
LogLevel is the internal value representing what levels of log messages are written to our log file. Where 0 = Off 1 = Errors Only, 2 = Warnings (Such as 404), 3 = Verbose (It'll say a lot), 4 = Debug Tracing (Won't shut up)
Functions ¶
func GetApplicationPath ¶
func GetApplicationPath() string
GetApplicationPath should return the full path to the executable. This is the root of the site and where the assembly file is
func GetLogDateFormat ¶
func GetLogDateFormat() string
GetLogDateFormat returns the current Golang time formatting string being used in logging
func GetLogFilename ¶
func GetLogFilename() string
GetLogFilename returns the current, or default log file that we will write to
func GetLogLevel ¶
func GetLogLevel() int
GetLogLevel returns the level of log messages that are written to our log file
func LogErrorf ¶
LogErrorf writes a formatted error message to the log file if our internal log level is >= 1
func LogMessage ¶
LogMessage writes an information message to the log file if our internal log level is >= 3
func LogMessagef ¶
LogMessagef writes a formatted information message to the log file if our internal log level is >= 3
func LogTrace ¶
LogTrace is used to log debug tracing messages (such as the most verbose helping the reader to track the flow of execution through the program)
func LogTracef ¶
LogTracef is used to log formatted debug tracing messages such as the most verbose heling the reader to track the flow of execution through the program
func LogWarning ¶
LogWarning writes a warning message to the log file if our internal log level is >= 2
func LogWarningf ¶
LogWarningf writes a formatted warning message to the log file if our internal log level is >= 2
func MakeTemplateList ¶
MakeTemplateList provides some common view template path fallbacks. Will test if each of the template file names exist as is, if not will try the following:
./views/template ./views/controllerName/template ./views/shared/template ./views/shared/controllerName/template
func RandomString ¶
RandomString returns a randomly generated string of the given length.
func RawHTML ¶
RawHTML was a patch method added late in v0.1.0 to provide the ability to pass through raw html content to be rendered by browser. Use this with caution, any code such as javascript should be stripped from the data before this method is called.
func SetLogDateFormat ¶
func SetLogDateFormat(format string)
SetLogDateFormat sets the current Golang time formatting string being used in logging
func SetLogFilename ¶
func SetLogFilename(filename string)
SetLogFilename will set the filename that log messages will be written to
func SetLogLevel ¶
func SetLogLevel(level int)
SetLogLevel sets the internal log level of messages that are written to our log file Where 0 = Off 1 = Errors Only, 2 = Warnings (Such as 404), 3 = Verbose (It'll say a lot)
func TemplateExists ¶
TemplateExists checks the standard folder paths based on the provided controllerName to see if the template file can be found. (See MakeTemplateList for path structure)
Types ¶
type ActionMap ¶
type ActionMap struct { // Verb is the HTTP Verb to bind this mapping to, blank to respond to all Verb string // Name is the site.com/controller/<ACTION> name that this map handles Name string // Method is the actual action method to execute on the controller Method ActionMethod }
ActionMap is used to define the HTTP Verb, Controller's Action Name and the corresponding action method
func NewActionMap ¶
func NewActionMap(httpVerb string, actionName string, actionMethod ActionMethod) *ActionMap
NewActionMap returns a new ActionMap struct populated with the given parameters
func NewDeleteActionMap ¶
func NewDeleteActionMap(actionName string, actionMethod ActionMethod) *ActionMap
NewDeleteActionMap returns a new ActionMap struct populated with the given parameters and sets the HTTP Verb to delete
func NewGetActionMap ¶
func NewGetActionMap(actionName string, actionMethod ActionMethod) *ActionMap
NewGetActionMap returns a new ActionMap struct populated with the given parameters and sets the HTTP Verb to get
func NewPostActionMap ¶
func NewPostActionMap(actionName string, actionMethod ActionMethod) *ActionMap
NewPostActionMap returns a new ActionMap struct populated with the given parameters and sets the HTTP Verb to post
func NewPutActionMap ¶
func NewPutActionMap(actionName string, actionMethod ActionMethod) *ActionMap
NewPutActionMap returns a new ActionMap struct populated with the given parameters and sets the HTTP Verb to put
type ActionMethod ¶
type ActionMethod func([]string) *ActionResult
ActionMethod defines the method signature for controller action methods
type ActionResult ¶
type ActionResult struct { // StatusCode is the HTTP status code to write with this response. default is 200 ok StatusCode int // Headers is a key value pairs map of the names and values of headers to write with this response Headers map[string]string // Cookies is a collection of http cookie values to write with this response Cookies []*http.Cookie // Data is the raw byte array representing the payload to deliver Data []byte }
ActionResult is a base level struct that implements the Execute method and provides the Data []byte member
func NewActionResult ¶
func NewActionResult(data []byte) *ActionResult
NewActionResult returns a new action result populated with the provided data
func NewJSONResult ¶
func NewJSONResult(payload interface{}) (*ActionResult, error)
NewJSONResult returns a new JSONResult with the payload json encoded to Data
func NewViewResult ¶
func NewViewResult(templates []string, model interface{}) (*ActionResult, error)
NewViewResult returns a new ViewResult struct with the Data member set to the compiled templates requested
func (*ActionResult) AddCookie ¶
func (result *ActionResult) AddCookie(cookie *http.Cookie) error
AddCookie adds the provided cookie to the result
func (*ActionResult) AddHeader ¶
func (result *ActionResult) AddHeader(key string, val string) error
AddHeader adds an http header key value pair combination to the result
func (ActionResult) Execute ¶
func (result ActionResult) Execute(response http.ResponseWriter) error
Execute writes the header, cookies and data of this action result to the client.
type Application ¶
type Application struct { // RouteManager is our Route Manager system RouteManager *RouteManager Config *ConfigurationManager // HTTPServer is the http.Server object being used to host http transport HTTPServer *http.Server // HTTPSServer is the http.Server object being used to host https transport HTTPSServer *http.Server }
Application is our global scope object (E.g. application wide configuration and manager systems)
func NewApplication ¶
func NewApplication() *Application
NewApplication returns a new default MVC Application object
func NewApplicationFromConfig ¶
func NewApplicationFromConfig(config *ConfigurationManager) *Application
NewApplicationFromConfig returns a new MVC Application object with the provided configuration manager object
func NewApplicationFromConfigFile ¶
func NewApplicationFromConfigFile(filename string) (*Application, error)
NewApplicationFromConfigFile returns a new MVC Application object constructed from the provided json config file
func (*Application) RedirectSecure ¶
func (app *Application) RedirectSecure(w http.ResponseWriter, req *http.Request)
RedirectSecure is used to submit an http redirect from http to https when forcing secure
func (*Application) RedirectSecureJS ¶
func (app *Application) RedirectSecureJS(w http.ResponseWriter, req *http.Request)
RedirectSecureJS is used to submit a javascript redirect from http to https when forcing secure
func (*Application) Run ¶
func (app *Application) Run() error
Run is used to execute this MVC Application (direct http socket server)
func (*Application) RunForcedSecure ¶
func (app *Application) RunForcedSecure(certFile string, keyFile string) error
RunForcedSecure is used to execute this MVC Application in both HTTP and HTTPS/TLS modes, the HTTP mode will force redirection to HTTPS only. (direct http and https socket servers)
func (*Application) RunForcedSecureJS ¶
func (app *Application) RunForcedSecureJS(certFile string, keyFile string) error
RunForcedSecureJS is used to run a web application in forced TLS secure mode by returning a simple page with javascript that redirects the browser to https://DomainName/path
func (*Application) RunSecure ¶
func (app *Application) RunSecure(certFile string, keyFile string) error
RunSecure is used to execute this MVC Application over HTTPS/TLS (direct https socket server)
func (*Application) Stop ¶
func (app *Application) Stop() error
Stop is used to stop hosting this MVC Application. You can call one of the Run methods to restart
type BundleManager ¶
type BundleManager struct { // Bundles are a collection of filenames that are compiled into a single deliverable Bundles map[string]*BundleMap Minifier *minify.M }
BundleManager is an object that we register our content bundles with and is used to compile said content bundles.
func NewBundleManager ¶
func NewBundleManager() *BundleManager
NewBundleManager returns a new instance of the bundle manager object
func (*BundleManager) BuildAllBundles ¶
func (bundleManager *BundleManager) BuildAllBundles() error
BuildAllBundles is used to build all of the currently registered content bundles
func (*BundleManager) BuildBundle ¶
func (bundleManager *BundleManager) BuildBundle(bundleName string) error
BuildBundle is used to compile the registered bundle defined by bundleName. This method will delete the existing bundle file if it exists and replacing with a newly built copy
func (*BundleManager) CreateBundle ¶
func (bundleManager *BundleManager) CreateBundle(bundleName string, mimeType string, bundledFiles []string) error
CreateBundle is used to register a bundle by name, mime type and slice of filenames Once registered, bundles can be compiled using the BuildBundle method referencing the provided bundleName
func (*BundleManager) RebuildAllBundles ¶
func (bundleManager *BundleManager) RebuildAllBundles() error
RebuildAllBundles is used to loop through all of the registered content bundles and compare file modification dates to the build time of the bundle. If files have been modified since this bundle was built, it will be built a new
func (*BundleManager) RebuildBundle ¶
func (bundleManager *BundleManager) RebuildBundle(bundleName string) error
RebuildBundle is used to compare the last modified times of the files in a content bundle to the creation time of this content bundle, if files have been modified since this bundle was built it will be built a new. Returns nil if no need to build
func (*BundleManager) RemoveBundle ¶
func (bundleManager *BundleManager) RemoveBundle(bundleName string) error
RemoveBundle is used to remove a bundle from the manager by name.
type BundleMap ¶
type BundleMap struct { // Files is a slice of the full path and file name of the files to include // in this content bundle Files []string // MimeType is the MIME type of the files in this bundle and is used to execute // the appropriate minification methods in the bundle manager MimeType string // BuildDate is the time and date when this bundle was created, the bundle // manager uses this to determine if a rebuild is warranted BuildDate time.Time }
BundleMap represents the slice of filenames, the mime type and last build date & time of a "Content Bundle"
func NewBundleMap ¶
NewBundleMap returns a new BundleMap from the provided mime type and filename slice
type ConfigurationManager ¶
type ConfigurationManager struct { // AppName is the display name for this application wherever applicable AppName string // AppVersion is the display version of this application wherever applicable AppVersion string // DomainName is the FQDN for this application DomainName string // BindAddress is the TCP/IP address to bind the listener to (normally leave blank for all) BindAddress string // HTTPPort is the TCP/IP Port number to listen on for plain http HTTPPort int // HTTPSPort is the TCP/IP Port number to listen on for TLS http HTTPSPort int // LogFilename is the full path and filename to write logging messages to (based on log level) LogFilename string // LogLevel represents the level of messages that are written to the log file. Allows for caller // to switch at runtime based on conditions or needs LogLevel int // TLSCertFile is the full path and filename of the TLS Certificate file to use for HTTPS TLSCertFile string // TLSKeyFile is the full path and filename of the TLS Key file to use for HTTPS TLSKeyFile string // AllowGoogleAuthFiles will allow the app to serve google site authentication files over plain // http even if the app is forcing all traffic to https (normally irrelevent) AllowGoogleAuthFiles bool // HTTPSessionIDKey is the name of the cookie that will store our user's session id if using // the built in http session manager system HTTPSessionIDKey string // HTTPSessionTimeout is the number of minutes that a users http session data will be stored in // memory between requests HTTPSessionTimeout int64 // TaskDuration is the number of seconds to idle between evaluating internal tasks (such as cleaning // user http sessions in memory) TaskDuration int64 // DefaultController is used to define where requests to the root of this DomainName are routed // Should be Home in most cases DefaultController string // DefaultAction is used to define the default action method to be executed if unable to map the // the requested action. Should be Index in most cases DefaultAction string }
ConfigurationManager is a simple json serializer wrapper that allows an mvcapp to easily save and load human friendly json files for application configuration values
func NewConfigurationManager ¶
func NewConfigurationManager() *ConfigurationManager
NewConfigurationManager returns an empty new Configuration Manager struct
func NewConfigurationManagerFromFile ¶
func NewConfigurationManagerFromFile(filename string) (*ConfigurationManager, error)
NewConfigurationManagerFromFile returns a new Configuration Manager struct constructed from the values in the provided json file
func (*ConfigurationManager) SaveFile ¶
func (config *ConfigurationManager) SaveFile(filename string) error
SaveFile will save the current values to a human readable json configuration file
type Controller ¶
type Controller struct { // IController is the interface that the base controller implements IController // Request is the http.Request object that this controller is responding to Request *http.Request // Response is the response writer stream to write data to the client Response http.ResponseWriter // BundleManager is a pointer to the content bundle manager used by the route manager BundleManager *BundleManager // Session is the User browser session data collection for the user who made this request Session *Session // Cookies are populated from the collection submitted from the client. Server can alter // or add cookies to this collection to have them delivered back to the client. (Call the // controllers DeleteCookie method to signal the client to forget a cookie) Cookies []*http.Cookie // ContinuePipeline is used from methods that mean to prevent the execution of a controller // action method. E.g. if a controller signals to RedirectJS in the BeforeExecute callback, // this will be set to false and will prevent the action method from assembling and executing // the action result. ContinuePipeline bool // ControllerName is used to help the template path mapping of the View method of this controller. // Should be set in the controller creator method and should represent the folder name where the // views for this controller can be found ControllerName string // RequestedPath is a quick reference member that contains the url path (after the domain) that // was requested. RequestedPath string // QueryString is a quick reference member that contains the key value pair query string parameters // that were submitted with this request QueryString map[string]string // Fragment represents the #Value portion of the requested URL (Note some sources indicate that URL // fragments are or should be depreciated. Use URL fragments and this member at your discretion) Fragment string // DefaultAction is the name of the default action method name (in the route map) to try and execute // when making a request directly to the controller. (E.g. site.com/controller) (This should be your // Index, Home or Default page name) DefaultAction string // ActionRoutes stores the routes which have been registered for this controller. This collection is // used in the Execute method to find the appropriate action method function to call ActionRoutes []*ActionMap // ViewData is the preferred means of pasing data models to your views as of version 0.2.0. ViewData map[string]interface{} // BeforeExecute is a callback method that a controller can set to provide a global method called before // the action method is executed. (Controller global prep function) BeforeExecute ControllerCallback // AfterExecute is a callback method that a controller can set to provide a global method called after // the action method is executed. (Controller global clean up function) AfterExecute ControllerCallback // ErrorResult is a callback method that a controller can set to respond to error conditions with a custom // error page ErrorResult ErrorResultCallback // NotFoundResult is a callback method that a controller can set to respond to a content not found condition // with a custom 404 page NotFoundResult NotFoundResultCallback }
Controller contains the basic members shared by custom controllers, also defines the required RegisterAction and Execute methods (below)
func NewBaseController ¶
func NewBaseController(request *http.Request) *Controller
NewBaseController returns a reference to a new Base Controller
func (*Controller) DefaultErrorPage ¶
func (controller *Controller) DefaultErrorPage(err error) *ActionResult
DefaultErrorPage will attempt to render the built in error page
func (*Controller) DefaultNotFoundPage ¶
func (controller *Controller) DefaultNotFoundPage() *ActionResult
DefaultNotFoundPage will attempt to render the built in 404 page
func (*Controller) DeleteCookie ¶
func (controller *Controller) DeleteCookie(cookieName string)
DeleteCookie will set the cookie (identified by provided ccokieName) to expire in the past, thus making the browser remove it and stop sending it back.
func (*Controller) Execute ¶
func (controller *Controller) Execute() (*ActionResult, error)
Execute is called by the route manager instructing this controller to respond
func (*Controller) GetCookie ¶
func (controller *Controller) GetCookie(name string) *http.Cookie
GetCookie returns the requested cookie from this controllers collection
func (*Controller) JSON ¶
func (controller *Controller) JSON(payload interface{}) *ActionResult
JSON returns a new JSONResult object of the provided payload
func (*Controller) RedirectJS ¶
func (controller *Controller) RedirectJS(url string) error
RedirectJS is a helper method that will write a very simple html page using the window.location.href='url' method to redirect the borwser to the provided url Note this will also set the controller.ContinuePipeline to false, meaning that the ActionMethod for this request will NOT be called. This allows us to use this method from BeginExecute callbacks to lock down an entire controller to given conditions, such as if the user is logged in. Can be called anytime before AfterExecute.
func (*Controller) RegisterAction ¶
func (controller *Controller) RegisterAction(verb string, name string, method ActionMethod)
RegisterAction allows package caller to map a controller action method to a given Http Request verb and action name (E.g. site.com/Controller/ActionName)
func (*Controller) Result ¶
func (controller *Controller) Result(data []byte) *ActionResult
Result returns a new ActionResult and automatically assigns the controllers cookies
func (*Controller) SetCookie ¶
func (controller *Controller) SetCookie(cookie *http.Cookie)
SetCookie will overwrite or create a cookie in this controllers collection
func (*Controller) SimpleView ¶
func (controller *Controller) SimpleView(templates ...string) *ActionResult
SimpleView takes the provided variadic strings and uses them to call controller.View(templates, controller) Note this is called at the base controller object, therefor will not accept custom controller members. You can pass custom data models by setting them to the controller.ViewData map, which can be accessed in the template via .ViewData["key"]
func (*Controller) ToController ¶
func (controller *Controller) ToController() *Controller
ToController is a method defined by the controller object (which implements IController) that returns a reference to the Controller object it is called on. We use this in the route manager to gain access to the session and cookie collections of the base controller from a custom controller
func (*Controller) View ¶
func (controller *Controller) View(templates []string, model interface{}) *ActionResult
View will take the provided array of template names and try to make an mvcapp Template List (see func mvcapp.MakeTemplateList) using the type name of this controller (from reflection). Then returns the ViewResult that is created. Note this method does NOT include the ViewData collection of the base controller
func (*Controller) WriteResponse ¶
func (controller *Controller) WriteResponse(result *ActionResult) error
WriteResponse is called from the route manager to execute the result that was constructed from this controllers Execute method (E.g. the result returned from the action if mapped)
type ControllerCallback ¶
type ControllerCallback func()
ControllerCallback is a simple declaration to provide a callback method members (e.g. variables that point to methods to be executed)
type ControllerCreator ¶
type ControllerCreator func(*http.Request) IController
ControllerCreator is a delegate to the creation method of a controller that is mapped as the primary route. (E.g. site.com/CONTROLLER is mapped to a NewXController method that implements this signature)
type EmailConnector ¶
type EmailConnector struct { Hostname string Port int Username string Password string Sender gomail.Sender }
EmailConnector is a simple wrapper around the gomail package allowing us to easily send and receive emails
func NewEmailConnector ¶
func NewEmailConnector(hostname string, port int, username string, password string) *EmailConnector
NewEmailConnector constructs a new EmailConnector object from the provided arguments
func (*EmailConnector) SendMail ¶
func (connector *EmailConnector) SendMail(emailMessage *EmailMessage) error
SendMail sends the provided email message through the connector object
type EmailMessage ¶
type EmailMessage struct { // From email address From *mail.Address // To email addresses To []*mail.Address // CC email addresses CC []*mail.Address // BCC email addresses BCC []*mail.Address //Attachments is a slice of the file names to attach to this email Attachments []string // Headers are addition / optional email headers Headers map[string]string // Subject line of the email Subject string // Body or content of the email Body string }
EmailMessage is a simple wrapper providing common email object fields this object is used in the email connector for reading and writing email messages
func NewEmailMessage ¶
NewEmailMessage constructs a new EmailMessage object from the provided arguments
func NewEmailMessageFromTemplate ¶
func NewEmailMessageFromTemplate(from string, to string, subject string, templatePath string, model interface{}) (*EmailMessage, error)
NewEmailMessageFromTemplate executes the provided templatePath and data model to constuct the body text. This and other provided values are then used to call NewEmailMessage
func (*EmailMessage) AddAttachment ¶
func (emailMessage *EmailMessage) AddAttachment(filename string) error
AddAttachment adds the provided filename to be attached to this email message
func (*EmailMessage) AddBCC ¶
func (emailMessage *EmailMessage) AddBCC(bcc string) error
AddBCC adds a new "BCC" or blind carbon copy recipient of this email message
func (*EmailMessage) AddCC ¶
func (emailMessage *EmailMessage) AddCC(cc string) error
AddCC adds a new "CC" or carbon copy recipient of this email message
func (*EmailMessage) AddRecipient ¶
func (emailMessage *EmailMessage) AddRecipient(to string) error
AddRecipient adds a new "To" recipient of this email message
type ErrorResultCallback ¶
type ErrorResultCallback func(err error) *ActionResult
ErrorResultCallback is a simple declaration to provide a callback method used when there is an internal server error (such as custom error page)
type IController ¶
type IController interface { // RegisterAction should add the Verb, Controller and Action method names to the // base controllers action map RegisterAction(string, string, ActionMethod) // Execute should query and execute the mapped action method Execute() (*ActionResult, error) // WriteResponse should write the provided action result to the response stream WriteResponse(*ActionResult) error // RedirectJS is a method that should write an html page with javascript redirect // function directly to the response stream (this can be used to lock pages from // users based of custom conditions, such as logged in or not) RedirectJS(string) error // ToController should return the actual base controller object (so that the system // can interact with controller variable members) ToController() *Controller }
IController defines the RegisterAction and Execute methods that need to be implemented by all controllers
type NotFoundResultCallback ¶
type NotFoundResultCallback func() *ActionResult
NotFoundResultCallback is a simple declaration to provide a callback method used when the requested content can not be found (custom 404)
type RouteManager ¶
type RouteManager struct { // SessionIDKey is the name of the Cookie / Session key to use when identifying // the browser session ID. (E.g. name of the cookie that contains this users // browser session ID) SessionIDKey string // DefaultController is a string defining the name of the controller to execute // when a request comes in to the root of the site (Should be your home / // site index controller) DefaultController string // DefaultAction is a string defining the name of the action method to be called // when a request is made to the root of a controller. (This should be your home // / default or index page name) DefaultAction string // Routes is the collection of RouteMaps that define the controllers which are // registered in this manager Routes []*RouteMap // SessionManager is a pointer to the SessionManager object to use for this app SessionManager *SessionManager // BundleManager is a pointer to the BundleManager that can be used by controllers // that derrive from the BundleController type (Is set during execution pipeline) BundleManager *BundleManager }
RouteManager provides the basic http request pipeline of the mvcapp framework
func NewRouteManager ¶
func NewRouteManager() *RouteManager
NewRouteManager returns a new route manager object with default controller and action tokens set to "Home" and "Index".
func NewRouteManagerFromConfig ¶
func NewRouteManagerFromConfig(config *ConfigurationManager) *RouteManager
NewRouteManagerFromConfig returns a new route manager object with members populated from the provided configuration manager object
func (*RouteManager) GetController ¶
func (manager *RouteManager) GetController(response http.ResponseWriter, request *http.Request) (IController, *Controller)
GetController takes the response and request from our http server and map it to the registered icontroller and controller objects (if they exist)
func (*RouteManager) HandleFile ¶
func (manager *RouteManager) HandleFile(response http.ResponseWriter, request *http.Request) bool
HandleFile is called if HandleRequest fails to load the controller or the result, if this fails we will fall back on MVC 404 functionality
func (*RouteManager) HandleRequest ¶
func (manager *RouteManager) HandleRequest(response http.ResponseWriter, request *http.Request)
HandleRequest is mapped to the http handler method and processes the HTTP request pipeline
func (*RouteManager) ParseControllerName ¶
func (manager *RouteManager) ParseControllerName(path string) string
ParseControllerName returns the controller name requested, will fallback and return the default controller if this is a root request.
func (*RouteManager) RegisterController ¶
func (manager *RouteManager) RegisterController(name string, creator ControllerCreator)
RegisterController is used to map a custom controller object to the controller section of the requested url (E.g. "site.com/CONTROLLER/action")
func (*RouteManager) ServeFile ¶
func (manager *RouteManager) ServeFile(response http.ResponseWriter, request *http.Request) bool
ServeFile is a simple wrapper that allows the caller to serve a raw file to the response
func (*RouteManager) SetControllerSessions ¶
func (manager *RouteManager) SetControllerSessions(controller *Controller) error
SetControllerSessions is called if there is an active session manager. This method will read the browser cookies to find the browser session ID (as defined by the managers SessionIDKey) and if present, will load the browser session value collection for this user into the controllers Session member.
func (*RouteManager) ToQueryStringMap ¶
func (manager *RouteManager) ToQueryStringMap(queryString string) map[string]string
ToQueryStringMap will parse the provided url encoded query string into a map of kvp's
func (*RouteManager) ValidPath ¶
func (manager *RouteManager) ValidPath(path string) bool
ValidPath is used internally to ignore paths that are used by the mvcapp system
type RouteMap ¶
type RouteMap struct { // ControllerName is controller portion of the url that this route map responds to ControllerName string // CreateController is the New*Controller method we call to invoke an instance of // the core controller object (E.g. custom controllers simply provide and register // a method to this map) CreateController ControllerCreator }
RouteMap is used to map the controller portion of the requested URL to a controller struct that implements IController
func NewRouteMap ¶
func NewRouteMap(name string, creator ControllerCreator) *RouteMap
NewRouteMap returns a new RouteMap object populated with the provided name and controller. (E.g. site.com/CONTROLLER/* is mapped to the provided controller creator)
type Session ¶
type Session struct { // ID is the unique key string that represents this browser session ID string // CreatedDate is the date and time when this browser session was created CreatedDate time.Time // ActivityDate is the date and time when this browser session was last active ActivityDate time.Time // Values is the collection of key value pair data stored in this browser session Values map[string]interface{} }
Session represents an http browser session data model
type SessionManager ¶
type SessionManager struct { // SessionIDKey is the name of the cookie value that will store the unique ID of the browser // session SessionIDKey string // Sessions is the collection of browser session objects Sessions map[string]*Session // SessionTimeout is the duration of time that a browser session will stay in memory between // requests / activity from the user SessionTimeout time.Duration }
SessionManager is the base struct that manages the collection of current http session models.
func NewSessionManager ¶
func NewSessionManager() *SessionManager
NewSessionManager returns a new Session Manager object
func NewSessionManagerFromConfig ¶
func NewSessionManagerFromConfig(config *ConfigurationManager) *SessionManager
NewSessionManagerFromConfig returns a new Session Manager object with the Session Timeout set from the provided config
func (*SessionManager) CleanSessions ¶
func (manager *SessionManager) CleanSessions()
CleanSessions will drop inactive sessions (E.g. with those with activity older than now - SessionTimeout)
func (*SessionManager) Contains ¶
func (manager *SessionManager) Contains(id string) bool
Contains detects if the requested id (key) exists in this session collection
func (*SessionManager) CreateSession ¶
func (manager *SessionManager) CreateSession(id string) *Session
CreateSession creates and returns a new http session model
func (*SessionManager) DropSession ¶
func (manager *SessionManager) DropSession(id string)
DropSession will remove a session from the session manager collection based on the provided session id
func (*SessionManager) GetSession ¶
func (manager *SessionManager) GetSession(id string) *Session
GetSession returns the current http session for the provided session id
func (*SessionManager) SetSession ¶
func (manager *SessionManager) SetSession(session *Session)
SetSession will set (creating if necessary) the provided session to the session manager collection