Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5b4a47c

Browse filesBrowse files
committed
Spaces to tabs (gofmt) files
1 parent 0f6050c commit 5b4a47c
Copy full SHA for 5b4a47c

14 files changed

+578
-581
lines changed

‎binder.go

Copy file name to clipboardExpand all lines: binder.go
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package revel
66

77
import (
8+
"encoding/json"
89
"fmt"
910
"io"
1011
"io/ioutil"
@@ -14,7 +15,6 @@ import (
1415
"strconv"
1516
"strings"
1617
"time"
17-
"encoding/json"
1818
)
1919

2020
// A Binder translates between string parameters and Go data structures.
@@ -291,16 +291,16 @@ func unbindSlice(output map[string]string, name string, val interface{}) {
291291
}
292292

293293
func bindStruct(params *Params, name string, typ reflect.Type) reflect.Value {
294-
resultPointer:= reflect.New(typ)
294+
resultPointer := reflect.New(typ)
295295
result := resultPointer.Elem()
296-
if params.JsonRequest {
297-
// Try to inject the response as a json into the created result
298-
if err := json.Unmarshal(params.Json, resultPointer.Interface());err!=nil {
299-
WARN.Println("W: bindStruct: Unable to unmarshal request:", name,err)
300-
}
301-
return result
302-
303-
}
296+
if params.JsonRequest {
297+
// Try to inject the response as a json into the created result
298+
if err := json.Unmarshal(params.Json, resultPointer.Interface()); err != nil {
299+
WARN.Println("W: bindStruct: Unable to unmarshal request:", name, err)
300+
}
301+
return result
302+
303+
}
304304
fieldValues := make(map[string]reflect.Value)
305305
for key := range params.Values {
306306
if !strings.HasPrefix(key, name+".") {

‎compress.go

Copy file name to clipboardExpand all lines: compress.go
+87-87Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,34 @@ type WriteFlusher interface {
4040
}
4141

4242
type CompressResponseWriter struct {
43-
Header *BufferedServerHeader
43+
Header *BufferedServerHeader
4444
ControllerResponse *Response
45-
OriginalWriter io.Writer
46-
compressWriter WriteFlusher
47-
compressionType string
48-
headersWritten bool
49-
closeNotify chan bool
50-
parentNotify <-chan bool
51-
closed bool
45+
OriginalWriter io.Writer
46+
compressWriter WriteFlusher
47+
compressionType string
48+
headersWritten bool
49+
closeNotify chan bool
50+
parentNotify <-chan bool
51+
closed bool
5252
}
5353

5454
// CompressFilter does compression of response body in gzip/deflate if
5555
// `results.compressed=true` in the app.conf
5656
func CompressFilter(c *Controller, fc []Filter) {
57-
if c.Response.ServerHeader!=nil && Config.BoolDefault("results.compressed", false) {
57+
if c.Response.ServerHeader != nil && Config.BoolDefault("results.compressed", false) {
5858
if c.Response.Status != http.StatusNoContent && c.Response.Status != http.StatusNotModified {
5959
if found, compressType, compressWriter := detectCompressionType(c.Request, c.Response); found {
6060
writer := CompressResponseWriter{
61-
ControllerResponse:c.Response,
62-
OriginalWriter: c.Response.GetWriter(),
63-
compressWriter: compressWriter,
64-
compressionType:compressType,
65-
headersWritten:false,
66-
closeNotify: make(chan bool, 1),
67-
closed: false}
68-
// Swap out the header with our own
69-
writer.Header = NewBufferedServerHeader(c.Response.ServerHeader)
70-
c.Response.ServerHeader = writer.Header
61+
ControllerResponse: c.Response,
62+
OriginalWriter: c.Response.GetWriter(),
63+
compressWriter: compressWriter,
64+
compressionType: compressType,
65+
headersWritten: false,
66+
closeNotify: make(chan bool, 1),
67+
closed: false}
68+
// Swap out the header with our own
69+
writer.Header = NewBufferedServerHeader(c.Response.ServerHeader)
70+
c.Response.ServerHeader = writer.Header
7171
if w, ok := c.Response.GetWriter().(http.CloseNotifier); ok {
7272
writer.parentNotify = w.CloseNotify()
7373
}
@@ -109,7 +109,7 @@ func (c *CompressResponseWriter) prepareHeaders() {
109109
c.compressionType = ""
110110
}
111111
}
112-
c.Header.Release()
112+
c.Header.Release()
113113
}
114114

115115
func (c *CompressResponseWriter) WriteHeader(status int) {
@@ -119,14 +119,14 @@ func (c *CompressResponseWriter) WriteHeader(status int) {
119119
}
120120

121121
func (c *CompressResponseWriter) Close() error {
122-
if !c.headersWritten {
123-
c.prepareHeaders()
124-
}
125-
if c.compressionType != "" {
126-
c.Header.Del("Content-Length")
122+
if !c.headersWritten {
123+
c.prepareHeaders()
124+
}
125+
if c.compressionType != "" {
126+
c.Header.Del("Content-Length")
127127
if err := c.compressWriter.Close(); err != nil {
128-
// TODO When writing directly to stream, an error will be generated
129-
ERROR.Println("Error closing compress writer",c.compressionType, err)
128+
// TODO When writing directly to stream, an error will be generated
129+
ERROR.Println("Error closing compress writer", c.compressionType, err)
130130
}
131131

132132
}
@@ -247,84 +247,84 @@ func detectCompressionType(req *Request, resp *Response) (found bool, compressio
247247
return
248248
}
249249

250-
251250
// This class will not send content out until the Released is called, from that point on it will act normally
252251
// It implements all the ServerHeader
253252
type BufferedServerHeader struct {
254-
cookieList []string
255-
headerMap map[string][]string
256-
status int
257-
released bool
258-
original ServerHeader
253+
cookieList []string
254+
headerMap map[string][]string
255+
status int
256+
released bool
257+
original ServerHeader
259258
}
259+
260260
func NewBufferedServerHeader(o ServerHeader) *BufferedServerHeader {
261-
return &BufferedServerHeader{original:o,headerMap:map[string][]string{}}
261+
return &BufferedServerHeader{original: o, headerMap: map[string][]string{}}
262262
}
263263
func (bsh *BufferedServerHeader) SetCookie(cookie string) {
264-
if bsh.released {
265-
bsh.original.SetCookie(cookie)
266-
} else {
267-
bsh.cookieList = append(bsh.cookieList,cookie)
268-
}
264+
if bsh.released {
265+
bsh.original.SetCookie(cookie)
266+
} else {
267+
bsh.cookieList = append(bsh.cookieList, cookie)
268+
}
269269
}
270270
func (bsh *BufferedServerHeader) GetCookie(key string) (value ServerCookie, err error) {
271-
return bsh.original.GetCookie(key)
271+
return bsh.original.GetCookie(key)
272272
}
273-
func (bsh *BufferedServerHeader) Set(key string, value string){
274-
if bsh.released {
275-
bsh.original.Set(key,value)
276-
} else {
277-
bsh.headerMap[key]=[]string{value}
278-
}
273+
func (bsh *BufferedServerHeader) Set(key string, value string) {
274+
if bsh.released {
275+
bsh.original.Set(key, value)
276+
} else {
277+
bsh.headerMap[key] = []string{value}
278+
}
279279
}
280280
func (bsh *BufferedServerHeader) Add(key string, value string) {
281-
if bsh.released {
282-
bsh.original.Set(key,value)
283-
} else {
284-
old := []string{}
285-
if v,found := bsh.headerMap[key];found {
286-
old = v
287-
}
288-
bsh.headerMap[key]=append(old,value)
289-
}
281+
if bsh.released {
282+
bsh.original.Set(key, value)
283+
} else {
284+
old := []string{}
285+
if v, found := bsh.headerMap[key]; found {
286+
old = v
287+
}
288+
bsh.headerMap[key] = append(old, value)
289+
}
290290

291291
}
292-
func (bsh *BufferedServerHeader) Del(key string){
293-
if bsh.released {
294-
bsh.original.Del(key)
295-
} else {
296-
delete(bsh.headerMap,key)
297-
}
292+
func (bsh *BufferedServerHeader) Del(key string) {
293+
if bsh.released {
294+
bsh.original.Del(key)
295+
} else {
296+
delete(bsh.headerMap, key)
297+
}
298298

299299
}
300-
func (bsh *BufferedServerHeader) Get(key string) (value string){
301-
if bsh.released {
302-
value = bsh.original.Get(key)
303-
} else {
304-
if v,found := bsh.headerMap[key]; found && len(v)>0{
305-
value = v[0]
306-
} else {
307-
value = bsh.original.Get(key)
308-
}
309-
}
310-
return
300+
func (bsh *BufferedServerHeader) Get(key string) (value string) {
301+
if bsh.released {
302+
value = bsh.original.Get(key)
303+
} else {
304+
if v, found := bsh.headerMap[key]; found && len(v) > 0 {
305+
value = v[0]
306+
} else {
307+
value = bsh.original.Get(key)
308+
}
309+
}
310+
return
311311
}
312312
func (bsh *BufferedServerHeader) SetStatus(statusCode int) {
313-
if bsh.released {
314-
bsh.original.SetStatus(statusCode)
315-
} else {
316-
bsh.status = statusCode
317-
}
313+
if bsh.released {
314+
bsh.original.SetStatus(statusCode)
315+
} else {
316+
bsh.status = statusCode
317+
}
318318
}
319319
func (bsh *BufferedServerHeader) Release() {
320-
bsh.released = true
321-
bsh.original.SetStatus(bsh.status)
322-
for k,v := range bsh.headerMap {
323-
for _,r:=range v {
324-
bsh.original.Set(k, r)
325-
}
326-
}
327-
for _,c:=range bsh.cookieList {
328-
bsh.original.SetCookie(c)
329-
}
320+
bsh.released = true
321+
bsh.original.SetStatus(bsh.status)
322+
for k, v := range bsh.headerMap {
323+
for _, r := range v {
324+
bsh.original.Set(k, r)
325+
}
326+
}
327+
for _, c := range bsh.cookieList {
328+
bsh.original.SetCookie(c)
329+
}
330330
}

‎controller.go

Copy file name to clipboardExpand all lines: controller.go
+17-16Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ type Controller struct {
4242

4343
// NewController returns new controller instance for Request and Response
4444
func NewControllerEmpty() *Controller {
45-
return &Controller{Request:NewRequest(nil),Response:NewResponse(nil)}
45+
return &Controller{Request: NewRequest(nil), Response: NewResponse(nil)}
4646
}
4747

4848
// New controller, creates a new instance wrapping the request and response in it
4949
func NewController(context ServerContext) *Controller {
50-
c := NewControllerEmpty()
51-
c.SetController(context)
50+
c := NewControllerEmpty()
51+
c.SetController(context)
5252
return c
5353
}
5454

@@ -81,8 +81,8 @@ func (c *Controller) Destroy() {
8181
cachedControllerMap[c.Name].Push(appController)
8282
c.AppController = nil
8383
}
84-
c.Request.Destroy()
85-
c.Response.Destroy()
84+
c.Request.Destroy()
85+
c.Response.Destroy()
8686
c.Params = nil
8787
c.Args = nil
8888
c.ViewArgs = nil
@@ -312,13 +312,14 @@ func (c *Controller) Redirect(val interface{}, args ...interface{}) Result {
312312
// This stats returns some interesting stats based on what is cached in memory
313313
// and what is available directly
314314
func (c *Controller) Stats() map[string]interface{} {
315-
result := CurrentEngine.Stats()
316-
result["revel-controllers"] = controllerStack.String()
317-
for key,appStack := range cachedControllerMap {
318-
result["app-" + key] = appStack.String()
319-
}
320-
return result
315+
result := CurrentEngine.Stats()
316+
result["revel-controllers"] = controllerStack.String()
317+
for key, appStack := range cachedControllerMap {
318+
result["app-"+key] = appStack.String()
319+
}
320+
return result
321321
}
322+
322323
// Message performs a lookup for the given message name using the given
323324
// arguments using the current language defined for this controller.
324325
//
@@ -346,11 +347,11 @@ func (c *Controller) SetAction(controllerName, methodName string) error {
346347
// Create a new stack for this controller
347348
localType := c.Type.Type
348349
cachedControllerMap[c.Name] = NewStackLock(
349-
cachedControllerStackSize,
350-
cachedControllerStackMaxSize,
351-
func() interface{} {
352-
return reflect.New(localType).Interface()
353-
})
350+
cachedControllerStackSize,
351+
cachedControllerStackMaxSize,
352+
func() interface{} {
353+
return reflect.New(localType).Interface()
354+
})
354355
}
355356
// Instantiate the controller.
356357
c.AppController = cachedControllerMap[c.Name].Pop()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.