Categorygithub.com/roblillack/mars
modulepackage
1.1.0
Repository: https://github.com/roblillack/mars.git
Documentation: pkg.go.dev

# README

Mars

A lightweight web toolkit for the Go language.

GoDoc Build Status Windows build status Documentation Status Coverage Status Go Report Card License

  • Latest Mars version: 1.1.0 (released May 1, 2022)
  • Supported Go versions: 1.13 … 1.18

Mars is a fork of the fantastic, yet not-that-idiomatic-and-pretty-much-abandoned, Revel framework. You might take a look at the corresponding documentation for the time being.

Have a question? Head over to our Discussions! 💬

Quick Start

Getting started with Mars is as easy as:

  1. Adding the package to your project

    $ go get github.com/roblillack/mars
    
  2. Creating an empty routes file in conf/routes

    $ mkdir conf; echo > conf/routes
    
  3. Running the server as part of your main package

    package main
    
    import "github.com/roblillack/mars"
    
    func main() {
      mars.Run()
    }
    

This essentially sets up an insecure server as part of your application that listens to HTTP (only) and responds to all requests with a 404. To learn where to go from here, please see the Mars tutorial

Differences to Revel

The major changes since forking away from Revel are these:

  • More idiomatic approach to integrating the framework into your application:
    • No need to use the revel command to build, run, package, or distribute your app.
    • Code generation (for registering controllers and reverse routes) is supported using the standard go generate way.
    • No runtime dependencies anymore. Apps using Mars are truly standalone and do not need access to the sources at runtime (default templates and mime config are embedded assets).
    • You are not forced into a fixed directory layout or package names anymore.
    • Removed most of the "path magic" that tried to determine where the sources of your application and revel are: No global AppPath, ViewsPath, TemplatePaths, RevelPath, and SourcePath variables anymore.
  • Added support for Go 1.5+ vendoring.
  • Vendor Mars' dependencies as Git submodules.
  • Added support for HTTP dual-stack mode.
  • Added support for generating self-signed SSL certificates on-the-fly.
  • Added graceful shutdown functionality.
  • Added CSRF protection.
  • Integrated Static controller to support hosting plain HTML files and assets.
  • Removed magic that automatically added template parameter names based on variable names in Controller.Render() calls using code generation and runtime introspection.
  • Removed the cache library.
  • Removed module support.
  • Removed support for configurable template delimiters.
  • Corrected case of render functions (RenderXml --> RenderXML).
  • Fix generating reverse routes for some edge cases: Action parameter is called args or action parameter is of type interface{}.
  • Fixed a XSS vulnerability.

Documentation

Links

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author
Asset loads and returns the asset for the given name.
AssetDir returns the file names below a certain directory embedded in the file by go-bindata.
AssetInfo loads and returns the asset info for the given name.
AssetNames returns the names of the assets.
Bind takes the name and type of the desired parameter and constructs it from one or more values from Params.
No description provided by the author
No description provided by the author
No description provided by the author
Returns a MIME content type based on the filename's extension.
CSRFFilter provides measures of protecting against attacks known as "Cross-site request forgery" multiple ways in which the frontend of the application can prove that a mutating request to the server was actually initiated by the said frontend and not an attacker, that lured the user into calling unwanted on your site.
FilterAction returns a configurator for the filters applied to the given controller method.
FilterConfiguringFilter is a filter stage that customizes the remaining filter chain for the action being invoked.
FilterController returns a configurator for the filters applied to all actions on the given controller instance.
FilterEq returns true if the two filters reference the same filter.
FlashFilter is a Mars Filter that retrieves and sets the flash cookie.
GetSessionFromCookie returns a Session struct pulled from the signed session cookie.
Override allowed http methods via form or browser param.
No description provided by the author
InitDefaults initializes Mars based on runtime-loading of config files.
InterceptFunc installs a general interceptor.
InterceptMethod installs an interceptor method that applies to its own Controller.
InterceptorFilter adds the interception functionality to Mars' filter chain.
No description provided by the author
Perform a message look-up for the given locale and message using the given arguments.
MessageHTML performs a message look-up for the given locale and message using the given arguments and guarantees, that safe HTML is always returned.
Return all currently loaded message languages.
MustAsset is like Asset but panics when Asset would return an error.
NewController creates a new controller based on the given Request and Response structure.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Prepares the route to be used in matching.
No description provided by the author
No description provided by the author
OnAppShutdown register a function to be run at app shutdown.
Register a function to be run at app startup.
PanicFilter wraps the action invocation in a protective defer blanket that converts panics into 500 "Runtime Error" pages.
No description provided by the author
No description provided by the author
RegisterController registers a controller and its methods with Mars.
ResolveAcceptLanguage returns a sorted list of Accept-Language header values.
Get the content type.
ResolveFormat maps the request's Accept MIME type declaration to a Request.Format attribute, specifically "html", "xml", "json", or "txt", returning a default of "html" when Accept header cannot be mapped to a value above.
RestoreAsset restores an asset under the given directory.
RestoreAssets restores an asset under the given directory recursively.
Return a url capable of invoking a given controller method: "Application.ShowApp 123" => "/app/123".
No description provided by the author
No description provided by the author
SessionFilter is a Mars Filter that retrieves and sets the session cookie.
No description provided by the author
SetupRouter will create the router of the application based on the information provided in RoutesFile and the controllers and actions which have been registered using RegisterController.
SetupViews will create a template loader for all the templates provided in ViewsPath.
Sign a given string with the app-configured secret key.
No description provided by the author
No description provided by the author
Mars Filter function to be hooked into the filter chain.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
An adapter for easily making one-key-value binders.
Verify returns true if the given signature is correct for the given message.

