static

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: MIT Imports: 0 Imported by: 2

README

For serving directories of static assets, Revel provides the static built in module, which contains a single Static controller.

Static.Serve action takes two parameters: (file path relative to app), (exact file name)

Static.ServeModule action takes three parameters: (module name), (file path relative to app), (exact file name)

Static.ServeDir action takes one parameter: (file path relative to app)

Config

The static module is optional is enabled by default.

By default when you create a new project the following configuration options are set in the file:

module.static = github.com/revel/modules/static

Additionally, these will be set in routes conf/routes:

	GET    /public/*filepath            Static.Serve("public")
	GET    /favicon.ico                 Static.Serve("public","img/favicon.png")
    GET     /public/*filepath           Static.ServeDir("public")
    GET     /public                     Static.ServeDir("public")

The syntax used for defining a route is Controller.Action(prefix,filepath). So the word public has nothing to do with visibility, it follows the default directory

  • prefix (string) - A (relative or absolute) path to the asset root.
  • filepath (string) - A relative path that specifies the requested file.

Bad example

GET    /img/icon.png                Static.Serve("public", "img/icon.png") << space causes error
Important:
For the two parameters version of Static.Serve, blank spaces are not allowed between " and , due to how encoding/csv works.
Static content can only be served from within the application root for security reasons. To include `external assets` consider symbolic links or a git submodule

Best Practices

Although Revel does serve out static content in the most efficient way it can, it makes more sense for your web server to serve the static files directly.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
app

Jump to

Keyboard shortcuts

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