byteview.go8
1:1format
byteview.go:1:1
/*Copyright 2012 Google Inc.- Fix (safe): run `strider fmt byteview.go`
17:9package-comments
byteview.go:17:9
package groupcache32:6exported-declaration-comment
byteview.go:32:6
// a pointer (like a time.Time).type ByteView struct { // If b is non-nil, b is used, else s is used.96:19exported-declaration-comment
byteview.go:96:19
// b2.func (v ByteView) Equal(b2 ByteView) bool { if b2.b == nil {105:19exported-declaration-comment
byteview.go:105:19
// in s.func (v ByteView) EqualString(s string) bool { if v.b == nil {123:19exported-declaration-comment
byteview.go:123:19
// in b2.func (v ByteView) EqualBytes(b2 []byte) bool { if v.b != nil {159:2no-naked-return
byteview.go:159:2
} return}174:2no-naked-return
byteview.go:174:2
n = int64(m) return}byteview_test.go23
1:1format
byteview_test.go:1:1
/*Copyright 2012 Google Inc.- Fix (safe): run `strider fmt byteview_test.go`
27:6cognitive-complexity
byteview_test.go:27:6
func TestByteView(t *testing.T) { for _, s := range []string{"", "x", "yy"} {27:6cyclomatic-complexity
byteview_test.go:27:6
func TestByteView(t *testing.T) { for _, s := range []string{"", "x", "yy"} {27:6test-parallelism
byteview_test.go:27:6
func TestByteView(t *testing.T) { for _, s := range []string{"", "x", "yy"} {60:11use-any
byteview_test.go:60:11
// of returns a byte view of the []byte or string in x.func of(x interface{}) ByteView { if bytes, ok := x.([]byte); ok {61:5import-shadowing
byteview_test.go:61:5
func of(x interface{}) ByteView { if bytes, ok := x.([]byte); ok { return ByteView{b: bytes}64:22unchecked-type-assertion
byteview_test.go:64:22
} return ByteView{s: x.(string)}}67:6cognitive-complexity
byteview_test.go:67:6
func TestByteViewEqual(t *testing.T) { tests := []struct {67:6test-parallelism
byteview_test.go:67:6
func TestByteViewEqual(t *testing.T) { tests := []struct {68:13nested-structs
byteview_test.go:68:13
func TestByteViewEqual(t *testing.T) { tests := []struct { a interface{} // string or []byte69:8use-any
byteview_test.go:69:8
tests := []struct { a interface{} // string or []byte b interface{} // string or []byte70:8use-any
byteview_test.go:70:8
a interface{} // string or []byte b interface{} // string or []byte want bool73:9add-constant
byteview_test.go:73:9
}{ {"x", "x", true}, {"x", "y", false},78:24add-constant
byteview_test.go:78:24
{[]byte("x"), []byte("y"), false}, {[]byte("x"), []byte("yy"), false}, {[]byte("x"), "x", true},80:17add-constant
byteview_test.go:80:17
{[]byte("x"), "x", true}, {[]byte("x"), "y", false}, {[]byte("x"), "yy", false},88:6import-shadowing
byteview_test.go:88:6
va := of(tt.a) if bytes, ok := tt.b.([]byte); ok { if got := va.EqualBytes(bytes); got != tt.want {93:33unchecked-type-assertion
byteview_test.go:93:33
} else { if got := va.EqualString(tt.b.(string)); got != tt.want { t.Errorf("%d. EqualString = %v; want %v", i, got, tt.want)103:6cognitive-complexity
byteview_test.go:103:6
func TestByteViewSlice(t *testing.T) { tests := []struct {103:6test-parallelism
byteview_test.go:103:6
func TestByteViewSlice(t *testing.T) { tests := []struct {104:13nested-structs
byteview_test.go:104:13
func TestByteViewSlice(t *testing.T) { tests := []struct { in string107:8use-any
byteview_test.go:107:8
from int to interface{} // nil to mean the end (SliceFrom); else int want string122:10add-constant
byteview_test.go:122:10
{ in: "abc", to: 2,131:31unchecked-type-assertion
byteview_test.go:131:31
if tt.to != nil { v = v.Slice(tt.from, tt.to.(int)) } else {consistenthash/consistenthash.go4
1:1format
consistenthash/consistenthash.go:1:1
/*Copyright 2013 Google Inc.- Fix (safe): run `strider fmt consistenthash/consistenthash.go`
26:6exported-declaration-comment
consistenthash/consistenthash.go:26:6
type Hash func(data []byte) uint3228:6exported-declaration-comment
consistenthash/consistenthash.go:28:6
type Map struct { hash Hash35:6exported-declaration-comment
consistenthash/consistenthash.go:35:6
func New(replicas int, fn Hash) *Map { m := &Map{consistenthash/consistenthash_test.go12
1:1format
consistenthash/consistenthash_test.go:1:1
/*Copyright 2013 Google Inc.- Fix (safe): run `strider fmt consistenthash/consistenthash_test.go`
25:6test-parallelism
consistenthash/consistenthash_test.go:25:6
func TestHashing(t *testing.T) {42:9add-constant
consistenthash/consistenthash_test.go:42:9
testCases := map[string]string{ "2": "2", "11": "2",50:13error-strings
consistenthash/consistenthash_test.go:50:13
if hash.Get(k) != v { t.Errorf("Asking for %s, should have yielded %s", k, v) }62:13error-strings
consistenthash/consistenthash_test.go:62:13
if hash.Get(k) != v { t.Errorf("Asking for %s, should have yielded %s", k, v) }68:6test-parallelism
consistenthash/consistenthash_test.go:68:6
func TestConsistency(t *testing.T) { hash1 := New(1, nil)76:12error-strings
consistenthash/consistenthash_test.go:76:12
if hash1.Get("Ben") != hash2.Get("Ben") { t.Errorf("Fetching 'Ben' from both hashes should be the same") }79:21add-constant
consistenthash/consistenthash_test.go:79:21
hash2.Add("Becky", "Ben", "Bobby")81:5optimize-operands-order
consistenthash/consistenthash_test.go:81:5
if hash1.Get("Ben") != hash2.Get("Ben") || hash1.Get("Bob") != hash2.Get("Bob") ||82:13add-constant
consistenthash/consistenthash_test.go:82:13
if hash1.Get("Ben") != hash2.Get("Ben") || hash1.Get("Bob") != hash2.Get("Bob") || hash1.Get("Bonny") != hash2.Get("Bonny") {83:13add-constant
consistenthash/consistenthash_test.go:83:13
hash1.Get("Bob") != hash2.Get("Bob") || hash1.Get("Bonny") != hash2.Get("Bonny") { t.Errorf("Direct matches should always return the same entry")84:12error-strings
consistenthash/consistenthash_test.go:84:12
hash1.Get("Bonny") != hash2.Get("Bonny") { t.Errorf("Direct matches should always return the same entry") }groupcache.go41
1:1file-length-limit
groupcache.go:1:1
/*Copyright 2012 Google Inc.1:1format
groupcache.go:1:1
/*Copyright 2012 Google Inc.- Fix (safe): run `strider fmt groupcache.go`
41:6exported-declaration-comment
groupcache.go:41:6
// A Getter loads data for a key.type Getter interface { // Get returns the value identified by key, populating dest.52:6exported-declaration-comment
groupcache.go:52:6
// A GetterFunc implements Getter with a function.type GetterFunc func(ctx context.Context, key string, dest Sink) error54:21exported-declaration-comment
groupcache.go:54:21
func (f GetterFunc) Get(ctx context.Context, key string, dest Sink) error { return f(ctx, key, dest)58:1top-level-declaration-order
groupcache.go:58:1
var ( mu sync.RWMutex59:2no-package-var
groupcache.go:59:2
var ( mu sync.RWMutex groups = make(map[string]*Group)60:2no-package-var
groupcache.go:60:2
mu sync.RWMutex groups = make(map[string]*Group)62:2no-package-var
groupcache.go:62:2
initPeerServerOnce sync.Once initPeerServer func()63:2no-package-var
groupcache.go:63:2
initPeerServerOnce sync.Once initPeerServer func())68:6exported-declaration-comment
groupcache.go:68:6
// nil if there's no such group.func GetGroup(name string) *Group { mu.RLock()84:6exported-declaration-comment
groupcache.go:84:6
// The group name must be unique for each getter.func NewGroup(name string, cacheBytes int64, getter Getter) *Group { return newGroup(name, cacheBytes, getter, nil)89:6confusing-naming
groupcache.go:89:6
// If peers is nil, the peerPicker is called via a sync.Once to initialize it.func newGroup(name string, cacheBytes int64, getter Getter, peers PeerPicker) *Group { if getter == nil {114:5no-package-var
groupcache.go:114:5
// newGroupHook, if non-nil, is called right after a new group is created.var newGroupHook func(*Group)118:6exported-declaration-comment
groupcache.go:118:6
// a group is created.func RegisterNewGroupHook(fn func(*Group)) { if newGroupHook != nil {127:6exported-declaration-comment
groupcache.go:127:6
// group is created.func RegisterServerStart(fn func()) { if initPeerServer != nil {142:6exported-declaration-comment
groupcache.go:142:6
// a group of 1 or more machines.type Group struct { name string177:2import-shadowing
groupcache.go:177:2
// to get predictable results in TestPeers. rand *rand.Rand}185:28use-any
groupcache.go:185:28
// Done is called when Do is done. Do(key string, fn func() (interface{}, error)) (interface{}, error)}185:50use-any
groupcache.go:185:50
// Done is called when Do is done. Do(key string, fn func() (interface{}, error)) (interface{}, error)}212:17exported-declaration-comment
groupcache.go:212:17
func (g *Group) Get(ctx context.Context, key string, dest Sink) error { g.peersOnce.Do(g.initPeers)243:44use-any
groupcache.go:243:44
g.Stats.Loads.Add(1) viewi, err := g.loadGroup.Do(key, func() (interface{}, error) { // Check the cache again because singleflight can only dedup calls279:4task-comment
groupcache.go:279:4
g.Stats.PeerErrors.Add(1) // TODO(bradfitz): log the peer's error? keep // log of the past few for /groupcachez? It's295:16unchecked-type-assertion
groupcache.go:295:16
if err == nil { value = viewi.(ByteView) }297:2no-naked-return
groupcache.go:297:2
} return}319:2task-comment
groupcache.go:319:2
value := ByteView{b: res.Value} // TODO(bradfitz): use res.MinuteQps or something smart to // conditionally populate hotCache. For now just do it some336:3no-naked-return
groupcache.go:336:3
if g.cacheBytes <= 0 { return }340:3no-naked-return
groupcache.go:340:3
if ok { return }343:2no-naked-return
groupcache.go:343:2
value, ok = g.hotCache.get(key) return}360:3task-comment
groupcache.go:360:3
// TODO(bradfitz): this is good-enough-for-now logic. // It should be something based on measurements and/or377:2exported-declaration-comment
groupcache.go:377:2
// owner for. MainCache CacheType = iota + 1382:2exported-declaration-comment
groupcache.go:382:2
// owner. HotCache)387:2single-case-switch
groupcache.go:387:2
func (g *Group) CacheStats(which CacheType) CacheStats { switch which { case MainCache:403:2import-shadowing
groupcache.go:403:2
nbytes int64 // of all keys and values lru *lru.Cache nhit, nget int64425:39use-any
groupcache.go:425:39
c.lru = &lru.Cache{ OnEvicted: func(key lru.Key, value interface{}) { val := value.(ByteView)426:17unchecked-type-assertion
groupcache.go:426:17
OnEvicted: func(key lru.Key, value interface{}) { val := value.(ByteView) c.nbytes -= int64(len(key.(string))) + int64(val.Len())427:30unchecked-type-assertion
groupcache.go:427:30
val := value.(ByteView) c.nbytes -= int64(len(key.(string))) + int64(val.Len()) c.nevict++441:3no-naked-return
groupcache.go:441:3
if c.lru == nil { return }445:3no-naked-return
groupcache.go:445:3
if !ok { return }448:11unchecked-type-assertion
groupcache.go:448:11
c.nhit++ return vi.(ByteView), true}479:6exported-declaration-comment
groupcache.go:479:6
// An AtomicInt is an int64 to be accessed atomically.type AtomicInt int64groupcache_test.go40
1:1format
groupcache_test.go:1:1
/*Copyright 2012 Google Inc.- Fix (safe): run `strider fmt groupcache_test.go`
33:2deprecated-api-usage
groupcache_test.go:33:2
"github.com/golang/protobuf/proto"36:2redundant-import-alias
groupcache_test.go:36:2
pb "github.com/golang/groupcache/groupcachepb" testpb "github.com/golang/groupcache/testpb")40:2no-package-var
groupcache_test.go:40:2
var ( once sync.Once stringGroup, protoGroup Getter41:2no-package-var
groupcache_test.go:41:2
once sync.Once stringGroup, protoGroup Getter41:15no-package-var
groupcache_test.go:41:15
once sync.Once stringGroup, protoGroup Getter43:2no-package-var
groupcache_test.go:43:2
stringc = make(chan string)45:2no-package-var
groupcache_test.go:45:2
dummyCtx = context.TODO()50:2no-package-var
groupcache_test.go:50:2
// cacheFills function. cacheFills AtomicInt)53:1top-level-declaration-order
groupcache_test.go:53:1
const ( stringGroupName = "string-group"84:6cognitive-complexity
groupcache_test.go:84:6
// outstanding callers. This is the string variant.func TestGetDupSuppressString(t *testing.T) { once.Do(testSetup)84:6test-parallelism
groupcache_test.go:84:6
// outstanding callers. This is the string variant.func TestGetDupSuppressString(t *testing.T) { once.Do(testSetup)103:2task-comment
groupcache_test.go:103:2
// singleflight. // TODO(bradfitz): decide whether there are any non-offensive // debug/test hooks that could be added to singleflight to126:6cognitive-complexity
groupcache_test.go:126:6
// outstanding callers. This is the proto variant.func TestGetDupSuppressProto(t *testing.T) { once.Do(testSetup)126:6test-parallelism
groupcache_test.go:126:6
// outstanding callers. This is the proto variant.func TestGetDupSuppressProto(t *testing.T) { once.Do(testSetup)144:2task-comment
groupcache_test.go:144:2
// singleflight. // TODO(bradfitz): decide whether there are any non-offensive // debug/test hooks that could be added to singleflight to174:6test-parallelism
groupcache_test.go:174:6
func TestCaching(t *testing.T) { once.Do(testSetup)189:6test-parallelism
groupcache_test.go:189:6
func TestCacheEviction(t *testing.T) { once.Do(testSetup)205:18unchecked-type-assertion
groupcache_test.go:205:18
g := stringGroup.(*Group) evict0 := g.mainCache.nevict214:3discarded-error-result
groupcache_test.go:214:3
key := fmt.Sprintf("dummy-key-%d", bytesFlooded) stringGroup.Get(dummyCtx, key, StringSink(&res)) bytesFlooded += int64(len(key) + len(res))234:20exported-declaration-comment
groupcache_test.go:234:20
func (p *fakePeer) Get(_ context.Context, in *pb.GetRequest, out *pb.GetResponse) error { p.hits++239:2modifies-parameter
groupcache_test.go:239:2
} out.Value = []byte("got:" + in.GetKey()) return nil245:20exported-declaration-comment
groupcache_test.go:245:20
func (p fakePeers) PickPeer(key string) (peer ProtoGetter, ok bool) { if len(p) == 0 {247:3no-naked-return
groupcache_test.go:247:3
if len(p) == 0 { return }254:6cognitive-complexity
groupcache_test.go:254:6
// TestPeers tests that peers (virtual, in-process) are hit, and how much.func TestPeers(t *testing.T) { once.Do(testSetup)254:6test-parallelism
groupcache_test.go:254:6
// TestPeers tests that peers (virtual, in-process) are hit, and how much.func TestPeers(t *testing.T) { once.Do(testSetup)277:12add-constant
groupcache_test.go:277:12
key := fmt.Sprintf("key-%d", i) want := "got:" + key var got string312:2task-comment
groupcache_test.go:312:2
// With one of the peers being down. // TODO(bradfitz): on a peer number being unavailable, the // consistent hashing should maybe keep trying others to325:6test-parallelism
groupcache_test.go:325:6
func TestTruncatingByteSliceTarget(t *testing.T) { var buf [100]byte344:6test-parallelism
groupcache_test.go:344:6
func TestAllocatingByteSliceTarget(t *testing.T) { var dst []byte349:2discarded-error-result
groupcache_test.go:349:2
inBytes := []byte("some bytes") sink.SetBytes(inBytes) if want := "some bytes"; string(dst) != want {351:12error-strings
groupcache_test.go:351:12
if want := "some bytes"; string(dst) != want { t.Errorf("SetBytes resulted in %q; want %q", dst, want) }378:30exported-declaration-comment
groupcache_test.go:378:30
func (g *orderedFlightGroup) Do(key string, fn func() (interface{}, error)) (interface{}, error) { <-g.stage1378:56use-any
groupcache_test.go:378:56
func (g *orderedFlightGroup) Do(key string, fn func() (interface{}, error)) (interface{}, error) { <-g.stage1378:78use-any
groupcache_test.go:378:78
func (g *orderedFlightGroup) Do(key string, fn func() (interface{}, error)) (interface{}, error) { <-g.stage1388:6cognitive-complexity
groupcache_test.go:388:6
// unable to dedup calls.func TestNoDedup(t *testing.T) { const testkey = "testkey"388:6test-parallelism
groupcache_test.go:388:6
// unable to dedup calls.func TestNoDedup(t *testing.T) { const testkey = "testkey"413:13add-constant
groupcache_test.go:413:13
if err := g.Get(dummyCtx, testkey, StringSink(&s)); err != nil { resc <- "ERROR:" + err.Error() return448:6test-parallelism
groupcache_test.go:448:6
func TestGroupStatsAlignment(t *testing.T) { var g Group456:1task-comment
groupcache_test.go:456:1
// TODO(bradfitz): port the Google-internal full integration test into here,// using HTTP requests instead of our RPC system.groupcachepb/groupcache.pb.go21
1:1format
groupcachepb/groupcache.pb.go:1:1
// Code generated by protoc-gen-go.// source: groupcache.proto- Fix (safe): run `strider fmt groupcachepb/groupcache.pb.go`
5:9filename-format
groupcachepb/groupcache.pb.go:5:9
package groupcachepb5:9package-comments
groupcachepb/groupcache.pb.go:5:9
package groupcachepb7:8redundant-import-alias
groupcachepb/groupcache.pb.go:7:8
import proto "github.com/golang/protobuf/proto"import json "encoding/json"7:14deprecated-api-usage
groupcachepb/groupcache.pb.go:7:14
import proto "github.com/golang/protobuf/proto"import json "encoding/json"8:8redundant-import-alias
groupcachepb/groupcache.pb.go:8:8
import proto "github.com/golang/protobuf/proto"import json "encoding/json"import math "math"9:8redundant-import-alias
groupcachepb/groupcache.pb.go:9:8
import json "encoding/json"import math "math"16:6exported-declaration-comment
groupcachepb/groupcache.pb.go:16:6
type GetRequest struct { Group *string `protobuf:"bytes,1,req,name=group" json:"group,omitempty"`19:2var-naming
groupcachepb/groupcache.pb.go:19:2
Key *string `protobuf:"bytes,2,req,name=key" json:"key,omitempty"` XXX_unrecognized []byte `json:"-"`}22:22exported-declaration-comment
groupcachepb/groupcache.pb.go:22:22
func (m *GetRequest) Reset() { *m = GetRequest{} }func (m *GetRequest) String() string { return proto.CompactTextString(m) }24:20exported-declaration-comment
groupcachepb/groupcache.pb.go:24:20
func (m *GetRequest) String() string { return proto.CompactTextString(m) }func (*GetRequest) ProtoMessage() {}26:22exported-declaration-comment
groupcachepb/groupcache.pb.go:26:22
func (m *GetRequest) GetGroup() string { if m != nil && m.Group != nil {33:22exported-declaration-comment
groupcachepb/groupcache.pb.go:33:22
func (m *GetRequest) GetKey() string { if m != nil && m.Key != nil {40:1top-level-declaration-order
groupcachepb/groupcache.pb.go:40:1
type GetResponse struct { Value []byte `protobuf:"bytes,1,opt,name=value" json:"value,omitempty"`40:6exported-declaration-comment
groupcachepb/groupcache.pb.go:40:6
type GetResponse struct { Value []byte `protobuf:"bytes,1,opt,name=value" json:"value,omitempty"`43:2var-naming
groupcachepb/groupcache.pb.go:43:2
MinuteQps *float64 `protobuf:"fixed64,2,opt,name=minute_qps" json:"minute_qps,omitempty"` XXX_unrecognized []byte `json:"-"`}46:23exported-declaration-comment
groupcachepb/groupcache.pb.go:46:23
func (m *GetResponse) Reset() { *m = GetResponse{} }func (m *GetResponse) String() string { return proto.CompactTextString(m) }48:21exported-declaration-comment
groupcachepb/groupcache.pb.go:48:21
func (m *GetResponse) String() string { return proto.CompactTextString(m) }func (*GetResponse) ProtoMessage() {}50:23exported-declaration-comment
groupcachepb/groupcache.pb.go:50:23
func (m *GetResponse) GetValue() []byte { if m != nil {57:23exported-declaration-comment
groupcachepb/groupcache.pb.go:57:23
func (m *GetResponse) GetMinuteQps() float64 { if m != nil && m.MinuteQps != nil {64:6no-init
groupcachepb/groupcache.pb.go:64:6
func init() {}http.go16
1:1format
http.go:1:1
/*Copyright 2013 Google Inc.- Fix (safe): run `strider fmt http.go`
17:9package-comments
http.go:17:9
package groupcache31:2deprecated-api-usage
http.go:31:2
pb "github.com/golang/groupcache/groupcachepb" "github.com/golang/protobuf/proto")80:6exported-declaration-comment
http.go:80:6
// for example "http://example.net:8000".func NewHTTPPool(self string) *HTTPPool { p := NewHTTPPoolOpts(self, nil)86:1top-level-declaration-order
http.go:86:1
var httpPoolMade bool86:5no-package-var
http.go:86:5
var httpPoolMade bool91:6exported-declaration-comment
http.go:91:6
// The returned *HTTPPool implements http.Handler and must be registered using http.Handle.func NewHTTPPoolOpts(self string, o *HTTPPoolOptions) *HTTPPool { if httpPoolMade {119:20exported-declaration-comment
http.go:119:20
// for example "http://example.net:8000".func (p *HTTPPool) Set(peers ...string) { p.mu.Lock()126:25range-value-address
http.go:126:25
for _, peer := range peers { p.httpGetters[peer] = &httpGetter{transport: p.Transport, baseURL: peer + p.opts.BasePath} }130:20exported-declaration-comment
http.go:130:20
func (p *HTTPPool) PickPeer(key string) (ProtoGetter, bool) { p.mu.Lock()183:2discarded-error-result
http.go:183:2
w.Header().Set("Content-Type", "application/x-protobuf") w.Write(body)}191:5no-package-var
http.go:191:5
var bufferPool = sync.Pool{ New: func() interface{} { return new(bytes.Buffer) },192:14use-any
http.go:192:14
var bufferPool = sync.Pool{ New: func() interface{} { return new(bytes.Buffer) },}195:22exported-declaration-comment
http.go:195:22
func (h *httpGetter) Get(ctx context.Context, in *pb.GetRequest, out *pb.GetResponse) error { u := fmt.Sprintf(202:30standard-http-method-constant
http.go:202:30
) req, err := http.NewRequest("GET", u, nil) if err != nil {219:23unchecked-type-assertion
http.go:219:23
} b := bufferPool.Get().(*bytes.Buffer) b.Reset()http_test.go17
1:1format
http_test.go:1:1
/*Copyright 2013 Google Inc.- Fix (safe): run `strider fmt http_test.go`
36:2no-package-var
http_test.go:36:2
var ( peerAddrs = flag.String("test_peer_addrs", "", "Comma-separated list of peer addresses; used by TestHTTPPool") peerIndex = flag.Int("test_peer_index", -1, "Index of which peer this child is; used by TestHTTPPool")37:2no-package-var
http_test.go:37:2
peerAddrs = flag.String("test_peer_addrs", "", "Comma-separated list of peer addresses; used by TestHTTPPool") peerIndex = flag.Int("test_peer_index", -1, "Index of which peer this child is; used by TestHTTPPool") peerChild = flag.Bool("test_peer_child", false, "True if running as a child process; used by TestHTTPPool")38:2no-package-var
http_test.go:38:2
peerIndex = flag.Int("test_peer_index", -1, "Index of which peer this child is; used by TestHTTPPool") peerChild = flag.Bool("test_peer_child", false, "True if running as a child process; used by TestHTTPPool"))41:6cognitive-complexity
http_test.go:41:6
func TestHTTPPool(t *testing.T) { if *peerChild {41:6test-parallelism
http_test.go:41:6
func TestHTTPPool(t *testing.T) { if *peerChild {44:3deep-exit
http_test.go:44:3
beChildForTestHTTPPool() os.Exit(0) }76:5discarded-error-result
http_test.go:76:5
if cmds[i].Process != nil { cmds[i].Process.Kill() }100:13error-strings
http_test.go:100:13
if suffix := ":" + key; !strings.HasSuffix(value, suffix) { t.Errorf("Get(%q) = %q, want value ending in %q", key, value, suffix) }111:2no-naked-return
http_test.go:111:2
} return}117:19insecure-url-scheme
http_test.go:117:19
p := NewHTTPPool("http://" + addrs[*peerIndex]) p.Set(addrToURL(addrs)...)121:3discarded-error-result
http_test.go:121:3
getter := GetterFunc(func(ctx context.Context, key string, dest Sink) error { dest.SetString(strconv.Itoa(*peerIndex) + ":" + key) return nil126:2deep-exit
http_test.go:126:2
log.Fatal(http.ListenAndServe(addrs[*peerIndex], p))}145:12insecure-url-scheme
http_test.go:145:12
for i := range addr { url[i] = "http://" + addr[i] }150:21unused-parameter
http_test.go:150:21
func awaitAddrReady(t *testing.T, addr string, wg *sync.WaitGroup) { defer wg.Done()152:8redefines-builtin-id
http_test.go:152:8
defer wg.Done() const max = 1 * time.Second tries := 0158:4discarded-error-result
http_test.go:158:4
if err == nil { c.Close() returnlru/lru.go18
1:1format
lru/lru.go:1:1
/*Copyright 2013 Google Inc.- Fix (safe): run `strider fmt lru/lru.go`
30:32use-any
lru/lru.go:30:32
// executed when an entry is purged from the cache. OnEvicted func(key Key, value interface{})33:12use-any
lru/lru.go:33:12
ll *list.List cache map[interface{}]*list.Element}36:1doc-comment-period
lru/lru.go:36:1
// A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operatorstype Key interface{}37:6exported-declaration-comment
lru/lru.go:37:6
// A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operatorstype Key interface{}37:10use-any
lru/lru.go:37:10
// A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operatorstype Key interface{}41:8use-any
lru/lru.go:41:8
key Key value interface{}}47:6exported-declaration-comment
lru/lru.go:47:6
// that eviction is done by the caller.func New(maxEntries int) *Cache { return &Cache{51:24use-any
lru/lru.go:51:24
ll: list.New(), cache: make(map[interface{}]*list.Element), }56:36use-any
lru/lru.go:56:36
// Add adds a value to the cache.func (c *Cache) Add(key Key, value interface{}) { if c.cache == nil {58:22use-any
lru/lru.go:58:22
if c.cache == nil { c.cache = make(map[interface{}]*list.Element) c.ll = list.New()63:11unchecked-type-assertion
lru/lru.go:63:11
c.ll.MoveToFront(ee) ee.Value.(*entry).value = value return74:37use-any
lru/lru.go:74:37
// Get looks up a key's value from the cache.func (c *Cache) Get(key Key) (value interface{}, ok bool) { if c.cache == nil {76:3no-naked-return
lru/lru.go:76:3
if c.cache == nil { return }80:19unchecked-type-assertion
lru/lru.go:80:19
c.ll.MoveToFront(ele) return ele.Value.(*entry).value, true }82:2no-naked-return
lru/lru.go:82:2
} return}108:15unchecked-type-assertion
lru/lru.go:108:15
c.ll.Remove(e) kv := e.Value.(*entry) delete(c.cache, kv.key)127:17unchecked-type-assertion
lru/lru.go:127:17
for _, e := range c.cache { kv := e.Value.(*entry) c.OnEvicted(kv.key, kv.value)lru/lru_test.go11
1:1format
lru/lru_test.go:1:1
/*Copyright 2013 Google Inc.- Fix (safe): run `strider fmt lru/lru_test.go`
34:1top-level-declaration-order
lru/lru_test.go:34:1
var getTests = []struct { name string34:5no-package-var
lru/lru_test.go:34:5
var getTests = []struct { name string34:18nested-structs
lru/lru_test.go:34:18
var getTests = []struct { name string36:13use-any
lru/lru_test.go:36:13
name string keyToAdd interface{} keyToGet interface{}37:13use-any
lru/lru_test.go:37:13
keyToAdd interface{} keyToGet interface{} expectedOk bool48:6test-parallelism
lru/lru_test.go:48:6
func TestGet(t *testing.T) { for _, tt := range getTests {61:6test-parallelism
lru/lru_test.go:61:6
func TestRemove(t *testing.T) { lru := New(0)70:13add-constant
lru/lru_test.go:70:13
lru.Remove("myKey") if _, ok := lru.Get("myKey"); ok {76:6test-parallelism
lru/lru_test.go:76:6
func TestEvict(t *testing.T) { evictedKeys := make([]Key, 0)78:38use-any
lru/lru_test.go:78:38
evictedKeys := make([]Key, 0) onEvictedFun := func(key Key, value interface{}) { evictedKeys = append(evictedKeys, key)peers.go10
1:1format
peers.go:1:1
/*Copyright 2012 Google Inc.- Fix (safe): run `strider fmt peers.go`
19:9package-comments
peers.go:19:9
package groupcache37:6exported-declaration-comment
peers.go:37:6
// the peer that owns a specific key.type PeerPicker interface { // PickPeer returns the peer that owns the specific key47:16exported-declaration-comment
peers.go:47:16
func (NoPeers) PickPeer(key string) (peer ProtoGetter, ok bool) { return }47:25unused-parameter
peers.go:47:25
func (NoPeers) PickPeer(key string) (peer ProtoGetter, ok bool) { return }47:67no-naked-return
peers.go:47:67
func (NoPeers) PickPeer(key string) (peer ProtoGetter, ok bool) { return }49:1top-level-declaration-order
peers.go:49:1
var ( portPicker func(groupName string) PeerPicker50:2no-package-var
peers.go:50:2
var ( portPicker func(groupName string) PeerPicker)57:6exported-declaration-comment
peers.go:57:6
// called exactly once, but not both.func RegisterPeerPicker(fn func() PeerPicker) { if portPicker != nil {69:6exported-declaration-comment
peers.go:69:6
// called exactly once, but not both.func RegisterPerGroupPeerPicker(fn func(groupName string) PeerPicker) { if portPicker != nil {singleflight/singleflight.go5
26:6use-any
singleflight/singleflight.go:26:6
wg sync.WaitGroup val interface{} err error32:6exported-declaration-comment
singleflight/singleflight.go:32:6
// units of work can be executed with duplicate suppression.type Group struct { mu sync.Mutex // protects m41:17exported-declaration-comment
singleflight/singleflight.go:41:17
// original to complete and receives the same results.func (g *Group) Do(key string, fn func() (interface{}, error)) (interface{}, error) { g.mu.Lock()41:43use-any
singleflight/singleflight.go:41:43
// original to complete and receives the same results.func (g *Group) Do(key string, fn func() (interface{}, error)) (interface{}, error) { g.mu.Lock()41:65use-any
singleflight/singleflight.go:41:65
// original to complete and receives the same results.func (g *Group) Do(key string, fn func() (interface{}, error)) (interface{}, error) { g.mu.Lock()singleflight/singleflight_test.go13
28:6test-parallelism
singleflight/singleflight_test.go:28:6
func TestDo(t *testing.T) { var g Group30:32use-any
singleflight/singleflight_test.go:30:32
var g Group v, err := g.Do("key", func() (interface{}, error) { return "bar", nil34:12error-strings
singleflight/singleflight_test.go:34:12
if got, want := fmt.Sprintf("%v (%T)", v, v), "bar (string)"; got != want { t.Errorf("Do = %v; want %v", got, want) }37:12error-strings
singleflight/singleflight_test.go:37:12
if err != nil { t.Errorf("Do error = %v", err) }41:6test-parallelism
singleflight/singleflight_test.go:41:6
func TestDoErr(t *testing.T) { var g Group44:32use-any
singleflight/singleflight_test.go:44:32
someErr := errors.New("some error") v, err := g.Do("key", func() (interface{}, error) { return nil, someErr48:12error-strings
singleflight/singleflight_test.go:48:12
if err != someErr { t.Errorf("Do error = %v; want someErr", err) }55:6test-parallelism
singleflight/singleflight_test.go:55:6
func TestDoDupSuppress(t *testing.T) { var g Group59:16use-any
singleflight/singleflight_test.go:59:16
var calls int32 fn := func() (interface{}, error) { atomic.AddInt32(&calls, 1)69:19add-constant
singleflight/singleflight_test.go:69:19
go func() { v, err := g.Do("key", fn) if err != nil {71:14error-strings
singleflight/singleflight_test.go:71:14
if err != nil { t.Errorf("Do error: %v", err) }73:8unchecked-type-assertion
singleflight/singleflight_test.go:73:8
} if v.(string) != "bar" { t.Errorf("got %q; want %q", v, "bar")74:36add-constant
singleflight/singleflight_test.go:74:36
if v.(string) != "bar" { t.Errorf("got %q; want %q", v, "bar") }sinks.go25
1:1format
sinks.go:1:1
/*Copyright 2012 Google Inc.- Fix (safe): run `strider fmt sinks.go`
17:9package-comments
sinks.go:17:9
package groupcache22:2deprecated-api-usage
sinks.go:22:2
"github.com/golang/protobuf/proto")29:6exported-declaration-comment
sinks.go:29:6
// on success.type Sink interface { // SetString sets the value to s.73:1top-level-declaration-order
sinks.go:73:1
type stringSink struct { sp *string76:2task-comment
sinks.go:76:2
v ByteView // TODO(bradfitz): track whether any Sets were called.}80:2task-comment
sinks.go:80:2
func (s *stringSink) view() (ByteView, error) { // TODO(bradfitz): return an error if no Set was called return s.v, nil84:22exported-declaration-comment
sinks.go:84:22
func (s *stringSink) SetString(v string) error { s.v.b = nil91:22exported-declaration-comment
sinks.go:91:22
func (s *stringSink) SetBytes(v []byte) error { return s.SetString(string(v))95:22exported-declaration-comment
sinks.go:95:22
func (s *stringSink) SetProto(m proto.Message) error { b, err := proto.Marshal(m)135:24exported-declaration-comment
sinks.go:135:24
func (s *byteViewSink) SetProto(m proto.Message) error { b, err := proto.Marshal(m)144:24exported-declaration-comment
sinks.go:144:24
func (s *byteViewSink) SetBytes(b []byte) error { *s.dst = ByteView{b: cloneBytes(b)}149:24exported-declaration-comment
sinks.go:149:24
func (s *byteViewSink) SetString(v string) error { *s.dst = ByteView{s: v}172:21exported-declaration-comment
sinks.go:172:21
func (s *protoSink) SetBytes(b []byte) error { err := proto.Unmarshal(b, s.dst)182:21exported-declaration-comment
sinks.go:182:21
func (s *protoSink) SetString(v string) error { b := []byte(v)193:21exported-declaration-comment
sinks.go:193:21
func (s *protoSink) SetProto(m proto.Message) error { b, err := proto.Marshal(m)198:2task-comment
sinks.go:198:2
} // TODO(bradfitz): optimize for same-task case more and write // right through? would need to document ownership rules at214:6exported-declaration-comment
sinks.go:214:6
// it to *dst. The memory is not retained by groupcache.func AllocatingByteSliceSink(dst *[]byte) Sink { return &allocBytesSink{dst: dst}237:26exported-declaration-comment
sinks.go:237:26
func (s *allocBytesSink) SetProto(m proto.Message) error { b, err := proto.Marshal(m)245:26exported-declaration-comment
sinks.go:245:26
func (s *allocBytesSink) SetBytes(b []byte) error { return s.setBytesOwned(cloneBytes(b))259:26exported-declaration-comment
sinks.go:259:26
func (s *allocBytesSink) SetString(v string) error { if s.dst == nil {273:6exported-declaration-comment
sinks.go:273:6
// is shrunk to fit the number of bytes available.func TruncatingByteSliceSink(dst *[]byte) Sink { return &truncBytesSink{dst: dst}286:26exported-declaration-comment
sinks.go:286:26
func (s *truncBytesSink) SetProto(m proto.Message) error { b, err := proto.Marshal(m)294:26exported-declaration-comment
sinks.go:294:26
func (s *truncBytesSink) SetBytes(b []byte) error { return s.setBytesOwned(cloneBytes(b))311:26exported-declaration-comment
sinks.go:311:26
func (s *truncBytesSink) SetString(v string) error { if s.dst == nil {testpb/test.pb.go57
1:1format
testpb/test.pb.go:1:1
// Code generated by protoc-gen-go.// source: test.proto- Fix (safe): run `strider fmt testpb/test.pb.go`
5:9filename-format
testpb/test.pb.go:5:9
package testpb5:9package-comments
testpb/test.pb.go:5:9
package testpb7:8redundant-import-alias
testpb/test.pb.go:7:8
import proto "github.com/golang/protobuf/proto"import json "encoding/json"7:14deprecated-api-usage
testpb/test.pb.go:7:14
import proto "github.com/golang/protobuf/proto"import json "encoding/json"8:8redundant-import-alias
testpb/test.pb.go:8:8
import proto "github.com/golang/protobuf/proto"import json "encoding/json"import math "math"9:8redundant-import-alias
testpb/test.pb.go:9:8
import json "encoding/json"import math "math"16:6exported-declaration-comment
testpb/test.pb.go:16:6
type TestMessage struct { Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`19:2var-naming
testpb/test.pb.go:19:2
City *string `protobuf:"bytes,2,opt,name=city" json:"city,omitempty"` XXX_unrecognized []byte `json:"-"`}22:23exported-declaration-comment
testpb/test.pb.go:22:23
func (m *TestMessage) Reset() { *m = TestMessage{} }func (m *TestMessage) String() string { return proto.CompactTextString(m) }24:21exported-declaration-comment
testpb/test.pb.go:24:21
func (m *TestMessage) String() string { return proto.CompactTextString(m) }func (*TestMessage) ProtoMessage() {}26:23exported-declaration-comment
testpb/test.pb.go:26:23
func (m *TestMessage) GetName() string { if m != nil && m.Name != nil {33:23exported-declaration-comment
testpb/test.pb.go:33:23
func (m *TestMessage) GetCity() string { if m != nil && m.City != nil {40:1top-level-declaration-order
testpb/test.pb.go:40:1
type TestRequest struct { Lower *string `protobuf:"bytes,1,req,name=lower" json:"lower,omitempty"`40:6exported-declaration-comment
testpb/test.pb.go:40:6
type TestRequest struct { Lower *string `protobuf:"bytes,1,req,name=lower" json:"lower,omitempty"`43:2var-naming
testpb/test.pb.go:43:2
RepeatCount *int32 `protobuf:"varint,2,opt,name=repeat_count,def=1" json:"repeat_count,omitempty"` XXX_unrecognized []byte `json:"-"`}46:23exported-declaration-comment
testpb/test.pb.go:46:23
func (m *TestRequest) Reset() { *m = TestRequest{} }func (m *TestRequest) String() string { return proto.CompactTextString(m) }48:21exported-declaration-comment
testpb/test.pb.go:48:21
func (m *TestRequest) String() string { return proto.CompactTextString(m) }func (*TestRequest) ProtoMessage() {}50:7exported-declaration-comment
testpb/test.pb.go:50:7
const Default_TestRequest_RepeatCount int32 = 150:7var-naming
testpb/test.pb.go:50:7
const Default_TestRequest_RepeatCount int32 = 152:23exported-declaration-comment
testpb/test.pb.go:52:23
func (m *TestRequest) GetLower() string { if m != nil && m.Lower != nil {59:23exported-declaration-comment
testpb/test.pb.go:59:23
func (m *TestRequest) GetRepeatCount() int32 { if m != nil && m.RepeatCount != nil {66:6exported-declaration-comment
testpb/test.pb.go:66:6
type TestResponse struct { Value *string `protobuf:"bytes,1,opt,name=value" json:"value,omitempty"`68:2var-naming
testpb/test.pb.go:68:2
Value *string `protobuf:"bytes,1,opt,name=value" json:"value,omitempty"` XXX_unrecognized []byte `json:"-"`}71:24exported-declaration-comment
testpb/test.pb.go:71:24
func (m *TestResponse) Reset() { *m = TestResponse{} }func (m *TestResponse) String() string { return proto.CompactTextString(m) }73:22exported-declaration-comment
testpb/test.pb.go:73:22
func (m *TestResponse) String() string { return proto.CompactTextString(m) }func (*TestResponse) ProtoMessage() {}75:24exported-declaration-comment
testpb/test.pb.go:75:24
func (m *TestResponse) GetValue() string { if m != nil && m.Value != nil {82:6exported-declaration-comment
testpb/test.pb.go:82:6
type CacheStats struct { Items *int64 `protobuf:"varint,1,opt,name=items" json:"items,omitempty"`88:2var-naming
testpb/test.pb.go:88:2
Evicts *int64 `protobuf:"varint,5,opt,name=evicts" json:"evicts,omitempty"` XXX_unrecognized []byte `json:"-"`}91:22exported-declaration-comment
testpb/test.pb.go:91:22
func (m *CacheStats) Reset() { *m = CacheStats{} }func (m *CacheStats) String() string { return proto.CompactTextString(m) }93:20exported-declaration-comment
testpb/test.pb.go:93:20
func (m *CacheStats) String() string { return proto.CompactTextString(m) }func (*CacheStats) ProtoMessage() {}95:22exported-declaration-comment
testpb/test.pb.go:95:22
func (m *CacheStats) GetItems() int64 { if m != nil && m.Items != nil {102:22exported-declaration-comment
testpb/test.pb.go:102:22
func (m *CacheStats) GetBytes() int64 { if m != nil && m.Bytes != nil {109:22exported-declaration-comment
testpb/test.pb.go:109:22
func (m *CacheStats) GetGets() int64 { if m != nil && m.Gets != nil {116:22exported-declaration-comment
testpb/test.pb.go:116:22
func (m *CacheStats) GetHits() int64 { if m != nil && m.Hits != nil {123:22exported-declaration-comment
testpb/test.pb.go:123:22
func (m *CacheStats) GetEvicts() int64 { if m != nil && m.Evicts != nil {130:6exported-declaration-comment
testpb/test.pb.go:130:6
type StatsResponse struct { Gets *int64 `protobuf:"varint,1,opt,name=gets" json:"gets,omitempty"`142:2var-naming
testpb/test.pb.go:142:2
LocalLoads *int64 `protobuf:"varint,11,opt,name=local_loads" json:"local_loads,omitempty"` XXX_unrecognized []byte `json:"-"`}145:25exported-declaration-comment
testpb/test.pb.go:145:25
func (m *StatsResponse) Reset() { *m = StatsResponse{} }func (m *StatsResponse) String() string { return proto.CompactTextString(m) }147:23exported-declaration-comment
testpb/test.pb.go:147:23
func (m *StatsResponse) String() string { return proto.CompactTextString(m) }func (*StatsResponse) ProtoMessage() {}149:25exported-declaration-comment
testpb/test.pb.go:149:25
func (m *StatsResponse) GetGets() int64 { if m != nil && m.Gets != nil {156:25exported-declaration-comment
testpb/test.pb.go:156:25
func (m *StatsResponse) GetCacheHits() int64 { if m != nil && m.CacheHits != nil {163:25exported-declaration-comment
testpb/test.pb.go:163:25
func (m *StatsResponse) GetFills() int64 { if m != nil && m.Fills != nil {170:25exported-declaration-comment
testpb/test.pb.go:170:25
func (m *StatsResponse) GetTotalAlloc() uint64 { if m != nil && m.TotalAlloc != nil {177:25exported-declaration-comment
testpb/test.pb.go:177:25
func (m *StatsResponse) GetMainCache() *CacheStats { if m != nil {184:25exported-declaration-comment
testpb/test.pb.go:184:25
func (m *StatsResponse) GetHotCache() *CacheStats { if m != nil {191:25exported-declaration-comment
testpb/test.pb.go:191:25
func (m *StatsResponse) GetServerIn() int64 { if m != nil && m.ServerIn != nil {198:25exported-declaration-comment
testpb/test.pb.go:198:25
func (m *StatsResponse) GetLoads() int64 { if m != nil && m.Loads != nil {205:25exported-declaration-comment
testpb/test.pb.go:205:25
func (m *StatsResponse) GetPeerLoads() int64 { if m != nil && m.PeerLoads != nil {212:25exported-declaration-comment
testpb/test.pb.go:212:25
func (m *StatsResponse) GetPeerErrors() int64 { if m != nil && m.PeerErrors != nil {219:25exported-declaration-comment
testpb/test.pb.go:219:25
func (m *StatsResponse) GetLocalLoads() int64 { if m != nil && m.LocalLoads != nil {226:6exported-declaration-comment
testpb/test.pb.go:226:6
type Empty struct { XXX_unrecognized []byte `json:"-"`226:6max-public-structs
testpb/test.pb.go:226:6
type Empty struct { XXX_unrecognized []byte `json:"-"`227:2var-naming
testpb/test.pb.go:227:2
type Empty struct { XXX_unrecognized []byte `json:"-"`}230:17exported-declaration-comment
testpb/test.pb.go:230:17
func (m *Empty) Reset() { *m = Empty{} }func (m *Empty) String() string { return proto.CompactTextString(m) }232:15exported-declaration-comment
testpb/test.pb.go:232:15
func (m *Empty) String() string { return proto.CompactTextString(m) }func (*Empty) ProtoMessage() {}234:6no-init
testpb/test.pb.go:234:6
func init() {}