Skip to content

Commit 1e357fb

Browse files
committed
Updated manual to reflect changes
1 parent b8cc7f7 commit 1e357fb

File tree

9 files changed

+318
-54
lines changed

9 files changed

+318
-54
lines changed

.travis.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
language: ruby
22
rvm:
3-
- 2.1
3+
- 2.4.1
44
before_install:
5+
- gem install ruby_dep -v 1.3.1
56
- gem install github-pages
67
- gem install octopress-escape-code
8+
branches:
9+
only:
10+
- master
11+
- develop
712
script: "jekyll build"
813

manual/controllers.md

+53-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,59 @@ The [revel.Controller](https://godoc.org/github.com/revel/revel#Controller) is t
1414
a single request and controls
1515
- the incoming [Request](https://godoc.org/github.com/revel/revel#Request) stuff
1616
- and the [Response](https://godoc.org/github.com/revel/revel#Response) back, in Html, Json, Xml, File or your own custom.
17+
- `Controllers` are reused but not for the same Request <br />
18+
- `Controllers.Destroy` function may be defined to *clean up* locally defined variables and are called
19+
after the controller is used.
20+
21+
A `Controller` instance is not shared by two simultaneous requests, but a controller instance may be
22+
reused. So if you have instance variables that are set in your controller
23+
(like in a `Before` function), you should ensure that these variables are always initialized inside your
24+
`Before` function.
25+
26+
27+
For example say you have a Map defined in your controller, and the `Before` function looks at
28+
the `Controller.Params` object and see that the `name` parameter exists, so it sets that value in the map.
29+
then the controller finishes its execution.
30+
31+
Now a new request comes in and the controller is reused, and the `Before` function looks at
32+
the `Controller.Params` object and does not see that the `name` parameter exists, so it does not change
33+
the "name" in the map, but as you see the map contains the value from the previous request. This type
34+
of hidden bugs can be difficult to track down and it is the reason why it is recommended not to use
35+
additional attributes in the controller
36+
37+
There are a few ways to avoid this situation,
38+
1) Use the `Controller.Args` map to store your single use variables, this map is always initialized
39+
to an empty map so it makes a perfect spot to transfer objects within the controller call
40+
2) If you do use controller defined variables make sure you initialize them in your `Before` function.
41+
(see Before function below)
42+
3) Define a `Destroy` function to "clean up" your locally defined stuff. Make sure the
43+
first thing the Destroy calls is to the controller `Destroy` call
44+
45+
###### Example of a Controller with a `Destroy` function
46+
```go
47+
type MyAppController struct {
48+
*revel.Controller
49+
MyMappedData map[string]interface{}
50+
}
51+
52+
// Assume that this is called for all the controller functions
53+
func (c MyAppController) Before() {
54+
c.MyMappedData = map[string]interface{}{}
55+
}
56+
57+
// This function will be called when the Controller is put back into the stack
58+
func (c MyAppController) Destroy() {
59+
c.Controller.Destroy()
60+
// Clean up locally defined maps or items
61+
c.MyMappedData = nil
62+
}
63+
```
64+
65+
1766

18-
A **Controller** is any type that embeds a [*revel.Controller](https://godoc.org/github.com/revel/revel#Controller) as the **first field/type**.
67+
A **Controller** is any type that embeds a
68+
[*revel.Controller](https://godoc.org/github.com/revel/revel#Controller) as the **first field/type**
69+
and is in a source path called controllers.
1970

2071
```go
2172
type MyAppController struct {
@@ -59,7 +110,7 @@ type Controller struct {
59110
Session Session // Session, stored in cookie, signed.
60111
Params *Params // Parameters from URL and form (including multipart).
61112
Args map[string]interface{} // Per-request scratch space.
62-
ViewArgs map[string]interface{} // Args passed to the template.
113+
ViewArgs map[string]interface{} // Args passed to the template.
63114
Validation *Validation // Data validation helpers
64115
}
65116
```
@@ -113,7 +164,6 @@ type Response struct {
113164
- As part of handling a HTTP request, Revel instantiates an instance of a
114165
[revel.Controller](https://godoc.org/github.com/revel/revel#Controller).
115166
- It then sets all of the properties on the embedded `revel.Controller`.
116-
- Revel does not share a `Controller` instance between requests.
117167

118168
### Extending the Controller
119169

manual/i18n-messages.md

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ greeting.suffix=, welcome to Revel!
150150

151151
A goconfig file is separated into *sections*. The *default section* always exists and contains any messages that are not defined in a specific section. For example:
152152
{% highlight ini %}
153+
[DEFAULT]
153154
key=value
154155

155156
[SECTION]

manual/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Ready to have a blast building apps? Let's get started!
99
- Read about the [concepts](concepts.html)
1010
- Browse the [example applications](/examples/)
1111
- Read the API docs at [godoc](https://godoc.org/github.com/revel/revel)
12+
- Read the Revel cmd [documentation](/manual/tool)
1213
- **Dev Support**
1314
- [![Gitter Chat](http://img.shields.io/badge/chat-online-brightgreen.svg)](https://gitter.im/revel/community)
1415
- [StackOverflow](http://stackoverflow.com/questions/tagged/revel)

manual/interceptors.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ which is useful for some common concerns such as:
2121

2222
In Revel, an interceptor can take one of three forms:
2323

24-
* A [Function Interceptor](#function_interceptor)
25-
* A [Method Interceptor](#method_interceptor)
26-
* A [Controller Auto Interceptor](#controller_auto_interceptor)
24+
* A [Function Interceptor](#function-interceptor)
25+
* A [Method Interceptor](#method-interceptor)
26+
* A [Controller Auto Interceptor](#controller-auto-interceptor)
2727
using the `revel.BeforeAfterFilter` filter
2828

2929
An Interceptor has an [intercept](#intercept_times) point in the request ([When](https://godoc.org/github.com/revel/revel#When))
@@ -120,7 +120,8 @@ Ensure your function names match `func (c Application) Before() (r revel.Result,
120120

121121
## Intercept Times
122122

123-
An interceptor can be registered to run at four points in the request lifecycle; defined in [When()](https://godoc.org/github.com/revel/revel#When):
123+
An interceptor can be registered to run at four points in the request lifecycle;
124+
defined in [When](https://godoc.org/github.com/revel/revel#When):
124125

125126
1. **BEFORE**
126127
* After the request has been [routed](routing.html), the [session, flash](sessionflash.html), and [parameters](parameters.html) decoded, but before the action has been invoked.

0 commit comments

Comments
 (0)