# Constants

Interceptor shall be called after invoking the action.
AllControllers means that the function will intercept all controllers.
Interceptor shall be called before invoking the action.
The key for the current locale render arg value.
Interceptor shall be called after invoking the action, and after recovering from a panic.
No description provided by the author
Interceptor shall be called in case the action paniced.
No description provided by the author
No description provided by the author

# Variables

e.g.
e.g.
No description provided by the author
e.g.
Booleans support a couple different value formats: "true" and "false" "on" and "" (a checkbox) "1" and "0" (why not).
No description provided by the author
ConfigFile specifies the path of the main configuration file relative to BasePath, e.g.
Cookie domain.
Cookie flags.
All cookies dropped by the framework begin with this prefix.
No description provided by the author
No description provided by the author
No description provided by the author
Register default validation keys for all calls to Controller.Validation.Func().
No description provided by the author
DisableCSRF disables CSRF checking altogether.
Loggers.
No description provided by the author
No description provided by the author
No description provided by the author
Filters is the default set of global filters.
No description provided by the author
Handler is a http.HandlerFunc which exposes Mars' filtering, routing, and interception functionality for you to use with custom HTTP servers.
e.g.
e.g.
e.g.
e.g.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
MaxAge specifies the time browsers shall cache static content served using Static.Serve.
No description provided by the author
MimeTypesFile specifies the path of the optional MIME type configuration file relative to BasePath, e.g.
NilFilter and NilChain are helpful in writing filter tests.
NilFilter and NilChain are helpful in writing filter tests.
No description provided by the author
RoutesFile specified the path of the route configuration file relative to BasePath, e.g.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
The functions available for use in the templates.
No description provided by the author
Applications can add custom time formats to this array, and they will be automatically attempted when binding a time.Time.
No description provided by the author
These are the lookups to find a Binder for any type of data.
No description provided by the author
ViewPath specifies the name of directory where all the templates are located relative to BasePath, e.g.
No description provided by the author
No description provided by the author

# Structs

AcceptLanguage is a single language from the Accept-Language HTTP header.
No description provided by the author
No description provided by the author
A Binder translates between string parameters and Go data structures.
No description provided by the author
Controller is the main type to embed for creating your own controllers.
No description provided by the author
No description provided by the author
An error description, used as an argument to the error template.
This result handles all kinds of error codes (500, 404, ..).
Field represents a data field that may be collected in a web form.
FilterConfigurator allows the developer configure the filter chain on a per-controller or per-action basis.
Flash represents a cookie that is overwritten on each request.
Interception allows specifying a configuration of when to intercept which invocations.
Requires an array or string to be exactly a given length.
Requires a string to match a given regex.
No description provided by the author
Requires an array or string to be at most a given length.
MergedConfig handles the parsing of app.conf It has a "preferred" section that is checked first for option queries.
No description provided by the author
No description provided by the author
No description provided by the author
Requires an array or string to be at least a given length.
Params provides a unified view of the request params.
No description provided by the author
Requires an integer to be within Min, Max inclusive.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Action methods return this result to request a template be rendered.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
This object handles loading and parsing of templates.
A Validation context manages data validation and error messages.
Simple struct to store the Message & Key of a validation error.
A ValidationResult is returned from every validation method.

# Interfaces

InterceptorMethos represents a method that can be used to intercept action invocations of a specific application controller.
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

AcceptLanguages is collection of sortable AcceptLanguage instances.
Args is a simple shorthand form for map[string]interface{} to represent rendering arguments.
No description provided by the author
No description provided by the author
InterceptorFunc represents a function that can be used to intercept action invocation of a specific or all controllers.
InterceptTarget is a helper make AllControllers have a valid type.
A signed cookie (and thus limited to 4kb in size).
When allows specifying when an interceptor shall be called.