Skip to content

Commit

Permalink
Merge pull request #1518 from ptman/lint
Browse files Browse the repository at this point in the history
More lint fixes and dead code removal
  • Loading branch information
brendensoares committed Dec 3, 2020
2 parents 3799c55 + 45a4413 commit 413dda3
Show file tree
Hide file tree
Showing 70 changed files with 479 additions and 519 deletions.
2 changes: 1 addition & 1 deletion before_after_filter.go
Expand Up @@ -5,7 +5,7 @@ import (
)

// Autocalls any defined before and after methods on the target controller
// If either calls returns a value then the result is returned
// If either calls returns a value then the result is returned.
func BeforeAfterFilter(c *Controller, fc []Filter) {
defer func() {
if resultValue := beforeAfterFilterInvoke(FINALLY, c); resultValue != nil && !resultValue.IsNil() {
Expand Down
8 changes: 4 additions & 4 deletions binder.go
Expand Up @@ -57,16 +57,16 @@ func ValueBinder(f func(value string, typ reflect.Type) reflect.Value) func(*Par
}
}

// Revel's default date and time constants
// Revel's default date and time constants.
const (
DefaultDateFormat = "2006-01-02"
DefaultDateTimeFormat = "2006-01-02 15:04"
)

// Binders type and kind definition
// Binders type and kind definition.
var (
// These are the lookups to find a Binder for any type of data.
// The most specific binder found will be used (Type before Kind)
// The most specific binder found will be used (Type before Kind).
TypeBinders = make(map[reflect.Type]Binder)
KindBinders = make(map[reflect.Kind]Binder)

Expand Down Expand Up @@ -284,7 +284,7 @@ func bindSlice(params *Params, name string, typ reflect.Type) reflect.Value {
}

// Break on dots and brackets.
// e.g. bar => "bar", bar.baz => "bar", bar[0] => "bar"
// e.g. bar => "bar", bar.baz => "bar", bar[0] => "bar".
func nextKey(key string) string {
fieldLen := strings.IndexAny(key, ".[")
if fieldLen == -1 {
Expand Down
8 changes: 4 additions & 4 deletions binder_test.go
Expand Up @@ -20,9 +20,10 @@ import (
)

type A struct {
ID int
Name string
B B
ID int
Name string
B B
//nolint:unused
private int
}

Expand Down Expand Up @@ -210,7 +211,6 @@ func TestJsonBinder(t *testing.T) {
if actualb["a"]["b"] != 45 {
t.Errorf("Failed to fetch map value %#v", actual["a"])
}

}
}

Expand Down
4 changes: 2 additions & 2 deletions cache/cache_test.go
Expand Up @@ -14,7 +14,7 @@ import (
// They should pass for all implementations.
type cacheFactory func(*testing.T, time.Duration) Cache

// Test typical cache interactions
// Test typical cache interactions.
func typicalGetSet(t *testing.T, newCache cacheFactory) {
var err error
cache := newCache(t, time.Hour)
Expand All @@ -34,7 +34,7 @@ func typicalGetSet(t *testing.T, newCache cacheFactory) {
}
}

// Test the increment-decrement cases
// Test the increment-decrement cases.
func incrDecr(t *testing.T, newCache cacheFactory) {
var err error
cache := newCache(t, time.Hour)
Expand Down
4 changes: 2 additions & 2 deletions cache/inmemory.go
Expand Up @@ -122,7 +122,7 @@ func (c InMemoryCache) Flush() error {
return nil
}

// Fetches and returns the converted type to a uint64
// Fetches and returns the converted type to a uint64.
func (c InMemoryCache) convertTypeToUint64(key string) (newValue uint64, err error) {
v, found := c.cache.Get(key)
if !found {
Expand Down Expand Up @@ -151,7 +151,7 @@ func (c InMemoryCache) convertTypeToUint64(key string) (newValue uint64, err err
case uint32:
newValue = uint64(v.(uint32))
case uint64:
newValue = uint64(v.(uint64))
newValue = v.(uint64)
case float32:
newValue = uint64(v.(float32))
case float64:
Expand Down
4 changes: 2 additions & 2 deletions cache/inmemory_test.go
Expand Up @@ -13,12 +13,12 @@ var newInMemoryCache = func(_ *testing.T, defaultExpiration time.Duration) Cache
return NewInMemoryCache(defaultExpiration)
}

// Test typical cache interactions
// Test typical cache interactions.
func TestInMemoryCache_TypicalGetSet(t *testing.T) {
typicalGetSet(t, newInMemoryCache)
}

// Test the increment-decrement cases
// Test the increment-decrement cases.
func TestInMemoryCache_IncrDecr(t *testing.T) {
incrDecr(t, newInMemoryCache)
}
Expand Down
2 changes: 1 addition & 1 deletion cache/memcached_test.go
Expand Up @@ -10,7 +10,7 @@ import (
"time"
)

// These tests require memcached running on localhost:11211 (the default)
// These tests require memcached running on localhost:11211 (the default).
const testServer = "localhost:11211"

var newMemcachedCache = func(t *testing.T, defaultExpiration time.Duration) Cache {
Expand Down
2 changes: 1 addition & 1 deletion cache/redis.go
Expand Up @@ -18,7 +18,7 @@ type RedisCache struct {
}

// NewRedisCache returns a new RedisCache with given parameters
// until redigo supports sharding/clustering, only one host will be in hostList
// until redigo supports sharding/clustering, only one host will be in hostList.
func NewRedisCache(host string, password string, defaultExpiration time.Duration) RedisCache {
pool := &redis.Pool{
MaxIdle: revel.Config.IntDefault("cache.redis.maxidle", 5),
Expand Down
2 changes: 1 addition & 1 deletion cache/redis_test.go
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/revel/revel"
)

// These tests require redis server running on localhost:6379 (the default)
// These tests require redis server running on localhost:6379 (the default).
const redisTestServer = "localhost:6379"

var newRedisCache = func(t *testing.T, defaultExpiration time.Duration) Cache {
Expand Down
8 changes: 0 additions & 8 deletions cache/serialization_test.go
Expand Up @@ -77,11 +77,3 @@ func TestRoundTrip(t *testing.T) {
}
}
}

func zeroMap(arg map[string]interface{}) map[string]interface{} {
result := map[string]interface{}{}
for key, value := range arg {
result[key] = reflect.Zero(reflect.TypeOf(value)).Interface()
}
return result
}
48 changes: 21 additions & 27 deletions compress.go
Expand Up @@ -31,17 +31,17 @@ var compressableMimes = [...]string{
"application/x-javascript",
}

// Local log instance for this class
// Local log instance for this class.
var compressLog = RevelLog.New("section", "compress")

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

// The compressed writer
// The compressed writer.
type CompressResponseWriter struct {
Header *BufferedServerHeader // The header
ControllerResponse *Response // The response
Expand All @@ -55,7 +55,7 @@ type CompressResponseWriter struct {
}

// CompressFilter does compression of response body in gzip/deflate if
// `results.compressed=true` in the app.conf
// `results.compressed=true` in the app.conf.
func CompressFilter(c *Controller, fc []Filter) {
if c.Response.Out.internalHeader.Server != nil && Config.BoolDefault("results.compressed", false) {
if c.Response.Status != http.StatusNoContent && c.Response.Status != http.StatusNotModified {
Expand Down Expand Up @@ -84,20 +84,15 @@ func CompressFilter(c *Controller, fc []Filter) {
fc[0](c, fc[1:])
}

// Called to notify the writer is closing
// Called to notify the writer is closing.
func (c CompressResponseWriter) CloseNotify() <-chan bool {
if c.parentNotify != nil {
return c.parentNotify
}
return c.closeNotify
}

// Cancel the writer
func (c *CompressResponseWriter) cancel() {
c.closed = true
}

// Prepare the headers
// Prepare the headers.
func (c *CompressResponseWriter) prepareHeaders() {
if c.compressionType != "" {
responseMime := ""
Expand Down Expand Up @@ -126,7 +121,7 @@ func (c *CompressResponseWriter) prepareHeaders() {
c.Header.Release()
}

// Write the headers
// Write the headers.
func (c *CompressResponseWriter) WriteHeader(status int) {
if c.closed {
return
Expand All @@ -136,7 +131,7 @@ func (c *CompressResponseWriter) WriteHeader(status int) {
c.Header.SetStatus(status)
}

// Close the writer
// Close the writer.
func (c *CompressResponseWriter) Close() error {
if c.closed {
return nil
Expand All @@ -150,7 +145,6 @@ func (c *CompressResponseWriter) Close() error {
// TODO When writing directly to stream, an error will be generated
compressLog.Error("Close: Error closing compress writer", "type", c.compressionType, "error", err)
}

}
// Non-blocking write to the closenotifier, if we for some reason should
// get called multiple times
Expand All @@ -162,7 +156,7 @@ func (c *CompressResponseWriter) Close() error {
return nil
}

// Write to the underling buffer
// Write to the underling buffer.
func (c *CompressResponseWriter) Write(b []byte) (int, error) {
if c.closed {
return 0, io.ErrClosedPipe
Expand Down Expand Up @@ -191,7 +185,7 @@ func (c *CompressResponseWriter) Write(b []byte) (int, error) {
}

// DetectCompressionType method detects the compression type
// from header "Accept-Encoding"
// from header "Accept-Encoding".
func detectCompressionType(req *Request, resp *Response) (found bool, compressionType string, compressionKind WriteFlusher) {
if Config.BoolDefault("results.compressed", false) {
acceptedEncodings := strings.Split(req.GetHttpHeader("Accept-Encoding"), ",")
Expand Down Expand Up @@ -274,7 +268,7 @@ 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
// It implements all the ServerHeader.
type BufferedServerHeader struct {
cookieList []string // The cookie list
headerMap map[string][]string // The header map
Expand All @@ -283,12 +277,12 @@ type BufferedServerHeader struct {
original ServerHeader // The original header
}

// Creates a new instance based on the ServerHeader
// Creates a new instance based on the ServerHeader.
func NewBufferedServerHeader(o ServerHeader) *BufferedServerHeader {
return &BufferedServerHeader{original: o, headerMap: map[string][]string{}}
}

// Sets the cookie
// Sets the cookie.
func (bsh *BufferedServerHeader) SetCookie(cookie string) {
if bsh.released {
bsh.original.SetCookie(cookie)
Expand All @@ -297,12 +291,12 @@ func (bsh *BufferedServerHeader) SetCookie(cookie string) {
}
}

// Returns a cookie
// Returns a cookie.
func (bsh *BufferedServerHeader) GetCookie(key string) (ServerCookie, error) {
return bsh.original.GetCookie(key)
}

// Sets (replace) the header key
// Sets (replace) the header key.
func (bsh *BufferedServerHeader) Set(key string, value string) {
if bsh.released {
bsh.original.Set(key, value)
Expand All @@ -311,7 +305,7 @@ func (bsh *BufferedServerHeader) Set(key string, value string) {
}
}

// Add (append) to a key this value
// Add (append) to a key this value.
func (bsh *BufferedServerHeader) Add(key string, value string) {
if bsh.released {
bsh.original.Set(key, value)
Expand All @@ -324,7 +318,7 @@ func (bsh *BufferedServerHeader) Add(key string, value string) {
}
}

// Delete this key
// Delete this key.
func (bsh *BufferedServerHeader) Del(key string) {
if bsh.released {
bsh.original.Del(key)
Expand All @@ -333,7 +327,7 @@ func (bsh *BufferedServerHeader) Del(key string) {
}
}

// Get this key
// Get this key.
func (bsh *BufferedServerHeader) Get(key string) (value []string) {
if bsh.released {
value = bsh.original.Get(key)
Expand All @@ -347,7 +341,7 @@ func (bsh *BufferedServerHeader) Get(key string) (value []string) {
return
}

// Get all header keys
// Get all header keys.
func (bsh *BufferedServerHeader) GetKeys() (value []string) {
if bsh.released {
value = bsh.original.GetKeys()
Expand All @@ -369,7 +363,7 @@ func (bsh *BufferedServerHeader) GetKeys() (value []string) {
return
}

// Set the status
// Set the status.
func (bsh *BufferedServerHeader) SetStatus(statusCode int) {
if bsh.released {
bsh.original.SetStatus(statusCode)
Expand All @@ -378,7 +372,7 @@ func (bsh *BufferedServerHeader) SetStatus(statusCode int) {
}
}

// Release the header and push the results to the original
// Release the header and push the results to the original.
func (bsh *BufferedServerHeader) Release() {
bsh.released = true
for k, v := range bsh.headerMap {
Expand Down

0 comments on commit 413dda3

Please sign in to comment.