blog

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2020 License: MIT Imports: 2 Imported by: 0

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StorageInterface

type StorageInterface interface {
	// GetUser is return User based on request
	// posssible to use cache, session, database or something else
	GetUser(ctrl revel.Controller)
	// ListPosts get the list of posts for the user by slug and page
	// if no user slug so it return post ordered by create date
	ListPosts(userSlug string, page int) []*models.Post
	GetPost(userSlug string, postSlug string) *models.Post
	// SavePost is save post. If there no id so it create new post, otherwise it update it
	SavePost(post models.Post)
	// RemovePost is remove the post using userSlug and postSlug. Both params required
	RemovePost(userSlug string, postSlug string)
	// SaveComment is save comment. If there no id so it create new comment, otherwise it update it
	SaveComment(postSlug string, post models.Comment)
	// RemoveComment is remove the comment using postSlug and commentID. Both params required
	RemoveComment(postSlug string, commentID string)
}

StorageInterface is use makeSlug for slugging, i.e. scale-golang-applications

var Storage *StorageInterface

Storage interface

Directories

Path Synopsis
app
routes
GENERATED CODE - DO NOT EDIT This file provides a way of creating URL's based on all the actions found in all the controllers.
GENERATED CODE - DO NOT EDIT This file provides a way of creating URL's based on all the actions found in all the controllers.
tmp
GENERATED CODE - DO NOT EDIT This file is the main file for Revel.
GENERATED CODE - DO NOT EDIT This file is the main file for Revel.
tmp/run
GENERATED CODE - DO NOT EDIT This file is the run file for Revel.
GENERATED CODE - DO NOT EDIT This file is the run file for Revel.

Jump to

Keyboard shortcuts

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