resource: Fix golint issues

Fix godoc comments and the following:

resource/image.go:33:2: a blank import should be only in a main or test package, or have a comment justifying it
resource/image.go:35:2: a blank import should be only in a main or test package, or have a comment justifying it
resource/image.go:41:2: a blank import should be only in a main or test package, or have a comment justifying it
resource/image.go:538:10: if block ends with a return statement, so drop this else and outdent its block
resource/resource.go:54:7: exported const DefaultResourceType should have comment or be unexported
resource/resource.go:233:1: receiver name r1 should be consistent with previous receiver name r for Resources
resource/resource.go:254:1: receiver name r1 should be consistent with previous receiver name r for Resources
This commit is contained in:
Cameron Moore 2018-09-06 20:41:59 -05:00 committed by Bjørn Erik Pedersen
parent 30bc4ed0a0
commit 0013bea901
2 changed files with 31 additions and 30 deletions

View file

@ -16,28 +16,26 @@ package resource
import (
"errors"
"fmt"
"image"
"image/color"
"image/draw"
"image/jpeg"
"io"
"os"
"strconv"
"strings"
"github.com/mitchellh/mapstructure"
"github.com/gohugoio/hugo/common/hugio"
"github.com/gohugoio/hugo/helpers"
// Importing image codecs for image.DecodeConfig
"image"
"image/draw"
_ "image/gif"
"image/jpeg"
_ "image/png"
"github.com/disintegration/imaging"
// Import webp codec
"sync"
"github.com/disintegration/imaging"
"github.com/gohugoio/hugo/common/hugio"
"github.com/gohugoio/hugo/helpers"
"github.com/mitchellh/mapstructure"
// Blind import for image.Decode
_ "image/gif"
_ "image/png"
// Blind import for image.Decode
_ "golang.org/x/image/webp"
)
@ -117,6 +115,7 @@ var imageFilters = map[string]imaging.ResampleFilter{
strings.ToLower("Cosine"): imaging.Cosine,
}
// Image represents an image resource.
type Image struct {
config image.Config
configInit sync.Once
@ -134,17 +133,19 @@ type Image struct {
*genericResource
}
// Width returns i's width.
func (i *Image) Width() int {
i.initConfig()
return i.config.Width
}
// Height returns i's height.
func (i *Image) Height() int {
i.initConfig()
return i.config.Height
}
// Implement the Cloner interface.
// WithNewBase implements the Cloner interface.
func (i *Image) WithNewBase(base string) Resource {
return &Image{
imaging: i.imaging,
@ -535,9 +536,8 @@ func (i *Image) encodeToDestinations(img image.Image, conf imageConfig, resource
}
if rgba != nil {
return jpeg.Encode(w, rgba, &jpeg.Options{Quality: quality})
} else {
return jpeg.Encode(w, img, &jpeg.Options{Quality: quality})
}
return jpeg.Encode(w, img, &jpeg.Options{Quality: quality})
default:
return imaging.Encode(w, img, i.format)
}

View file

@ -51,8 +51,6 @@ var (
_ permalinker = (*genericResource)(nil)
)
const DefaultResourceType = "unknown"
var noData = make(map[string]interface{})
// Source is an internal template and not meant for use in the templates. It
@ -110,6 +108,8 @@ type Resource interface {
Params() map[string]interface{}
}
// ResourcesLanguageMerger describes an interface for merging resources from a
// different language.
type ResourcesLanguageMerger interface {
MergeByLanguage(other Resources) Resources
// Needed for integration with the tpl package.
@ -136,7 +136,7 @@ type ContentResource interface {
Content() (interface{}, error)
}
// OpenReadSeekeCloser allows setting some other way (than reading from a filesystem)
// OpenReadSeekCloser allows setting some other way (than reading from a filesystem)
// to open or create a ReadSeekCloser.
type OpenReadSeekCloser func() (hugio.ReadSeekCloser, error)
@ -150,6 +150,7 @@ type ReadSeekCloserResource interface {
// I.e. both pages and images etc.
type Resources []Resource
// ByType returns resources of a given resource type (ie. "image").
func (r Resources) ByType(tp string) Resources {
var filtered Resources
@ -230,19 +231,19 @@ func getGlob(pattern string) (glob.Glob, error) {
}
// MergeByLanguage adds missing translations in r1 from r2.
func (r1 Resources) MergeByLanguage(r2 Resources) Resources {
result := append(Resources(nil), r1...)
func (r Resources) MergeByLanguage(r2 Resources) Resources {
result := append(Resources(nil), r...)
m := make(map[string]bool)
for _, r := range r1 {
if translated, ok := r.(translatedResource); ok {
for _, rr := range r {
if translated, ok := rr.(translatedResource); ok {
m[translated.TranslationKey()] = true
}
}
for _, r := range r2 {
if translated, ok := r.(translatedResource); ok {
for _, rr := range r2 {
if translated, ok := rr.(translatedResource); ok {
if _, found := m[translated.TranslationKey()]; !found {
result = append(result, r)
result = append(result, rr)
}
}
}
@ -251,12 +252,12 @@ func (r1 Resources) MergeByLanguage(r2 Resources) Resources {
// MergeByLanguageInterface is the generic version of MergeByLanguage. It
// is here just so it can be called from the tpl package.
func (r1 Resources) MergeByLanguageInterface(in interface{}) (interface{}, error) {
func (r Resources) MergeByLanguageInterface(in interface{}) (interface{}, error) {
r2, ok := in.(Resources)
if !ok {
return nil, fmt.Errorf("%T cannot be merged by language", in)
}
return r1.MergeByLanguage(r2), nil
return r.MergeByLanguage(r2), nil
}
type Spec struct {