diff options
author | Cameron Moore <moorereason@gmail.com> | 2018-09-06 20:41:59 -0500 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-09-07 08:25:51 +0200 |
commit | 0013bea901ee2124f4c18f9728abf47c3880f97d (patch) | |
tree | 324e607110c1250247cabcd9739e39489cbc33c8 /resource/resource.go | |
parent | 30bc4ed0a01f965cc2f9187ccb6ab5d28a3149f6 (diff) |
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
Diffstat (limited to 'resource/resource.go')
-rw-r--r-- | resource/resource.go | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/resource/resource.go b/resource/resource.go index dbbbca3ad..9a974e912 100644 --- a/resource/resource.go +++ b/resource/resource.go @@ -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 { |