From 18f5fcea28259002dae96227ccae6324bb685cd7 Mon Sep 17 00:00:00 2001 From: rht Date: Sun, 14 Jun 2015 21:44:32 +0700 Subject: [PATCH] golint util/, thirdparty/ and exchange/bitswap/testutils.go License: MIT Signed-off-by: rht --- exchange/bitswap/testutils.go | 6 +++--- test/integration/addcat_test.go | 2 +- test/integration/bench_test.go | 10 +++++----- test/integration/three_legged_cat_test.go | 2 +- thirdparty/eventlog/loggable.go | 2 +- thirdparty/notifier/notifier.go | 2 +- thirdparty/redis-datastore/datastore.go | 22 +++++++++++----------- thirdparty/unit/unit.go | 2 +- util/testutil/gen.go | 2 +- util/testutil/latency_config.go | 14 +++++++------- util/util.go | 10 ++++------ 11 files changed, 36 insertions(+), 38 deletions(-) diff --git a/exchange/bitswap/testutils.go b/exchange/bitswap/testutils.go index 47930de69..91fdece7f 100644 --- a/exchange/bitswap/testutils.go +++ b/exchange/bitswap/testutils.go @@ -50,7 +50,7 @@ func (g *SessionGenerator) Next() Instance { } func (g *SessionGenerator) Instances(n int) []Instance { - instances := make([]Instance, 0) + var instances []Instance for j := 0; j < n; j++ { inst := g.Next() instances = append(instances, inst) @@ -87,12 +87,12 @@ func (i *Instance) SetBlockstoreLatency(t time.Duration) time.Duration { // just a much better idea. func session(ctx context.Context, net tn.Network, p testutil.Identity) Instance { bsdelay := delay.Fixed(0) - const kWriteCacheElems = 100 + const writeCacheElems = 100 adapter := net.Adapter(p) dstore := ds_sync.MutexWrap(datastore2.WithDelay(ds.NewMapDatastore(), bsdelay)) - bstore, err := blockstore.WriteCached(blockstore.NewBlockstore(ds_sync.MutexWrap(dstore)), kWriteCacheElems) + bstore, err := blockstore.WriteCached(blockstore.NewBlockstore(ds_sync.MutexWrap(dstore)), writeCacheElems) if err != nil { panic(err.Error()) // FIXME perhaps change signature and return error. } diff --git a/test/integration/addcat_test.go b/test/integration/addcat_test.go index 62c8944fd..c81672e6c 100644 --- a/test/integration/addcat_test.go +++ b/test/integration/addcat_test.go @@ -61,7 +61,7 @@ func TestDegenerateSlowRouting(t *testing.T) { func Test100MBMacbookCoastToCoast(t *testing.T) { SkipUnlessEpic(t) - conf := testutil.LatencyConfig{}.Network_NYtoSF().Blockstore_SlowSSD2014().Routing_Slow() + conf := testutil.LatencyConfig{}.NetworkNYtoSF().BlockstoreSlowSSD2014().RoutingSlow() if err := DirectAddCat(RandomBytes(100*1024*1024), conf); err != nil { t.Fatal(err) } diff --git a/test/integration/bench_test.go b/test/integration/bench_test.go index b159b912d..eaadf2702 100644 --- a/test/integration/bench_test.go +++ b/test/integration/bench_test.go @@ -21,7 +21,7 @@ func benchmarkAddCat(numBytes int64, conf testutil.LatencyConfig, b *testing.B) } } -var instant = testutil.LatencyConfig{}.All_Instantaneous() +var instant = testutil.LatencyConfig{}.AllInstantaneous() func BenchmarkInstantaneousAddCat1KB(b *testing.B) { benchmarkAddCat(1*unit.KB, instant, b) } func BenchmarkInstantaneousAddCat1MB(b *testing.B) { benchmarkAddCat(1*unit.MB, instant, b) } @@ -34,7 +34,7 @@ func BenchmarkInstantaneousAddCat64MB(b *testing.B) { benchmarkAddCat(64*unit.M func BenchmarkInstantaneousAddCat128MB(b *testing.B) { benchmarkAddCat(128*unit.MB, instant, b) } func BenchmarkInstantaneousAddCat256MB(b *testing.B) { benchmarkAddCat(256*unit.MB, instant, b) } -var routing = testutil.LatencyConfig{}.Routing_Slow() +var routing = testutil.LatencyConfig{}.RoutingSlow() func BenchmarkRoutingSlowAddCat1MB(b *testing.B) { benchmarkAddCat(1*unit.MB, routing, b) } func BenchmarkRoutingSlowAddCat2MB(b *testing.B) { benchmarkAddCat(2*unit.MB, routing, b) } @@ -47,7 +47,7 @@ func BenchmarkRoutingSlowAddCat128MB(b *testing.B) { benchmarkAddCat(128*unit.MB func BenchmarkRoutingSlowAddCat256MB(b *testing.B) { benchmarkAddCat(256*unit.MB, routing, b) } func BenchmarkRoutingSlowAddCat512MB(b *testing.B) { benchmarkAddCat(512*unit.MB, routing, b) } -var network = testutil.LatencyConfig{}.Network_NYtoSF() +var network = testutil.LatencyConfig{}.NetworkNYtoSF() func BenchmarkNetworkSlowAddCat1MB(b *testing.B) { benchmarkAddCat(1*unit.MB, network, b) } func BenchmarkNetworkSlowAddCat2MB(b *testing.B) { benchmarkAddCat(2*unit.MB, network, b) } @@ -59,7 +59,7 @@ func BenchmarkNetworkSlowAddCat64MB(b *testing.B) { benchmarkAddCat(64*unit.MB, func BenchmarkNetworkSlowAddCat128MB(b *testing.B) { benchmarkAddCat(128*unit.MB, network, b) } func BenchmarkNetworkSlowAddCat256MB(b *testing.B) { benchmarkAddCat(256*unit.MB, network, b) } -var hdd = testutil.LatencyConfig{}.Blockstore_7200RPM() +var hdd = testutil.LatencyConfig{}.Blockstore7200RPM() func BenchmarkBlockstoreSlowAddCat1MB(b *testing.B) { benchmarkAddCat(1*unit.MB, hdd, b) } func BenchmarkBlockstoreSlowAddCat2MB(b *testing.B) { benchmarkAddCat(2*unit.MB, hdd, b) } @@ -71,7 +71,7 @@ func BenchmarkBlockstoreSlowAddCat64MB(b *testing.B) { benchmarkAddCat(64*unit. func BenchmarkBlockstoreSlowAddCat128MB(b *testing.B) { benchmarkAddCat(128*unit.MB, hdd, b) } func BenchmarkBlockstoreSlowAddCat256MB(b *testing.B) { benchmarkAddCat(256*unit.MB, hdd, b) } -var mixed = testutil.LatencyConfig{}.Network_NYtoSF().Blockstore_SlowSSD2014().Routing_Slow() +var mixed = testutil.LatencyConfig{}.NetworkNYtoSF().BlockstoreSlowSSD2014().RoutingSlow() func BenchmarkMixedAddCat1MBXX(b *testing.B) { benchmarkAddCat(1*unit.MB, mixed, b) } func BenchmarkMixedAddCat2MBXX(b *testing.B) { benchmarkAddCat(2*unit.MB, mixed, b) } diff --git a/test/integration/three_legged_cat_test.go b/test/integration/three_legged_cat_test.go index 26a7924b6..45b05f769 100644 --- a/test/integration/three_legged_cat_test.go +++ b/test/integration/three_legged_cat_test.go @@ -55,7 +55,7 @@ func TestThreeLeggedCatDegenerateSlowRouting(t *testing.T) { func TestThreeLeggedCat100MBMacbookCoastToCoast(t *testing.T) { SkipUnlessEpic(t) - conf := testutil.LatencyConfig{}.Network_NYtoSF().Blockstore_SlowSSD2014().Routing_Slow() + conf := testutil.LatencyConfig{}.NetworkNYtoSF().BlockstoreSlowSSD2014().RoutingSlow() if err := RunThreeLeggedCat(RandomBytes(100*unit.MB), conf); err != nil { t.Fatal(err) } diff --git a/thirdparty/eventlog/loggable.go b/thirdparty/eventlog/loggable.go index 3f954ccc1..27ffd8048 100644 --- a/thirdparty/eventlog/loggable.go +++ b/thirdparty/eventlog/loggable.go @@ -11,7 +11,7 @@ func (l LoggableMap) Loggable() map[string]interface{} { return l } -// Loggable converts a func into a Loggable +// LoggableF converts a func into a Loggable type LoggableF func() map[string]interface{} func (l LoggableF) Loggable() map[string]interface{} { diff --git a/thirdparty/notifier/notifier.go b/thirdparty/notifier/notifier.go index 7bfdbb22a..5d5a830b0 100644 --- a/thirdparty/notifier/notifier.go +++ b/thirdparty/notifier/notifier.go @@ -71,7 +71,7 @@ func (n *Notifier) Notify(e Notifiee) { n.mu.Unlock() } -// StopNotifying stops notifying Notifiee e. This function +// StopNotify stops notifying Notifiee e. This function // is meant to be called behind your own type-safe function(s): // // // generic function for pattern-following diff --git a/thirdparty/redis-datastore/datastore.go b/thirdparty/redis-datastore/datastore.go index 139ed86eb..cc3161818 100644 --- a/thirdparty/redis-datastore/datastore.go +++ b/thirdparty/redis-datastore/datastore.go @@ -11,31 +11,31 @@ import ( query "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/query" ) -var _ datastore.Datastore = &RedisDatastore{} -var _ datastore.ThreadSafeDatastore = &RedisDatastore{} +var _ datastore.Datastore = &Datastore{} +var _ datastore.ThreadSafeDatastore = &Datastore{} var ErrInvalidType = errors.New("redis datastore: invalid type error. this datastore only supports []byte values") func NewExpiringDatastore(client *redis.Client, ttl time.Duration) (datastore.ThreadSafeDatastore, error) { - return &RedisDatastore{ + return &Datastore{ client: client, ttl: ttl, }, nil } func NewDatastore(client *redis.Client) (datastore.ThreadSafeDatastore, error) { - return &RedisDatastore{ + return &Datastore{ client: client, }, nil } -type RedisDatastore struct { +type Datastore struct { mu sync.Mutex client *redis.Client ttl time.Duration } -func (ds *RedisDatastore) Put(key datastore.Key, value interface{}) error { +func (ds *Datastore) Put(key datastore.Key, value interface{}) error { ds.mu.Lock() defer ds.mu.Unlock() @@ -59,26 +59,26 @@ func (ds *RedisDatastore) Put(key datastore.Key, value interface{}) error { return nil } -func (ds *RedisDatastore) Get(key datastore.Key) (value interface{}, err error) { +func (ds *Datastore) Get(key datastore.Key) (value interface{}, err error) { ds.mu.Lock() defer ds.mu.Unlock() return ds.client.Cmd("GET", key.String()).Bytes() } -func (ds *RedisDatastore) Has(key datastore.Key) (exists bool, err error) { +func (ds *Datastore) Has(key datastore.Key) (exists bool, err error) { ds.mu.Lock() defer ds.mu.Unlock() return ds.client.Cmd("EXISTS", key.String()).Bool() } -func (ds *RedisDatastore) Delete(key datastore.Key) (err error) { +func (ds *Datastore) Delete(key datastore.Key) (err error) { ds.mu.Lock() defer ds.mu.Unlock() return ds.client.Cmd("DEL", key.String()).Err } -func (ds *RedisDatastore) Query(q query.Query) (query.Results, error) { +func (ds *Datastore) Query(q query.Query) (query.Results, error) { return nil, errors.New("TODO implement query for redis datastore?") } -func (ds *RedisDatastore) IsThreadSafe() {} +func (ds *Datastore) IsThreadSafe() {} diff --git a/thirdparty/unit/unit.go b/thirdparty/unit/unit.go index 866beea51..feeaa42bb 100644 --- a/thirdparty/unit/unit.go +++ b/thirdparty/unit/unit.go @@ -19,7 +19,7 @@ func (i Information) String() string { tmp := int64(i) // default - var d int64 = tmp + var d = tmp symbol := "B" switch { diff --git a/util/testutil/gen.go b/util/testutil/gen.go index bfc73723a..1d5d359d3 100644 --- a/util/testutil/gen.go +++ b/util/testutil/gen.go @@ -122,7 +122,7 @@ func (p *PeerNetParams) checkKeys() error { return fmt.Errorf("sig verify failed: %s", err) } if !sigok { - return fmt.Errorf("sig verify failed: sig invalid!") + return fmt.Errorf("sig verify failed: sig invalid") } return nil // ok. move along. diff --git a/util/testutil/latency_config.go b/util/testutil/latency_config.go index 767b9a638..5628d9ed1 100644 --- a/util/testutil/latency_config.go +++ b/util/testutil/latency_config.go @@ -8,7 +8,7 @@ type LatencyConfig struct { RoutingLatency time.Duration } -func (c LatencyConfig) All_Instantaneous() LatencyConfig { +func (c LatencyConfig) AllInstantaneous() LatencyConfig { // Could use a zero value but whatever. Consistency of interface c.NetworkLatency = 0 c.RoutingLatency = 0 @@ -16,33 +16,33 @@ func (c LatencyConfig) All_Instantaneous() LatencyConfig { return c } -func (c LatencyConfig) Network_NYtoSF() LatencyConfig { +func (c LatencyConfig) NetworkNYtoSF() LatencyConfig { c.NetworkLatency = 20 * time.Millisecond return c } -func (c LatencyConfig) Network_IntraDatacenter2014() LatencyConfig { +func (c LatencyConfig) NetworkIntraDatacenter2014() LatencyConfig { c.NetworkLatency = 250 * time.Microsecond return c } -func (c LatencyConfig) Blockstore_FastSSD2014() LatencyConfig { +func (c LatencyConfig) BlockstoreFastSSD2014() LatencyConfig { const iops = 100000 c.BlockstoreLatency = (1 / iops) * time.Second return c } -func (c LatencyConfig) Blockstore_SlowSSD2014() LatencyConfig { +func (c LatencyConfig) BlockstoreSlowSSD2014() LatencyConfig { c.BlockstoreLatency = 150 * time.Microsecond return c } -func (c LatencyConfig) Blockstore_7200RPM() LatencyConfig { +func (c LatencyConfig) Blockstore7200RPM() LatencyConfig { c.BlockstoreLatency = 8 * time.Millisecond return c } -func (c LatencyConfig) Routing_Slow() LatencyConfig { +func (c LatencyConfig) RoutingSlow() LatencyConfig { c.RoutingLatency = 200 * time.Millisecond return c } diff --git a/util/util.go b/util/util.go index 8823a6bf3..d0fee9d42 100644 --- a/util/util.go +++ b/util/util.go @@ -1,4 +1,4 @@ -// package util implements various utility functions used within ipfs +// Package util implements various utility functions used within ipfs // that do not currently have a better place to live. package util @@ -95,7 +95,7 @@ func GetenvBool(name string) bool { return v == "true" || v == "t" || v == "1" } -// multiErr is a util to return multiple errors +// MultiErr is a util to return multiple errors type MultiErr []error func (m MultiErr) Error() string { @@ -116,17 +116,15 @@ func (m MultiErr) Error() string { func Partition(subject string, sep string) (string, string, string) { if i := strings.Index(subject, sep); i != -1 { return subject[:i], subject[i : i+len(sep)], subject[i+len(sep):] - } else { - return subject, "", "" } + return subject, "", "" } func RPartition(subject string, sep string) (string, string, string) { if i := strings.LastIndex(subject, sep); i != -1 { return subject[:i], subject[i : i+len(sep)], subject[i+len(sep):] - } else { - return subject, "", "" } + return subject, "", "" } // Hash is the global IPFS hash function. uses multihash SHA2_256, 256 bits