Skip to content

Commit

Permalink
Merge pull request #1514 from ptman/lint
Browse files Browse the repository at this point in the history
Fix misspellings and some lint errors
  • Loading branch information
notzippy committed Oct 20, 2020
2 parents 655927a + 060e640 commit 3799c55
Show file tree
Hide file tree
Showing 56 changed files with 617 additions and 566 deletions.
1 change: 0 additions & 1 deletion before_after_filter.go
Expand Up @@ -31,7 +31,6 @@ func BeforeAfterFilter(c *Controller, fc []Filter) {
}

func beforeAfterFilterInvoke(method When, c *Controller) (r *reflect.Value) {

if c.Type == nil {
return
}
Expand Down
5 changes: 2 additions & 3 deletions binder_test.go
Expand Up @@ -7,7 +7,6 @@ package revel
import (
"encoding/json"
"fmt"
"github.com/revel/config"
"io"
"io/ioutil"
"os"
Expand All @@ -16,6 +15,8 @@ import (
"strings"
"testing"
"time"

"github.com/revel/config"
)

type A struct {
Expand Down Expand Up @@ -250,7 +251,6 @@ func TestBinder(t *testing.T) {
}

for k, fhs := range expectedBoundFiles {

if len(fhs) == 1 {
// Test binding single files to: *os.File, []byte, io.Reader, io.ReadSeeker
for _, binding := range fileBindings {
Expand All @@ -263,7 +263,6 @@ func TestBinder(t *testing.T) {
returns := reflect.ValueOf(binding.f).Call([]reflect.Value{actual})
valEq(t, k, returns[0], reflect.ValueOf(fhs[0].content))
}

} else {
// Test binding multi to:
// []*os.File, [][]byte, []io.Reader, []io.ReadSeeker
Expand Down
2 changes: 2 additions & 0 deletions cache/cache.go
Expand Up @@ -137,9 +137,11 @@ func Flush() error { return Insta
func Set(key string, value interface{}, expires time.Duration) error {
return Instance.Set(key, value, expires)
}

func Add(key string, value interface{}, expires time.Duration) error {
return Instance.Add(key, value, expires)
}

func Replace(key string, value interface{}, expires time.Duration) error {
return Instance.Replace(key, value, expires)
}
2 changes: 1 addition & 1 deletion cache/inmemory.go
Expand Up @@ -7,10 +7,10 @@ package cache
import (
"fmt"
"reflect"
"sync"
"time"

"github.com/patrickmn/go-cache"
"sync"
)

type InMemoryCache struct {
Expand Down
1 change: 0 additions & 1 deletion cache/memcached.go
Expand Up @@ -72,7 +72,6 @@ func (c MemcachedCache) Flush() error {

func (c MemcachedCache) invoke(f func(*memcache.Client, *memcache.Item) error,
key string, value interface{}, expires time.Duration) error {

switch expires {
case DefaultExpiryTime:
expires = c.defaultExpiration
Expand Down
3 changes: 1 addition & 2 deletions cache/redis.go
Expand Up @@ -20,7 +20,7 @@ type RedisCache struct {
// NewRedisCache returns a new RedisCache with given parameters
// until redigo supports sharding/clustering, only one host will be in hostList
func NewRedisCache(host string, password string, defaultExpiration time.Duration) RedisCache {
var pool = &redis.Pool{
pool := &redis.Pool{
MaxIdle: revel.Config.IntDefault("cache.redis.maxidle", 5),
MaxActive: revel.Config.IntDefault("cache.redis.maxactive", 0),
IdleTimeout: time.Duration(revel.Config.IntDefault("cache.redis.idletimeout", 240)) * time.Second,
Expand Down Expand Up @@ -237,7 +237,6 @@ func (c RedisCache) Flush() error {

func (c RedisCache) invoke(f func(string, ...interface{}) (interface{}, error),
key string, value interface{}, expires time.Duration) error {

switch expires {
case DefaultExpiryTime:
expires = c.defaultExpiration
Expand Down
34 changes: 17 additions & 17 deletions compress.go
Expand Up @@ -36,22 +36,22 @@ var compressLog = RevelLog.New("section", "compress")

// WriteFlusher interface for compress writer
type WriteFlusher interface {
io.Writer // An IO Writer
io.Closer // A closure
io.Writer // An IO Writer
io.Closer // A closure
Flush() error /// A flush function
}

// The compressed writer
type CompressResponseWriter struct {
Header *BufferedServerHeader // The header
ControllerResponse *Response // The response
OriginalWriter io.Writer // The writer
compressWriter WriteFlusher // The flushed writer
compressionType string // The compression type
headersWritten bool // True if written
closeNotify chan bool // The notify channel to close
parentNotify <-chan bool // The parent chanel to receive the closed event
closed bool // True if closed
ControllerResponse *Response // The response
OriginalWriter io.Writer // The writer
compressWriter WriteFlusher // The flushed writer
compressionType string // The compression type
headersWritten bool // True if written
closeNotify chan bool // The notify channel to close
parentNotify <-chan bool // The parent chanel to receive the closed event
closed bool // True if closed
}

// CompressFilter does compression of response body in gzip/deflate if
Expand Down Expand Up @@ -276,11 +276,11 @@ func detectCompressionType(req *Request, resp *Response) (found bool, compressio
// BufferedServerHeader will not send content out until the Released is called, from that point on it will act normally
// It implements all the ServerHeader
type BufferedServerHeader struct {
cookieList []string // The cookie list
cookieList []string // The cookie list
headerMap map[string][]string // The header map
status int // The status
released bool // True if released
original ServerHeader // The original header
status int // The status
released bool // True if released
original ServerHeader // The original header
}

// Creates a new instance based on the ServerHeader
Expand Down Expand Up @@ -355,14 +355,14 @@ func (bsh *BufferedServerHeader) GetKeys() (value []string) {
value = bsh.original.GetKeys()
for key := range bsh.headerMap {
found := false
for _,v := range value {
if v==key {
for _, v := range value {
if v == key {
found = true
break
}
}
if !found {
value = append(value,key)
value = append(value, key)
}
}
}
Expand Down
57 changes: 28 additions & 29 deletions controller.go
Expand Up @@ -24,30 +24,32 @@ import (
// Controller Revel's controller structure that gets embedded in user defined
// controllers
type Controller struct {
Name string // The controller name, e.g. "Application"
Type *ControllerType // A description of the controller type.
MethodName string // The method name, e.g. "Index"
MethodType *MethodType // A description of the invoked action type.
AppController interface{} // The controller that was instantiated. embeds revel.Controller
Action string // The fully qualified action name, e.g. "App.Index"
ClientIP string // holds IP address of request came from

Request *Request
Response *Response
Result Result

Flash Flash // User cookie, cleared after 1 request.
Session session.Session // Session, stored using the session engine specified
Params *Params // Parameters from URL and form (including multipart).
Args map[string]interface{} // Per-request scratch space.
ViewArgs map[string]interface{} // Variables passed to the template.
Validation *Validation // Data validation helpers
Log logger.MultiLogger // Context Logger
Name string // The controller name, e.g. "Application"
Type *ControllerType // A description of the controller type.
MethodName string // The method name, e.g. "Index"
MethodType *MethodType // A description of the invoked action type.
AppController interface{} // The controller that was instantiated. embeds revel.Controller
Action string // The fully qualified action name, e.g. "App.Index"
ClientIP string // holds IP address of request came from

Request *Request
Response *Response
Result Result

Flash Flash // User cookie, cleared after 1 request.
Session session.Session // Session, stored using the session engine specified
Params *Params // Parameters from URL and form (including multipart).
Args map[string]interface{} // Per-request scratch space.
ViewArgs map[string]interface{} // Variables passed to the template.
Validation *Validation // Data validation helpers
Log logger.MultiLogger // Context Logger
}

// The map of controllers, controllers are mapped by using the namespace|controller_name as the key
var controllers = make(map[string]*ControllerType)
var controllerLog = RevelLog.New("section", "controller")
var (
controllers = make(map[string]*ControllerType)
controllerLog = RevelLog.New("section", "controller")
)

// NewController returns new controller instance for Request and Response
func NewControllerEmpty() *Controller {
Expand All @@ -63,7 +65,6 @@ func NewController(context ServerContext) *Controller {

// Sets the request and the response for the controller
func (c *Controller) SetController(context ServerContext) {

c.Request.SetRequest(context.GetRequest())
c.Response.SetResponse(context.GetResponse())
c.Request.controller = c
Expand All @@ -73,8 +74,8 @@ func (c *Controller) SetController(context ServerContext) {
"RunMode": RunMode,
"DevMode": DevMode,
}

}

func (c *Controller) Destroy() {
// When the instantiated controller gets injected
// It inherits this method, so we need to
Expand Down Expand Up @@ -312,7 +313,7 @@ func (c *Controller) RenderFile(file *os.File, delivery ContentDisposition) Resu
c.setStatusIfNil(http.StatusOK)

var (
modtime = time.Now()
modtime = time.Now()
fileInfo, err = file.Stat()
)
if err != nil {
Expand Down Expand Up @@ -364,7 +365,7 @@ func (c *Controller) Stats() map[string]interface{} {
if RevelConfig.Controller.Reuse {
result["revel-controllers"] = RevelConfig.Controller.Stack.String()
for key, appStack := range RevelConfig.Controller.CachedMap {
result["app-" + key] = appStack.String()
result["app-"+key] = appStack.String()
}
}
return result
Expand All @@ -381,13 +382,11 @@ func (c *Controller) Message(message string, args ...interface{}) string {
// SetAction sets the action that is being invoked in the current request.
// It sets the following properties: Name, Action, Type, MethodType
func (c *Controller) SetAction(controllerName, methodName string) error {

return c.SetTypeAction(controllerName, methodName, nil)
}

// SetAction sets the assigns the Controller type, sets the action and initializes the controller
func (c *Controller) SetTypeAction(controllerName, methodName string, typeOfController *ControllerType) error {

// Look up the controller and method types.
if typeOfController == nil {
if c.Type = ControllerTypeByName(controllerName, anyModule); c.Type == nil {
Expand Down Expand Up @@ -482,8 +481,8 @@ func findControllers(appControllerType reflect.Type) (indexes [][]int) {
for len(queue) > 0 {
// Get the next value and de-reference it if necessary.
var (
node = queue[0]
elem = node.val
node = queue[0]
elem = node.val
elemType = elem.Type()
)
if elemType.Kind() == reflect.Ptr {
Expand Down
2 changes: 2 additions & 0 deletions controller_type.go
Expand Up @@ -14,6 +14,7 @@ type ControllerType struct {
ControllerIndexes [][]int // FieldByIndex to all embedded *Controllers
ControllerEvents *ControllerTypeEvents
}

type ControllerTypeEvents struct {
Before, After, Finally, Panic []*ControllerFieldPath
}
Expand Down Expand Up @@ -141,6 +142,7 @@ func (cte *ControllerTypeEvents) check(theType reflect.Type, fieldPath []int) {
}
}
}

func newFieldPath(isPointer bool, value reflect.Value, fieldPath []int) *ControllerFieldPath {
return &ControllerFieldPath{IsPointer: isPointer, FunctionCall: value, FieldIndexPath: fieldPath}
}
Expand Down
1 change: 0 additions & 1 deletion errors.go
Expand Up @@ -34,7 +34,6 @@ type SourceLine struct {
// provide a code listing of that, on the line that eventually triggered
// the panic. Returns nil if no relevant stack frame can be found.
func NewErrorFromPanic(err interface{}) *Error {

// Parse the filename and line from the originating line of app code.
// /Users/robfig/code/gocode/src/revel/examples/booking/app/controllers/hotels.go:191 (0x44735)
stack := string(debug.Stack())
Expand Down
3 changes: 2 additions & 1 deletion event_test.go
@@ -1,9 +1,10 @@
package revel_test

import (
"testing"

"github.com/revel/revel"
"github.com/stretchr/testify/assert"
"testing"
)

// Test that the event handler can be attached and it dispatches the event received
Expand Down
3 changes: 2 additions & 1 deletion fakeapp_test.go
Expand Up @@ -134,12 +134,13 @@ func registerControllers() {
},
})
}

func startFakeBookingApp() {
Init("prod", "github.com/revel/revel/testdata", "")

MainTemplateLoader = NewTemplateLoader([]string{ViewsPath, filepath.Join(RevelPath, "templates")})
if err := MainTemplateLoader.Refresh(); err != nil {
RevelLog.Fatal("Template error","error",err)
RevelLog.Fatal("Template error", "error", err)
}

registerControllers()
Expand Down

0 comments on commit 3799c55

Please sign in to comment.