Revel requires itself and the user application to be installed into a GOPATH layout as prescribed by the go command line tool. (See “GOPATH Environment Variable” in the go command documentation)

Default Layout

Below is the recommended layout of a Revel application, supplemented with domain entities and services. (version 1+)

  • my_gocode/ - GOPATH root
    • go.mod - The go.mod file
    • entities/ - domain entities
    • app/ - app sources
      • controllers/ - app controllers
      • models/ - app domain models
      • jobs/ - app domain jobs
      • services/ - app domain services
      • routes/ - reverse routes (generated code)
      • views/ - templates
      • tmp/ - app main file, generated code
    • tests/ - test suites
    • conf/ - configuration files
    • messages/ - i18n message files
    • public/ - static/public assets
      • css/ - stylesheet files
      • js/ - javascript files
      • images/ - image files

Prior to version 1 this is the default layout created

  • my_gocode/ - GOPATH root
    • src/ - GOPATH src/ directory
      • github.com/revel/revel/ - Revel source code
      • bitbucket.org/me/sample/ - Sample app root
        • entities/ - domain entities
        • app/ - app sources
          • controllers/ - app controllers
          • models/ - app domain models
          • jobs/ - app domain jobs
          • services/ - app domain services
          • routes/ - reverse routes (generated code)
          • views/ - templates
          • tmp/ - app main file, generated code
        • tests/ - test suites
        • conf/ - configuration files
        • messages/ - i18n message files
        • public/ - static/public assets
          • css/ - stylesheet files
          • js/ - javascript files
          • images/ - image files
        • vendor/ - vendor folder used for version control
        • Gopkg.toml - vendor dependency management file

app/ directory

The app/ directory contains the source code and templates for your application.

  • app/controllers/ - All controllers are required here
  • app/views - All templates are required here

Beyond that, the application may organize its code however it wishes. Revel will watch all directories under app/ and rebuild when it notices any changes. Any dependencies outside of app/ will not be watched for changes, it is the developer’s responsibility to recompile when necessary.

Additionally, Revel will import any packages within app/ (or imported modules) that contain init() functions on startup, to ensure that all of the developer’s code is initialized.

The app/init.go file is a conventional location to register all of the interceptor hooks. The order of init() functions is undefined between source files from the same package, so collecting all of the interceptor definitions into the same file allows the developer to specify (and know) the order in which they are run. (It could also be used for other order-sensitive initialization in the future.)

conf/ directory

The conf/ directory contains the application’s configuration files. There are two main configuration files:

  • app.conf - the main configuration file for the application
  • routes - the URL routing definition file.

messages/ directory

The messages/ directory contains all localized message files.

public/ directory

Resources stored in the public/ directory are static assets that are served directly by the web server. Typically it is split into three standard sub-directories for images/, css/ stylesheets and js/ JavaScript files.

The names of these directories may be anything and the developer need only update the routes.

vendor/ directory

Used by the dep tool for storing dependent packages (instead of using the GOPATH) see versions. To initialize a vendor application see the Revel tool