Skip to content

Commit 3c791e4

Browse files
committed
revel#1057 addressing golint ALL_CAPS except Interceptors
1 parent ffbd00a commit 3c791e4

File tree

11 files changed

+91
-91
lines changed

11 files changed

+91
-91
lines changed

binder.go

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func ValueBinder(f func(value string, typ reflect.Type) reflect.Value) func(*Par
5151
}
5252

5353
const (
54-
DEFAULT_DATE_FORMAT = "2006-01-02"
55-
DEFAULT_DATETIME_FORMAT = "2006-01-02 15:04"
54+
DefaultDateFormat = "2006-01-02"
55+
DefaultDateTimeFormat = "2006-01-02 15:04"
5656
)
5757

5858
var (
@@ -190,46 +190,6 @@ var (
190190
}
191191
)
192192

193-
// Sadly, the binder lookups can not be declared initialized -- that results in
194-
// an "initialization loop" compile error.
195-
func init() {
196-
KindBinders[reflect.Int] = IntBinder
197-
KindBinders[reflect.Int8] = IntBinder
198-
KindBinders[reflect.Int16] = IntBinder
199-
KindBinders[reflect.Int32] = IntBinder
200-
KindBinders[reflect.Int64] = IntBinder
201-
202-
KindBinders[reflect.Uint] = UintBinder
203-
KindBinders[reflect.Uint8] = UintBinder
204-
KindBinders[reflect.Uint16] = UintBinder
205-
KindBinders[reflect.Uint32] = UintBinder
206-
KindBinders[reflect.Uint64] = UintBinder
207-
208-
KindBinders[reflect.Float32] = FloatBinder
209-
KindBinders[reflect.Float64] = FloatBinder
210-
211-
KindBinders[reflect.String] = StringBinder
212-
KindBinders[reflect.Bool] = BoolBinder
213-
KindBinders[reflect.Slice] = Binder{bindSlice, unbindSlice}
214-
KindBinders[reflect.Struct] = Binder{bindStruct, unbindStruct}
215-
KindBinders[reflect.Ptr] = PointerBinder
216-
KindBinders[reflect.Map] = MapBinder
217-
218-
TypeBinders[reflect.TypeOf(time.Time{})] = TimeBinder
219-
220-
// Uploads
221-
TypeBinders[reflect.TypeOf(&os.File{})] = Binder{bindFile, nil}
222-
TypeBinders[reflect.TypeOf([]byte{})] = Binder{bindByteArray, nil}
223-
TypeBinders[reflect.TypeOf((*io.Reader)(nil)).Elem()] = Binder{bindReadSeeker, nil}
224-
TypeBinders[reflect.TypeOf((*io.ReadSeeker)(nil)).Elem()] = Binder{bindReadSeeker, nil}
225-
226-
OnAppStart(func() {
227-
DateTimeFormat = Config.StringDefault("format.datetime", DEFAULT_DATETIME_FORMAT)
228-
DateFormat = Config.StringDefault("format.date", DEFAULT_DATE_FORMAT)
229-
TimeFormats = append(TimeFormats, DateTimeFormat, DateFormat)
230-
})
231-
}
232-
233193
// Used to keep track of the index for individual keyvalues.
234194
type sliceValue struct {
235195
index int // Index extracted from brackets. If -1, no index was provided.
@@ -506,3 +466,43 @@ func binderForType(typ reflect.Type) (Binder, bool) {
506466
}
507467
return binder, true
508468
}
469+
470+
// Sadly, the binder lookups can not be declared initialized -- that results in
471+
// an "initialization loop" compile error.
472+
func init() {
473+
KindBinders[reflect.Int] = IntBinder
474+
KindBinders[reflect.Int8] = IntBinder
475+
KindBinders[reflect.Int16] = IntBinder
476+
KindBinders[reflect.Int32] = IntBinder
477+
KindBinders[reflect.Int64] = IntBinder
478+
479+
KindBinders[reflect.Uint] = UintBinder
480+
KindBinders[reflect.Uint8] = UintBinder
481+
KindBinders[reflect.Uint16] = UintBinder
482+
KindBinders[reflect.Uint32] = UintBinder
483+
KindBinders[reflect.Uint64] = UintBinder
484+
485+
KindBinders[reflect.Float32] = FloatBinder
486+
KindBinders[reflect.Float64] = FloatBinder
487+
488+
KindBinders[reflect.String] = StringBinder
489+
KindBinders[reflect.Bool] = BoolBinder
490+
KindBinders[reflect.Slice] = Binder{bindSlice, unbindSlice}
491+
KindBinders[reflect.Struct] = Binder{bindStruct, unbindStruct}
492+
KindBinders[reflect.Ptr] = PointerBinder
493+
KindBinders[reflect.Map] = MapBinder
494+
495+
TypeBinders[reflect.TypeOf(time.Time{})] = TimeBinder
496+
497+
// Uploads
498+
TypeBinders[reflect.TypeOf(&os.File{})] = Binder{bindFile, nil}
499+
TypeBinders[reflect.TypeOf([]byte{})] = Binder{bindByteArray, nil}
500+
TypeBinders[reflect.TypeOf((*io.Reader)(nil)).Elem()] = Binder{bindReadSeeker, nil}
501+
TypeBinders[reflect.TypeOf((*io.ReadSeeker)(nil)).Elem()] = Binder{bindReadSeeker, nil}
502+
503+
OnAppStart(func() {
504+
DateTimeFormat = Config.StringDefault("format.datetime", DefaultDateTimeFormat)
505+
DateFormat = Config.StringDefault("format.date", DefaultDateFormat)
506+
TimeFormats = append(TimeFormats, DateTimeFormat, DateFormat)
507+
})
508+
}

