Skip to content

Commit

Permalink
Placate linter
Browse files Browse the repository at this point in the history
  • Loading branch information
bboreham committed Mar 20, 2017
1 parent 03411a7 commit aa6c2f4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
4 changes: 1 addition & 3 deletions extras/generate_latest_map
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ function generate_latest_map() {
local data_type="$2"
local uppercase_data_type="${data_type^}"
local lowercase_data_type="${data_type,}"
local entry_type="${uppercase_data_type}LatestEntry"
local decoder_type="${lowercase_data_type}LatestEntryDecoder"
local iface_decoder_variable="${uppercase_data_type}LatestEntryDecoder"
local entry_type="${data_type}LatestEntry"
local latest_map_type="${uppercase_data_type}LatestMap"
local empty_latest_map_variable="Empty${latest_map_type}"
local make_function="Make${latest_map_type}"
Expand Down
24 changes: 12 additions & 12 deletions report/latest_map_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import (
"github.com/weaveworks/ps"
)

type StringLatestEntry struct {
type stringLatestEntry struct {
Timestamp time.Time `json:"timestamp"`
Value string `json:"value"`
}

// String returns the StringLatestEntry's string representation.
func (e *StringLatestEntry) String() string {
func (e *stringLatestEntry) String() string {
return fmt.Sprintf("%v (%s)", e.Value, e.Timestamp.String())
}

// Equal returns true if the supplied StringLatestEntry is equal to this one.
func (e *StringLatestEntry) Equal(e2 *StringLatestEntry) bool {
func (e *stringLatestEntry) Equal(e2 *stringLatestEntry) bool {
return e.Timestamp.Equal(e2.Timestamp) && e.Value == e2.Value
}

Expand Down Expand Up @@ -54,7 +54,7 @@ func (m StringLatestMap) Size() int {
// When both inputs contain the same key, the newer value is used.
func (m StringLatestMap) Merge(other StringLatestMap) StringLatestMap {
output := mergeMaps(m.Map, other.Map, func(a, b interface{}) bool {
return a.(*StringLatestEntry).Timestamp.Before(b.(*StringLatestEntry).Timestamp)
return a.(*stringLatestEntry).Timestamp.Before(b.(*stringLatestEntry).Timestamp)
})
return StringLatestMap{output}
}
Expand All @@ -80,7 +80,7 @@ func (m StringLatestMap) LookupEntry(key string) (string, time.Time, bool) {
var zero string
return zero, time.Time{}, false
}
e := value.(*StringLatestEntry)
e := value.(*stringLatestEntry)
return e.Value, e.Timestamp, true
}

Expand All @@ -89,7 +89,7 @@ func (m StringLatestMap) Set(key string, timestamp time.Time, value string) Stri
if m.Map == nil {
m.Map = ps.NewMap()
}
return StringLatestMap{m.Map.Set(key, &StringLatestEntry{timestamp, value})}
return StringLatestMap{m.Map.Set(key, &stringLatestEntry{timestamp, value})}
}

// Delete the value for the given key.
Expand All @@ -104,7 +104,7 @@ func (m StringLatestMap) Delete(key string) StringLatestMap {
func (m StringLatestMap) ForEach(fn func(k string, timestamp time.Time, v string)) {
if m.Map != nil {
m.Map.ForEach(func(key string, value interface{}) {
fn(key, value.(*StringLatestEntry).Timestamp, value.(*StringLatestEntry).Value)
fn(key, value.(*stringLatestEntry).Timestamp, value.(*stringLatestEntry).Value)
})
}
}
Expand All @@ -117,15 +117,15 @@ func (m StringLatestMap) String() string {
// DeepEqual tests equality with other StringLatestMap.
func (m StringLatestMap) DeepEqual(n StringLatestMap) bool {
return mapEqual(m.Map, n.Map, func(val, otherValue interface{}) bool {
return val.(*StringLatestEntry).Equal(otherValue.(*StringLatestEntry))
return val.(*stringLatestEntry).Equal(otherValue.(*stringLatestEntry))
})
}

func (m StringLatestMap) toIntermediate() map[string]StringLatestEntry {
intermediate := make(map[string]StringLatestEntry, m.Size())
func (m StringLatestMap) toIntermediate() map[string]stringLatestEntry {
intermediate := make(map[string]stringLatestEntry, m.Size())
if m.Map != nil {
m.Map.ForEach(func(key string, val interface{}) {
intermediate[key] = *val.(*StringLatestEntry)
intermediate[key] = *val.(*stringLatestEntry)
})
}
return intermediate
Expand All @@ -143,7 +143,7 @@ func (m *StringLatestMap) CodecEncodeSelf(encoder *codec.Encoder) {
// CodecDecodeSelf implements codec.Selfer.
func (m *StringLatestMap) CodecDecodeSelf(decoder *codec.Decoder) {
out := mapRead(decoder, func(isNil bool) interface{} {
value := &StringLatestEntry{}
value := &stringLatestEntry{}
if !isNil {
decoder.Decode(value)
}
Expand Down
3 changes: 2 additions & 1 deletion report/map_helpers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Helper functions for ps.Map, without considering what is inside
package report

import (
Expand All @@ -10,6 +9,8 @@ import (
"github.com/weaveworks/ps"
)

// Helper functions for ps.Map, without considering what is inside

// Return a new map containing all the elements of the two input maps
// and where the same key is in both, pick 'b' where prefer(a,b) is true
func mergeMaps(m, n ps.Map, prefer func(a, b interface{}) bool) ps.Map {
Expand Down

0 comments on commit aa6c2f4

Please sign in to comment.