mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
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:
parent
30bc4ed0a0
commit
0013bea901
2 changed files with 31 additions and 30 deletions
|
@ -16,28 +16,26 @@ package resource
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"image/draw"
|
||||||
|
"image/jpeg"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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"
|
"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"
|
_ "golang.org/x/image/webp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -117,6 +115,7 @@ var imageFilters = map[string]imaging.ResampleFilter{
|
||||||
strings.ToLower("Cosine"): imaging.Cosine,
|
strings.ToLower("Cosine"): imaging.Cosine,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Image represents an image resource.
|
||||||
type Image struct {
|
type Image struct {
|
||||||
config image.Config
|
config image.Config
|
||||||
configInit sync.Once
|
configInit sync.Once
|
||||||
|
@ -134,17 +133,19 @@ type Image struct {
|
||||||
*genericResource
|
*genericResource
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Width returns i's width.
|
||||||
func (i *Image) Width() int {
|
func (i *Image) Width() int {
|
||||||
i.initConfig()
|
i.initConfig()
|
||||||
return i.config.Width
|
return i.config.Width
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Height returns i's height.
|
||||||
func (i *Image) Height() int {
|
func (i *Image) Height() int {
|
||||||
i.initConfig()
|
i.initConfig()
|
||||||
return i.config.Height
|
return i.config.Height
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement the Cloner interface.
|
// WithNewBase implements the Cloner interface.
|
||||||
func (i *Image) WithNewBase(base string) Resource {
|
func (i *Image) WithNewBase(base string) Resource {
|
||||||
return &Image{
|
return &Image{
|
||||||
imaging: i.imaging,
|
imaging: i.imaging,
|
||||||
|
@ -535,9 +536,8 @@ func (i *Image) encodeToDestinations(img image.Image, conf imageConfig, resource
|
||||||
}
|
}
|
||||||
if rgba != nil {
|
if rgba != nil {
|
||||||
return jpeg.Encode(w, rgba, &jpeg.Options{Quality: quality})
|
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:
|
default:
|
||||||
return imaging.Encode(w, img, i.format)
|
return imaging.Encode(w, img, i.format)
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,8 +51,6 @@ var (
|
||||||
_ permalinker = (*genericResource)(nil)
|
_ permalinker = (*genericResource)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultResourceType = "unknown"
|
|
||||||
|
|
||||||
var noData = make(map[string]interface{})
|
var noData = make(map[string]interface{})
|
||||||
|
|
||||||
// Source is an internal template and not meant for use in the templates. It
|
// 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{}
|
Params() map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResourcesLanguageMerger describes an interface for merging resources from a
|
||||||
|
// different language.
|
||||||
type ResourcesLanguageMerger interface {
|
type ResourcesLanguageMerger interface {
|
||||||
MergeByLanguage(other Resources) Resources
|
MergeByLanguage(other Resources) Resources
|
||||||
// Needed for integration with the tpl package.
|
// Needed for integration with the tpl package.
|
||||||
|
@ -136,7 +136,7 @@ type ContentResource interface {
|
||||||
Content() (interface{}, error)
|
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.
|
// to open or create a ReadSeekCloser.
|
||||||
type OpenReadSeekCloser func() (hugio.ReadSeekCloser, error)
|
type OpenReadSeekCloser func() (hugio.ReadSeekCloser, error)
|
||||||
|
|
||||||
|
@ -150,6 +150,7 @@ type ReadSeekCloserResource interface {
|
||||||
// I.e. both pages and images etc.
|
// I.e. both pages and images etc.
|
||||||
type Resources []Resource
|
type Resources []Resource
|
||||||
|
|
||||||
|
// ByType returns resources of a given resource type (ie. "image").
|
||||||
func (r Resources) ByType(tp string) Resources {
|
func (r Resources) ByType(tp string) Resources {
|
||||||
var filtered Resources
|
var filtered Resources
|
||||||
|
|
||||||
|
@ -230,19 +231,19 @@ func getGlob(pattern string) (glob.Glob, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MergeByLanguage adds missing translations in r1 from r2.
|
// MergeByLanguage adds missing translations in r1 from r2.
|
||||||
func (r1 Resources) MergeByLanguage(r2 Resources) Resources {
|
func (r Resources) MergeByLanguage(r2 Resources) Resources {
|
||||||
result := append(Resources(nil), r1...)
|
result := append(Resources(nil), r...)
|
||||||
m := make(map[string]bool)
|
m := make(map[string]bool)
|
||||||
for _, r := range r1 {
|
for _, rr := range r {
|
||||||
if translated, ok := r.(translatedResource); ok {
|
if translated, ok := rr.(translatedResource); ok {
|
||||||
m[translated.TranslationKey()] = true
|
m[translated.TranslationKey()] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, r := range r2 {
|
for _, rr := range r2 {
|
||||||
if translated, ok := r.(translatedResource); ok {
|
if translated, ok := rr.(translatedResource); ok {
|
||||||
if _, found := m[translated.TranslationKey()]; !found {
|
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
|
// MergeByLanguageInterface is the generic version of MergeByLanguage. It
|
||||||
// is here just so it can be called from the tpl package.
|
// 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)
|
r2, ok := in.(Resources)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("%T cannot be merged by language", in)
|
return nil, fmt.Errorf("%T cannot be merged by language", in)
|
||||||
}
|
}
|
||||||
return r1.MergeByLanguage(r2), nil
|
return r.MergeByLanguage(r2), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Spec struct {
|
type Spec struct {
|
||||||
|
|
Loading…
Reference in a new issue