binder_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,6 @@ var binderTestCases = map[string]interface{}{
147147
"uint8-overflow": uint8(0),
148148
}
149149

150-
func init() {
151-
DateFormat = DEFAULT_DATE_FORMAT
152-
DateTimeFormat = DEFAULT_DATETIME_FORMAT
153-
TimeFormats = append(TimeFormats, DEFAULT_DATE_FORMAT, DEFAULT_DATETIME_FORMAT, "01/02/2006")
154-
}
155-
156150
// Types that files may be bound to, and a func that can read the content from
157151
// that type.
158152
// TODO: Is there any way to create a slice, given only the element Type?
@@ -274,28 +268,28 @@ var unbinderTestCases = map[string]interface{}{
274268
// Some of the unbinding results are not exactly what is in PARAMS, since it
275269
// serializes implicit zero values explicitly.
276270
var unbinderOverrideAnswers = map[string]map[string]string{
277-
"arr": map[string]string{
271+
"arr": {
278272
"arr[0]": "1",
279273
"arr[1]": "2",
280274
"arr[2]": "0",
281275
"arr[3]": "3",
282276
},
283-
"A": map[string]string{
277+
"A": {
284278
"A.Id": "123",
285279
"A.Name": "rob",
286280
"A.B.Extra": "",
287281
},
288-
"arrC": map[string]string{
282+
"arrC": {
289283
"arrC[0].Id": "5",
290284
"arrC[0].Name": "rob",
291285
"arrC[0].B.Extra": "foo",
292286
"arrC[1].Id": "8",
293287
"arrC[1].Name": "bill",
294288
"arrC[1].B.Extra": "",
295289
},
296-
"m": map[string]string{"m[a]": "foo", "m[b]": "bar"},
297-
"m2": map[string]string{"m2[1]": "foo", "m2[2]": "bar"},
298-
"m3": map[string]string{"m3[a]": "1", "m3[b]": "2"},
290+
"m": {"m[a]": "foo", "m[b]": "bar"},
291+
"m2": {"m2[1]": "foo", "m2[2]": "bar"},
292+
"m3": {"m3[a]": "1", "m3[b]": "2"},
299293
}
300294

301295
func TestUnbinder(t *testing.T) {
@@ -364,3 +358,9 @@ func valEq(t *testing.T, name string, actual, expected reflect.Value) {
364358
eq(t, name, actual.Interface(), expected.Interface())
365359
}
366360
}
361+
362+
func init() {
363+
DateFormat = DefaultDateFormat
364+
DateTimeFormat = DefaultDateTimeFormat
365+
TimeFormats = append(TimeFormats, DefaultDateFormat, DefaultDateTimeFormat, "01/02/2006")
366+
}

field.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ func (f *Field) Value() interface{} {
6363
return val.Interface()
6464
}
6565

66-
// ErrorClass returns ERROR_CLASS if this field has a validation error, else empty string.
66+
// ErrorClass returns ErrorCSSClass if this field has a validation error, else empty string.
6767
func (f *Field) ErrorClass() string {
6868
if f.Error != nil {
6969
if errorClass, ok := f.renderArgs["ERROR_CLASS"]; ok {
7070
return errorClass.(string)
7171
}
72-
return ERROR_CLASS
72+
return ErrorCSSClass
7373
}
7474
return ""
7575
}

intercept.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const (
4848
type InterceptTarget int
4949

5050
const (
51-
ALL_CONTROLLERS InterceptTarget = iota
51+
AllControllers InterceptTarget = iota
5252
)
5353

5454
type Interception struct {
@@ -136,7 +136,7 @@ func InterceptFunc(intc InterceptorFunc, when When, target interface{}) {
136136
function: intc,
137137
callable: reflect.ValueOf(intc),
138138
target: reflect.TypeOf(target),
139-
interceptAll: target == ALL_CONTROLLERS,
139+
interceptAll: target == AllControllers,
140140
})
141141
}
142142

intercept_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ func (c InterceptControllerP) methPN() Result { return nil }
2626
func (c *InterceptControllerP) methPP() Result { return nil }
2727

2828
// Methods accessible from InterceptControllerN
29-
var METHODS_N = []interface{}{
29+
var MethodN = []interface{}{
3030
InterceptController.methN,
3131
(*InterceptController).methP,
3232
InterceptControllerN.methNN,
3333
(*InterceptControllerN).methNP,
3434
}
3535

3636
// Methods accessible from InterceptControllerP
37-
var METHODS_P = []interface{}{
37+
var MethodP = []interface{}{
3838
InterceptController.methN,
3939
(*InterceptController).methP,
4040
InterceptControllerP.methPN,
@@ -47,16 +47,16 @@ func TestInvokeArgType(t *testing.T) {
4747
n := InterceptControllerN{InterceptController{&Controller{}}}
4848
p := InterceptControllerP{&InterceptController{&Controller{}}}
4949
np := InterceptControllerNP{&Controller{}, n, p}
50-
testInterceptorController(t, reflect.ValueOf(&n), METHODS_N)
51-
testInterceptorController(t, reflect.ValueOf(&p), METHODS_P)
52-
testInterceptorController(t, reflect.ValueOf(&np), METHODS_N)
53-
testInterceptorController(t, reflect.ValueOf(&np), METHODS_P)
50+
testInterceptorController(t, reflect.ValueOf(&n), MethodN)
51+
testInterceptorController(t, reflect.ValueOf(&p), MethodP)
52+
testInterceptorController(t, reflect.ValueOf(&np), MethodN)
53+
testInterceptorController(t, reflect.ValueOf(&np), MethodP)
5454
}
5555

5656
func testInterceptorController(t *testing.T, appControllerPtr reflect.Value, methods []interface{}) {
5757
interceptors = []*Interception{}
5858
InterceptFunc(funcP, BEFORE, appControllerPtr.Elem().Interface())
59-
InterceptFunc(funcP2, BEFORE, ALL_CONTROLLERS)
59+
InterceptFunc(funcP2, BEFORE, AllControllers)
6060
for _, m := range methods {
6161
InterceptMethod(m, BEFORE)
6262
}

params_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
// Params: Testing Multipart forms
1414

1515
const (
16-
MULTIPART_BOUNDARY = "A"
17-
MULTIPART_FORM_DATA = `--A
16+
MultipartBoundary = "A"
17+
MultipartFormData = `--A
1818
Content-Disposition: form-data; name="text1"
1919
2020
data1
@@ -76,11 +76,11 @@ var (
7676

7777
func getMultipartRequest() *http.Request {
7878
req, _ := http.NewRequest("POST", "http://localhost/path",
79-
bytes.NewBufferString(MULTIPART_FORM_DATA))
79+
bytes.NewBufferString(MultipartFormData))
8080
req.Header.Set(
81-
"Content-Type", fmt.Sprintf("multipart/form-data; boundary=%s", MULTIPART_BOUNDARY))
81+
"Content-Type", fmt.Sprintf("multipart/form-data; boundary=%s", MultipartBoundary))
8282
req.Header.Set(
83-
"Content-Length", fmt.Sprintf("%d", len(MULTIPART_FORM_DATA)))
83+
"Content-Length", fmt.Sprintf("%d", len(MultipartFormData)))
8484
return req
8585
}
8686

revel.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
const (
18-
REVEL_IMPORT_PATH = "github.com/revel/revel"
18+
RevelImportPath = "github.com/revel/revel"
1919
)
2020

2121
type revelLogs struct {
@@ -140,7 +140,7 @@ func Init(mode, importPath, srcPath string) {
140140
packaged = true
141141
}
142142

143-
RevelPath = filepath.Join(revelSourcePath, filepath.FromSlash(REVEL_IMPORT_PATH))
143+
RevelPath = filepath.Join(revelSourcePath, filepath.FromSlash(RevelImportPath))
144144
BasePath = filepath.Join(SourcePath, filepath.FromSlash(importPath))
145145
AppPath = filepath.Join(BasePath, "app")
146146
ViewsPath = filepath.Join(AppPath, "views")
@@ -311,7 +311,7 @@ func findSrcPaths(importPath string) (revelSourcePath, appSourcePath string) {
311311
ERROR.Fatalln("Failed to import", importPath, "with error:", err)
312312
}
313313

314-
revelPkg, err := build.Import(REVEL_IMPORT_PATH, "", build.FindOnly)
314+
revelPkg, err := build.Import(RevelImportPath, "", build.FindOnly)
315315
if err != nil {
316316
ERROR.Fatalln("Failed to find Revel with error:", err)
317317
}

router_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestComputeRoute(t *testing.T) {
109109

110110
// Router Tests
111111

112-
const TEST_ROUTES = `
112+
const TestRoutes = `
113113
# This is a comment
114114
GET / Application.Index
115115
GET /test/ Application.Index("Test", "Test2")
@@ -256,7 +256,7 @@ var routeMatchTestCases = map[*http.Request]*RouteMatch{
256256
func TestRouteMatches(t *testing.T) {
257257
BasePath = "/BasePath"
258258
router := NewRouter("")
259-
router.Routes, _ = parseRoutes("", "", TEST_ROUTES, false)
259+
router.Routes, _ = parseRoutes("", "", TestRoutes, false)
260260
if err := router.updateTree(); err != nil {
261261
t.Errorf("updateTree failed: %s", err)
262262
}
@@ -340,7 +340,7 @@ var reverseRoutingTestCases = map[*ReverseRouteArgs]*ActionDefinition{
340340

341341
func TestReverseRouting(t *testing.T) {
342342
router := NewRouter("")
343-
router.Routes, _ = parseRoutes("", "", TEST_ROUTES, false)
343+
router.Routes, _ = parseRoutes("", "", TestRoutes, false)
344344
for routeArgs, expected := range reverseRoutingTestCases {
345345
actual := router.Reverse(routeArgs.action, routeArgs.args)
346346
if !eq(t, "Found route", actual != nil, expected != nil) {
@@ -355,7 +355,7 @@ func TestReverseRouting(t *testing.T) {
355355

356356
func BenchmarkRouter(b *testing.B) {
357357
router := NewRouter("")
358-
router.Routes, _ = parseRoutes("", "", TEST_ROUTES, false)
358+
router.Routes, _ = parseRoutes("", "", TestRoutes, false)
359359
if err := router.updateTree(); err != nil {
360360
b.Errorf("updateTree failed: %s", err)
361361
}

session.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
type Session map[string]string
1717

1818
const (
19-
SESSION_ID_KEY = "_ID"
20-
TIMESTAMP_KEY = "_TS"
19+
SessionIDKey = "_ID"
20+
TimestampKey = "_TS"
2121
)
2222

2323
// expireAfterDuration is the time to live, in seconds, of a session cookie.
@@ -43,7 +43,7 @@ func init() {
4343
// Id retrieves from the cookie or creates a time-based UUID identifying this
4444
// session.
4545
func (s Session) Id() string {
46-
if sessionIdStr, ok := s[SESSION_ID_KEY]; ok {
46+
if sessionIdStr, ok := s[SessionIDKey]; ok {
4747
return sessionIdStr
4848
}
4949

@@ -52,14 +52,14 @@ func (s Session) Id() string {
5252
panic(err)
5353
}
5454

55-
s[SESSION_ID_KEY] = hex.EncodeToString(buffer)
56-
return s[SESSION_ID_KEY]
55+
s[SessionIDKey] = hex.EncodeToString(buffer)
56+
return s[SessionIDKey]
5757
}
5858

5959
// getExpiration return a time.Time with the session's expiration date.
6060
// If previous session has set to "session", remain it
6161
func (s Session) getExpiration() time.Time {
62-
if expireAfterDuration == 0 || s[TIMESTAMP_KEY] == "session" {
62+
if expireAfterDuration == 0 || s[TimestampKey] == "session" {
6363
// Expire after closing browser
6464
return time.Time{}
6565
}
@@ -70,7 +70,7 @@ func (s Session) getExpiration() time.Time {
7070
func (s Session) Cookie() *http.Cookie {
7171
var sessionValue string
7272
ts := s.getExpiration()
73-
s[TIMESTAMP_KEY] = getSessionExpirationCookie(ts)
73+
s[TimestampKey] = getSessionExpirationCookie(ts)
7474
for key, value := range s {
7575
if strings.ContainsAny(key, ":\x00") {
7676
panic("Session keys may not have colons or null bytes")
@@ -97,7 +97,7 @@ func (s Session) Cookie() *http.Cookie {
9797
// cookie is either not present or present but beyond its time to live; i.e.,
9898
// whether there is not a valid session.
9999
func sessionTimeoutExpiredOrMissing(session Session) bool {
100-
if exp, present := session[TIMESTAMP_KEY]; !present {
100+
if exp, present := session[TimestampKey]; !present {
101101
return true
102102
} else if exp == "session" {
103103
return false
@@ -176,10 +176,10 @@ func getSessionExpirationCookie(t time.Time) string {
176176

177177
// SetNoExpiration sets session to expire when browser session ends
178178
func (s Session) SetNoExpiration() {
179-
s[TIMESTAMP_KEY] = "session"
179+
s[TimestampKey] = "session"
180180
}
181181

182182
// SetDefaultExpiration sets session to expire after default duration
183183
func (s Session) SetDefaultExpiration() {
184-
delete(s, TIMESTAMP_KEY)
184+
delete(s, TimestampKey)
185185
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy