Switch to go modules
This commit is contained in:
parent
461954facb
commit
1720059244
763 changed files with 24896 additions and 177398 deletions
1
vendor/github.com/golang/groupcache/.gitignore
generated
vendored
1
vendor/github.com/golang/groupcache/.gitignore
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
*~
|
||||
19
vendor/github.com/golang/groupcache/.travis.yml
generated
vendored
19
vendor/github.com/golang/groupcache/.travis.yml
generated
vendored
|
|
@ -1,19 +0,0 @@
|
|||
language: go
|
||||
go_import_path: github.com/golang/groupcache
|
||||
|
||||
os: linux
|
||||
dist: trusty
|
||||
sudo: false
|
||||
|
||||
script:
|
||||
- go test ./...
|
||||
|
||||
go:
|
||||
- 1.9.x
|
||||
- 1.10.x
|
||||
- 1.11.x
|
||||
- master
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $GOPATH/pkg
|
||||
73
vendor/github.com/golang/groupcache/README.md
generated
vendored
73
vendor/github.com/golang/groupcache/README.md
generated
vendored
|
|
@ -1,73 +0,0 @@
|
|||
# groupcache
|
||||
|
||||
## Summary
|
||||
|
||||
groupcache is a caching and cache-filling library, intended as a
|
||||
replacement for memcached in many cases.
|
||||
|
||||
For API docs and examples, see http://godoc.org/github.com/golang/groupcache
|
||||
|
||||
## Comparison to memcached
|
||||
|
||||
### **Like memcached**, groupcache:
|
||||
|
||||
* shards by key to select which peer is responsible for that key
|
||||
|
||||
### **Unlike memcached**, groupcache:
|
||||
|
||||
* does not require running a separate set of servers, thus massively
|
||||
reducing deployment/configuration pain. groupcache is a client
|
||||
library as well as a server. It connects to its own peers.
|
||||
|
||||
* comes with a cache filling mechanism. Whereas memcached just says
|
||||
"Sorry, cache miss", often resulting in a thundering herd of
|
||||
database (or whatever) loads from an unbounded number of clients
|
||||
(which has resulted in several fun outages), groupcache coordinates
|
||||
cache fills such that only one load in one process of an entire
|
||||
replicated set of processes populates the cache, then multiplexes
|
||||
the loaded value to all callers.
|
||||
|
||||
* does not support versioned values. If key "foo" is value "bar",
|
||||
key "foo" must always be "bar". There are neither cache expiration
|
||||
times, nor explicit cache evictions. Thus there is also no CAS,
|
||||
nor Increment/Decrement. This also means that groupcache....
|
||||
|
||||
* ... supports automatic mirroring of super-hot items to multiple
|
||||
processes. This prevents memcached hot spotting where a machine's
|
||||
CPU and/or NIC are overloaded by very popular keys/values.
|
||||
|
||||
* is currently only available for Go. It's very unlikely that I
|
||||
(bradfitz@) will port the code to any other language.
|
||||
|
||||
## Loading process
|
||||
|
||||
In a nutshell, a groupcache lookup of **Get("foo")** looks like:
|
||||
|
||||
(On machine #5 of a set of N machines running the same code)
|
||||
|
||||
1. Is the value of "foo" in local memory because it's super hot? If so, use it.
|
||||
|
||||
2. Is the value of "foo" in local memory because peer #5 (the current
|
||||
peer) is the owner of it? If so, use it.
|
||||
|
||||
3. Amongst all the peers in my set of N, am I the owner of the key
|
||||
"foo"? (e.g. does it consistent hash to 5?) If so, load it. If
|
||||
other callers come in, via the same process or via RPC requests
|
||||
from peers, they block waiting for the load to finish and get the
|
||||
same answer. If not, RPC to the peer that's the owner and get
|
||||
the answer. If the RPC fails, just load it locally (still with
|
||||
local dup suppression).
|
||||
|
||||
## Users
|
||||
|
||||
groupcache is in production use by dl.google.com (its original user),
|
||||
parts of Blogger, parts of Google Code, parts of Google Fiber, parts
|
||||
of Google production monitoring systems, etc.
|
||||
|
||||
## Presentations
|
||||
|
||||
See http://talks.golang.org/2013/oscon-dl.slide
|
||||
|
||||
## Help
|
||||
|
||||
Use the golang-nuts mailing list for any discussion or questions.
|
||||
175
vendor/github.com/golang/groupcache/byteview.go
generated
vendored
175
vendor/github.com/golang/groupcache/byteview.go
generated
vendored
|
|
@ -1,175 +0,0 @@
|
|||
/*
|
||||
Copyright 2012 Google Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package groupcache
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// A ByteView holds an immutable view of bytes.
|
||||
// Internally it wraps either a []byte or a string,
|
||||
// but that detail is invisible to callers.
|
||||
//
|
||||
// A ByteView is meant to be used as a value type, not
|
||||
// a pointer (like a time.Time).
|
||||
type ByteView struct {
|
||||
// If b is non-nil, b is used, else s is used.
|
||||
b []byte
|
||||
s string
|
||||
}
|
||||
|
||||
// Len returns the view's length.
|
||||
func (v ByteView) Len() int {
|
||||
if v.b != nil {
|
||||
return len(v.b)
|
||||
}
|
||||
return len(v.s)
|
||||
}
|
||||
|
||||
// ByteSlice returns a copy of the data as a byte slice.
|
||||
func (v ByteView) ByteSlice() []byte {
|
||||
if v.b != nil {
|
||||
return cloneBytes(v.b)
|
||||
}
|
||||
return []byte(v.s)
|
||||
}
|
||||
|
||||
// String returns the data as a string, making a copy if necessary.
|
||||
func (v ByteView) String() string {
|
||||
if v.b != nil {
|
||||
return string(v.b)
|
||||
}
|
||||
return v.s
|
||||
}
|
||||
|
||||
// At returns the byte at index i.
|
||||
func (v ByteView) At(i int) byte {
|
||||
if v.b != nil {
|
||||
return v.b[i]
|
||||
}
|
||||
return v.s[i]
|
||||
}
|
||||
|
||||
// Slice slices the view between the provided from and to indices.
|
||||
func (v ByteView) Slice(from, to int) ByteView {
|
||||
if v.b != nil {
|
||||
return ByteView{b: v.b[from:to]}
|
||||
}
|
||||
return ByteView{s: v.s[from:to]}
|
||||
}
|
||||
|
||||
// SliceFrom slices the view from the provided index until the end.
|
||||
func (v ByteView) SliceFrom(from int) ByteView {
|
||||
if v.b != nil {
|
||||
return ByteView{b: v.b[from:]}
|
||||
}
|
||||
return ByteView{s: v.s[from:]}
|
||||
}
|
||||
|
||||
// Copy copies b into dest and returns the number of bytes copied.
|
||||
func (v ByteView) Copy(dest []byte) int {
|
||||
if v.b != nil {
|
||||
return copy(dest, v.b)
|
||||
}
|
||||
return copy(dest, v.s)
|
||||
}
|
||||
|
||||
// Equal returns whether the bytes in b are the same as the bytes in
|
||||
// b2.
|
||||
func (v ByteView) Equal(b2 ByteView) bool {
|
||||
if b2.b == nil {
|
||||
return v.EqualString(b2.s)
|
||||
}
|
||||
return v.EqualBytes(b2.b)
|
||||
}
|
||||
|
||||
// EqualString returns whether the bytes in b are the same as the bytes
|
||||
// in s.
|
||||
func (v ByteView) EqualString(s string) bool {
|
||||
if v.b == nil {
|
||||
return v.s == s
|
||||
}
|
||||
l := v.Len()
|
||||
if len(s) != l {
|
||||
return false
|
||||
}
|
||||
for i, bi := range v.b {
|
||||
if bi != s[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// EqualBytes returns whether the bytes in b are the same as the bytes
|
||||
// in b2.
|
||||
func (v ByteView) EqualBytes(b2 []byte) bool {
|
||||
if v.b != nil {
|
||||
return bytes.Equal(v.b, b2)
|
||||
}
|
||||
l := v.Len()
|
||||
if len(b2) != l {
|
||||
return false
|
||||
}
|
||||
for i, bi := range b2 {
|
||||
if bi != v.s[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Reader returns an io.ReadSeeker for the bytes in v.
|
||||
func (v ByteView) Reader() io.ReadSeeker {
|
||||
if v.b != nil {
|
||||
return bytes.NewReader(v.b)
|
||||
}
|
||||
return strings.NewReader(v.s)
|
||||
}
|
||||
|
||||
// ReadAt implements io.ReaderAt on the bytes in v.
|
||||
func (v ByteView) ReadAt(p []byte, off int64) (n int, err error) {
|
||||
if off < 0 {
|
||||
return 0, errors.New("view: invalid offset")
|
||||
}
|
||||
if off >= int64(v.Len()) {
|
||||
return 0, io.EOF
|
||||
}
|
||||
n = v.SliceFrom(int(off)).Copy(p)
|
||||
if n < len(p) {
|
||||
err = io.EOF
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// WriteTo implements io.WriterTo on the bytes in v.
|
||||
func (v ByteView) WriteTo(w io.Writer) (n int64, err error) {
|
||||
var m int
|
||||
if v.b != nil {
|
||||
m, err = w.Write(v.b)
|
||||
} else {
|
||||
m, err = io.WriteString(w, v.s)
|
||||
}
|
||||
if err == nil && m < v.Len() {
|
||||
err = io.ErrShortWrite
|
||||
}
|
||||
n = int64(m)
|
||||
return
|
||||
}
|
||||
491
vendor/github.com/golang/groupcache/groupcache.go
generated
vendored
491
vendor/github.com/golang/groupcache/groupcache.go
generated
vendored
|
|
@ -1,491 +0,0 @@
|
|||
/*
|
||||
Copyright 2012 Google Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package groupcache provides a data loading mechanism with caching
|
||||
// and de-duplication that works across a set of peer processes.
|
||||
//
|
||||
// Each data Get first consults its local cache, otherwise delegates
|
||||
// to the requested key's canonical owner, which then checks its cache
|
||||
// or finally gets the data. In the common case, many concurrent
|
||||
// cache misses across a set of peers for the same key result in just
|
||||
// one cache fill.
|
||||
package groupcache
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
pb "github.com/golang/groupcache/groupcachepb"
|
||||
"github.com/golang/groupcache/lru"
|
||||
"github.com/golang/groupcache/singleflight"
|
||||
)
|
||||
|
||||
// A Getter loads data for a key.
|
||||
type Getter interface {
|
||||
// Get returns the value identified by key, populating dest.
|
||||
//
|
||||
// The returned data must be unversioned. That is, key must
|
||||
// uniquely describe the loaded data, without an implicit
|
||||
// current time, and without relying on cache expiration
|
||||
// mechanisms.
|
||||
Get(ctx Context, key string, dest Sink) error
|
||||
}
|
||||
|
||||
// A GetterFunc implements Getter with a function.
|
||||
type GetterFunc func(ctx Context, key string, dest Sink) error
|
||||
|
||||
func (f GetterFunc) Get(ctx Context, key string, dest Sink) error {
|
||||
return f(ctx, key, dest)
|
||||
}
|
||||
|
||||
var (
|
||||
mu sync.RWMutex
|
||||
groups = make(map[string]*Group)
|
||||
|
||||
initPeerServerOnce sync.Once
|
||||
initPeerServer func()
|
||||
)
|
||||
|
||||
// GetGroup returns the named group previously created with NewGroup, or
|
||||
// nil if there's no such group.
|
||||
func GetGroup(name string) *Group {
|
||||
mu.RLock()
|
||||
g := groups[name]
|
||||
mu.RUnlock()
|
||||
return g
|
||||
}
|
||||
|
||||
// NewGroup creates a coordinated group-aware Getter from a Getter.
|
||||
//
|
||||
// The returned Getter tries (but does not guarantee) to run only one
|
||||
// Get call at once for a given key across an entire set of peer
|
||||
// processes. Concurrent callers both in the local process and in
|
||||
// other processes receive copies of the answer once the original Get
|
||||
// completes.
|
||||
//
|
||||
// The group name must be unique for each getter.
|
||||
func NewGroup(name string, cacheBytes int64, getter Getter) *Group {
|
||||
return newGroup(name, cacheBytes, getter, nil)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
panic("nil Getter")
|
||||
}
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
initPeerServerOnce.Do(callInitPeerServer)
|
||||
if _, dup := groups[name]; dup {
|
||||
panic("duplicate registration of group " + name)
|
||||
}
|
||||
g := &Group{
|
||||
name: name,
|
||||
getter: getter,
|
||||
peers: peers,
|
||||
cacheBytes: cacheBytes,
|
||||
loadGroup: &singleflight.Group{},
|
||||
}
|
||||
if fn := newGroupHook; fn != nil {
|
||||
fn(g)
|
||||
}
|
||||
groups[name] = g
|
||||
return g
|
||||
}
|
||||
|
||||
// newGroupHook, if non-nil, is called right after a new group is created.
|
||||
var newGroupHook func(*Group)
|
||||
|
||||
// RegisterNewGroupHook registers a hook that is run each time
|
||||
// a group is created.
|
||||
func RegisterNewGroupHook(fn func(*Group)) {
|
||||
if newGroupHook != nil {
|
||||
panic("RegisterNewGroupHook called more than once")
|
||||
}
|
||||
newGroupHook = fn
|
||||
}
|
||||
|
||||
// RegisterServerStart registers a hook that is run when the first
|
||||
// group is created.
|
||||
func RegisterServerStart(fn func()) {
|
||||
if initPeerServer != nil {
|
||||
panic("RegisterServerStart called more than once")
|
||||
}
|
||||
initPeerServer = fn
|
||||
}
|
||||
|
||||
func callInitPeerServer() {
|
||||
if initPeerServer != nil {
|
||||
initPeerServer()
|
||||
}
|
||||
}
|
||||
|
||||
// A Group is a cache namespace and associated data loaded spread over
|
||||
// a group of 1 or more machines.
|
||||
type Group struct {
|
||||
name string
|
||||
getter Getter
|
||||
peersOnce sync.Once
|
||||
peers PeerPicker
|
||||
cacheBytes int64 // limit for sum of mainCache and hotCache size
|
||||
|
||||
// mainCache is a cache of the keys for which this process
|
||||
// (amongst its peers) is authoritative. That is, this cache
|
||||
// contains keys which consistent hash on to this process's
|
||||
// peer number.
|
||||
mainCache cache
|
||||
|
||||
// hotCache contains keys/values for which this peer is not
|
||||
// authoritative (otherwise they would be in mainCache), but
|
||||
// are popular enough to warrant mirroring in this process to
|
||||
// avoid going over the network to fetch from a peer. Having
|
||||
// a hotCache avoids network hotspotting, where a peer's
|
||||
// network card could become the bottleneck on a popular key.
|
||||
// This cache is used sparingly to maximize the total number
|
||||
// of key/value pairs that can be stored globally.
|
||||
hotCache cache
|
||||
|
||||
// loadGroup ensures that each key is only fetched once
|
||||
// (either locally or remotely), regardless of the number of
|
||||
// concurrent callers.
|
||||
loadGroup flightGroup
|
||||
|
||||
_ int32 // force Stats to be 8-byte aligned on 32-bit platforms
|
||||
|
||||
// Stats are statistics on the group.
|
||||
Stats Stats
|
||||
}
|
||||
|
||||
// flightGroup is defined as an interface which flightgroup.Group
|
||||
// satisfies. We define this so that we may test with an alternate
|
||||
// implementation.
|
||||
type flightGroup interface {
|
||||
// Done is called when Do is done.
|
||||
Do(key string, fn func() (interface{}, error)) (interface{}, error)
|
||||
}
|
||||
|
||||
// Stats are per-group statistics.
|
||||
type Stats struct {
|
||||
Gets AtomicInt // any Get request, including from peers
|
||||
CacheHits AtomicInt // either cache was good
|
||||
PeerLoads AtomicInt // either remote load or remote cache hit (not an error)
|
||||
PeerErrors AtomicInt
|
||||
Loads AtomicInt // (gets - cacheHits)
|
||||
LoadsDeduped AtomicInt // after singleflight
|
||||
LocalLoads AtomicInt // total good local loads
|
||||
LocalLoadErrs AtomicInt // total bad local loads
|
||||
ServerRequests AtomicInt // gets that came over the network from peers
|
||||
}
|
||||
|
||||
// Name returns the name of the group.
|
||||
func (g *Group) Name() string {
|
||||
return g.name
|
||||
}
|
||||
|
||||
func (g *Group) initPeers() {
|
||||
if g.peers == nil {
|
||||
g.peers = getPeers(g.name)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Group) Get(ctx Context, key string, dest Sink) error {
|
||||
g.peersOnce.Do(g.initPeers)
|
||||
g.Stats.Gets.Add(1)
|
||||
if dest == nil {
|
||||
return errors.New("groupcache: nil dest Sink")
|
||||
}
|
||||
value, cacheHit := g.lookupCache(key)
|
||||
|
||||
if cacheHit {
|
||||
g.Stats.CacheHits.Add(1)
|
||||
return setSinkView(dest, value)
|
||||
}
|
||||
|
||||
// Optimization to avoid double unmarshalling or copying: keep
|
||||
// track of whether the dest was already populated. One caller
|
||||
// (if local) will set this; the losers will not. The common
|
||||
// case will likely be one caller.
|
||||
destPopulated := false
|
||||
value, destPopulated, err := g.load(ctx, key, dest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if destPopulated {
|
||||
return nil
|
||||
}
|
||||
return setSinkView(dest, value)
|
||||
}
|
||||
|
||||
// load loads key either by invoking the getter locally or by sending it to another machine.
|
||||
func (g *Group) load(ctx Context, key string, dest Sink) (value ByteView, destPopulated bool, err error) {
|
||||
g.Stats.Loads.Add(1)
|
||||
viewi, err := g.loadGroup.Do(key, func() (interface{}, error) {
|
||||
// Check the cache again because singleflight can only dedup calls
|
||||
// that overlap concurrently. It's possible for 2 concurrent
|
||||
// requests to miss the cache, resulting in 2 load() calls. An
|
||||
// unfortunate goroutine scheduling would result in this callback
|
||||
// being run twice, serially. If we don't check the cache again,
|
||||
// cache.nbytes would be incremented below even though there will
|
||||
// be only one entry for this key.
|
||||
//
|
||||
// Consider the following serialized event ordering for two
|
||||
// goroutines in which this callback gets called twice for hte
|
||||
// same key:
|
||||
// 1: Get("key")
|
||||
// 2: Get("key")
|
||||
// 1: lookupCache("key")
|
||||
// 2: lookupCache("key")
|
||||
// 1: load("key")
|
||||
// 2: load("key")
|
||||
// 1: loadGroup.Do("key", fn)
|
||||
// 1: fn()
|
||||
// 2: loadGroup.Do("key", fn)
|
||||
// 2: fn()
|
||||
if value, cacheHit := g.lookupCache(key); cacheHit {
|
||||
g.Stats.CacheHits.Add(1)
|
||||
return value, nil
|
||||
}
|
||||
g.Stats.LoadsDeduped.Add(1)
|
||||
var value ByteView
|
||||
var err error
|
||||
if peer, ok := g.peers.PickPeer(key); ok {
|
||||
value, err = g.getFromPeer(ctx, peer, key)
|
||||
if err == nil {
|
||||
g.Stats.PeerLoads.Add(1)
|
||||
return value, nil
|
||||
}
|
||||
g.Stats.PeerErrors.Add(1)
|
||||
// TODO(bradfitz): log the peer's error? keep
|
||||
// log of the past few for /groupcachez? It's
|
||||
// probably boring (normal task movement), so not
|
||||
// worth logging I imagine.
|
||||
}
|
||||
value, err = g.getLocally(ctx, key, dest)
|
||||
if err != nil {
|
||||
g.Stats.LocalLoadErrs.Add(1)
|
||||
return nil, err
|
||||
}
|
||||
g.Stats.LocalLoads.Add(1)
|
||||
destPopulated = true // only one caller of load gets this return value
|
||||
g.populateCache(key, value, &g.mainCache)
|
||||
return value, nil
|
||||
})
|
||||
if err == nil {
|
||||
value = viewi.(ByteView)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (g *Group) getLocally(ctx Context, key string, dest Sink) (ByteView, error) {
|
||||
err := g.getter.Get(ctx, key, dest)
|
||||
if err != nil {
|
||||
return ByteView{}, err
|
||||
}
|
||||
return dest.view()
|
||||
}
|
||||
|
||||
func (g *Group) getFromPeer(ctx Context, peer ProtoGetter, key string) (ByteView, error) {
|
||||
req := &pb.GetRequest{
|
||||
Group: &g.name,
|
||||
Key: &key,
|
||||
}
|
||||
res := &pb.GetResponse{}
|
||||
err := peer.Get(ctx, req, res)
|
||||
if err != nil {
|
||||
return ByteView{}, err
|
||||
}
|
||||
value := ByteView{b: res.Value}
|
||||
// TODO(bradfitz): use res.MinuteQps or something smart to
|
||||
// conditionally populate hotCache. For now just do it some
|
||||
// percentage of the time.
|
||||
if rand.Intn(10) == 0 {
|
||||
g.populateCache(key, value, &g.hotCache)
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (g *Group) lookupCache(key string) (value ByteView, ok bool) {
|
||||
if g.cacheBytes <= 0 {
|
||||
return
|
||||
}
|
||||
value, ok = g.mainCache.get(key)
|
||||
if ok {
|
||||
return
|
||||
}
|
||||
value, ok = g.hotCache.get(key)
|
||||
return
|
||||
}
|
||||
|
||||
func (g *Group) populateCache(key string, value ByteView, cache *cache) {
|
||||
if g.cacheBytes <= 0 {
|
||||
return
|
||||
}
|
||||
cache.add(key, value)
|
||||
|
||||
// Evict items from cache(s) if necessary.
|
||||
for {
|
||||
mainBytes := g.mainCache.bytes()
|
||||
hotBytes := g.hotCache.bytes()
|
||||
if mainBytes+hotBytes <= g.cacheBytes {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO(bradfitz): this is good-enough-for-now logic.
|
||||
// It should be something based on measurements and/or
|
||||
// respecting the costs of different resources.
|
||||
victim := &g.mainCache
|
||||
if hotBytes > mainBytes/8 {
|
||||
victim = &g.hotCache
|
||||
}
|
||||
victim.removeOldest()
|
||||
}
|
||||
}
|
||||
|
||||
// CacheType represents a type of cache.
|
||||
type CacheType int
|
||||
|
||||
const (
|
||||
// The MainCache is the cache for items that this peer is the
|
||||
// owner for.
|
||||
MainCache CacheType = iota + 1
|
||||
|
||||
// The HotCache is the cache for items that seem popular
|
||||
// enough to replicate to this node, even though it's not the
|
||||
// owner.
|
||||
HotCache
|
||||
)
|
||||
|
||||
// CacheStats returns stats about the provided cache within the group.
|
||||
func (g *Group) CacheStats(which CacheType) CacheStats {
|
||||
switch which {
|
||||
case MainCache:
|
||||
return g.mainCache.stats()
|
||||
case HotCache:
|
||||
return g.hotCache.stats()
|
||||
default:
|
||||
return CacheStats{}
|
||||
}
|
||||
}
|
||||
|
||||
// cache is a wrapper around an *lru.Cache that adds synchronization,
|
||||
// makes values always be ByteView, and counts the size of all keys and
|
||||
// values.
|
||||
type cache struct {
|
||||
mu sync.RWMutex
|
||||
nbytes int64 // of all keys and values
|
||||
lru *lru.Cache
|
||||
nhit, nget int64
|
||||
nevict int64 // number of evictions
|
||||
}
|
||||
|
||||
func (c *cache) stats() CacheStats {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
return CacheStats{
|
||||
Bytes: c.nbytes,
|
||||
Items: c.itemsLocked(),
|
||||
Gets: c.nget,
|
||||
Hits: c.nhit,
|
||||
Evictions: c.nevict,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *cache) add(key string, value ByteView) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if c.lru == nil {
|
||||
c.lru = &lru.Cache{
|
||||
OnEvicted: func(key lru.Key, value interface{}) {
|
||||
val := value.(ByteView)
|
||||
c.nbytes -= int64(len(key.(string))) + int64(val.Len())
|
||||
c.nevict++
|
||||
},
|
||||
}
|
||||
}
|
||||
c.lru.Add(key, value)
|
||||
c.nbytes += int64(len(key)) + int64(value.Len())
|
||||
}
|
||||
|
||||
func (c *cache) get(key string) (value ByteView, ok bool) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.nget++
|
||||
if c.lru == nil {
|
||||
return
|
||||
}
|
||||
vi, ok := c.lru.Get(key)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
c.nhit++
|
||||
return vi.(ByteView), true
|
||||
}
|
||||
|
||||
func (c *cache) removeOldest() {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if c.lru != nil {
|
||||
c.lru.RemoveOldest()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *cache) bytes() int64 {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
return c.nbytes
|
||||
}
|
||||
|
||||
func (c *cache) items() int64 {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
return c.itemsLocked()
|
||||
}
|
||||
|
||||
func (c *cache) itemsLocked() int64 {
|
||||
if c.lru == nil {
|
||||
return 0
|
||||
}
|
||||
return int64(c.lru.Len())
|
||||
}
|
||||
|
||||
// An AtomicInt is an int64 to be accessed atomically.
|
||||
type AtomicInt int64
|
||||
|
||||
// Add atomically adds n to i.
|
||||
func (i *AtomicInt) Add(n int64) {
|
||||
atomic.AddInt64((*int64)(i), n)
|
||||
}
|
||||
|
||||
// Get atomically gets the value of i.
|
||||
func (i *AtomicInt) Get() int64 {
|
||||
return atomic.LoadInt64((*int64)(i))
|
||||
}
|
||||
|
||||
func (i *AtomicInt) String() string {
|
||||
return strconv.FormatInt(i.Get(), 10)
|
||||
}
|
||||
|
||||
// CacheStats are returned by stats accessors on Group.
|
||||
type CacheStats struct {
|
||||
Bytes int64
|
||||
Items int64
|
||||
Gets int64
|
||||
Hits int64
|
||||
Evictions int64
|
||||
}
|
||||
227
vendor/github.com/golang/groupcache/http.go
generated
vendored
227
vendor/github.com/golang/groupcache/http.go
generated
vendored
|
|
@ -1,227 +0,0 @@
|
|||
/*
|
||||
Copyright 2013 Google Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package groupcache
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/golang/groupcache/consistenthash"
|
||||
pb "github.com/golang/groupcache/groupcachepb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
const defaultBasePath = "/_groupcache/"
|
||||
|
||||
const defaultReplicas = 50
|
||||
|
||||
// HTTPPool implements PeerPicker for a pool of HTTP peers.
|
||||
type HTTPPool struct {
|
||||
// Context optionally specifies a context for the server to use when it
|
||||
// receives a request.
|
||||
// If nil, the server uses a nil Context.
|
||||
Context func(*http.Request) Context
|
||||
|
||||
// Transport optionally specifies an http.RoundTripper for the client
|
||||
// to use when it makes a request.
|
||||
// If nil, the client uses http.DefaultTransport.
|
||||
Transport func(Context) http.RoundTripper
|
||||
|
||||
// this peer's base URL, e.g. "https://example.net:8000"
|
||||
self string
|
||||
|
||||
// opts specifies the options.
|
||||
opts HTTPPoolOptions
|
||||
|
||||
mu sync.Mutex // guards peers and httpGetters
|
||||
peers *consistenthash.Map
|
||||
httpGetters map[string]*httpGetter // keyed by e.g. "http://10.0.0.2:8008"
|
||||
}
|
||||
|
||||
// HTTPPoolOptions are the configurations of a HTTPPool.
|
||||
type HTTPPoolOptions struct {
|
||||
// BasePath specifies the HTTP path that will serve groupcache requests.
|
||||
// If blank, it defaults to "/_groupcache/".
|
||||
BasePath string
|
||||
|
||||
// Replicas specifies the number of key replicas on the consistent hash.
|
||||
// If blank, it defaults to 50.
|
||||
Replicas int
|
||||
|
||||
// HashFn specifies the hash function of the consistent hash.
|
||||
// If blank, it defaults to crc32.ChecksumIEEE.
|
||||
HashFn consistenthash.Hash
|
||||
}
|
||||
|
||||
// NewHTTPPool initializes an HTTP pool of peers, and registers itself as a PeerPicker.
|
||||
// For convenience, it also registers itself as an http.Handler with http.DefaultServeMux.
|
||||
// The self argument should be a valid base URL that points to the current server,
|
||||
// for example "http://example.net:8000".
|
||||
func NewHTTPPool(self string) *HTTPPool {
|
||||
p := NewHTTPPoolOpts(self, nil)
|
||||
http.Handle(p.opts.BasePath, p)
|
||||
return p
|
||||
}
|
||||
|
||||
var httpPoolMade bool
|
||||
|
||||
// NewHTTPPoolOpts initializes an HTTP pool of peers with the given options.
|
||||
// Unlike NewHTTPPool, this function does not register the created pool as an HTTP handler.
|
||||
// The returned *HTTPPool implements http.Handler and must be registered using http.Handle.
|
||||
func NewHTTPPoolOpts(self string, o *HTTPPoolOptions) *HTTPPool {
|
||||
if httpPoolMade {
|
||||
panic("groupcache: NewHTTPPool must be called only once")
|
||||
}
|
||||
httpPoolMade = true
|
||||
|
||||
p := &HTTPPool{
|
||||
self: self,
|
||||
httpGetters: make(map[string]*httpGetter),
|
||||
}
|
||||
if o != nil {
|
||||
p.opts = *o
|
||||
}
|
||||
if p.opts.BasePath == "" {
|
||||
p.opts.BasePath = defaultBasePath
|
||||
}
|
||||
if p.opts.Replicas == 0 {
|
||||
p.opts.Replicas = defaultReplicas
|
||||
}
|
||||
p.peers = consistenthash.New(p.opts.Replicas, p.opts.HashFn)
|
||||
|
||||
RegisterPeerPicker(func() PeerPicker { return p })
|
||||
return p
|
||||
}
|
||||
|
||||
// Set updates the pool's list of peers.
|
||||
// Each peer value should be a valid base URL,
|
||||
// for example "http://example.net:8000".
|
||||
func (p *HTTPPool) Set(peers ...string) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
p.peers = consistenthash.New(p.opts.Replicas, p.opts.HashFn)
|
||||
p.peers.Add(peers...)
|
||||
p.httpGetters = make(map[string]*httpGetter, len(peers))
|
||||
for _, peer := range peers {
|
||||
p.httpGetters[peer] = &httpGetter{transport: p.Transport, baseURL: peer + p.opts.BasePath}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *HTTPPool) PickPeer(key string) (ProtoGetter, bool) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
if p.peers.IsEmpty() {
|
||||
return nil, false
|
||||
}
|
||||
if peer := p.peers.Get(key); peer != p.self {
|
||||
return p.httpGetters[peer], true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (p *HTTPPool) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// Parse request.
|
||||
if !strings.HasPrefix(r.URL.Path, p.opts.BasePath) {
|
||||
panic("HTTPPool serving unexpected path: " + r.URL.Path)
|
||||
}
|
||||
parts := strings.SplitN(r.URL.Path[len(p.opts.BasePath):], "/", 2)
|
||||
if len(parts) != 2 {
|
||||
http.Error(w, "bad request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
groupName := parts[0]
|
||||
key := parts[1]
|
||||
|
||||
// Fetch the value for this group/key.
|
||||
group := GetGroup(groupName)
|
||||
if group == nil {
|
||||
http.Error(w, "no such group: "+groupName, http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
var ctx Context
|
||||
if p.Context != nil {
|
||||
ctx = p.Context(r)
|
||||
}
|
||||
|
||||
group.Stats.ServerRequests.Add(1)
|
||||
var value []byte
|
||||
err := group.Get(ctx, key, AllocatingByteSliceSink(&value))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Write the value to the response body as a proto message.
|
||||
body, err := proto.Marshal(&pb.GetResponse{Value: value})
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/x-protobuf")
|
||||
w.Write(body)
|
||||
}
|
||||
|
||||
type httpGetter struct {
|
||||
transport func(Context) http.RoundTripper
|
||||
baseURL string
|
||||
}
|
||||
|
||||
var bufferPool = sync.Pool{
|
||||
New: func() interface{} { return new(bytes.Buffer) },
|
||||
}
|
||||
|
||||
func (h *httpGetter) Get(context Context, in *pb.GetRequest, out *pb.GetResponse) error {
|
||||
u := fmt.Sprintf(
|
||||
"%v%v/%v",
|
||||
h.baseURL,
|
||||
url.QueryEscape(in.GetGroup()),
|
||||
url.QueryEscape(in.GetKey()),
|
||||
)
|
||||
req, err := http.NewRequest("GET", u, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tr := http.DefaultTransport
|
||||
if h.transport != nil {
|
||||
tr = h.transport(context)
|
||||
}
|
||||
res, err := tr.RoundTrip(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("server returned: %v", res.Status)
|
||||
}
|
||||
b := bufferPool.Get().(*bytes.Buffer)
|
||||
b.Reset()
|
||||
defer bufferPool.Put(b)
|
||||
_, err = io.Copy(b, res.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading response body: %v", err)
|
||||
}
|
||||
err = proto.Unmarshal(b.Bytes(), out)
|
||||
if err != nil {
|
||||
return fmt.Errorf("decoding response body: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
85
vendor/github.com/golang/groupcache/peers.go
generated
vendored
85
vendor/github.com/golang/groupcache/peers.go
generated
vendored
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
Copyright 2012 Google Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// peers.go defines how processes find and communicate with their peers.
|
||||
|
||||
package groupcache
|
||||
|
||||
import (
|
||||
pb "github.com/golang/groupcache/groupcachepb"
|
||||
)
|
||||
|
||||
// Context is an opaque value passed through calls to the
|
||||
// ProtoGetter. It may be nil if your ProtoGetter implementation does
|
||||
// not require a context.
|
||||
type Context interface{}
|
||||
|
||||
// ProtoGetter is the interface that must be implemented by a peer.
|
||||
type ProtoGetter interface {
|
||||
Get(context Context, in *pb.GetRequest, out *pb.GetResponse) error
|
||||
}
|
||||
|
||||
// PeerPicker is the interface that must be implemented to locate
|
||||
// the peer that owns a specific key.
|
||||
type PeerPicker interface {
|
||||
// PickPeer returns the peer that owns the specific key
|
||||
// and true to indicate that a remote peer was nominated.
|
||||
// It returns nil, false if the key owner is the current peer.
|
||||
PickPeer(key string) (peer ProtoGetter, ok bool)
|
||||
}
|
||||
|
||||
// NoPeers is an implementation of PeerPicker that never finds a peer.
|
||||
type NoPeers struct{}
|
||||
|
||||
func (NoPeers) PickPeer(key string) (peer ProtoGetter, ok bool) { return }
|
||||
|
||||
var (
|
||||
portPicker func(groupName string) PeerPicker
|
||||
)
|
||||
|
||||
// RegisterPeerPicker registers the peer initialization function.
|
||||
// It is called once, when the first group is created.
|
||||
// Either RegisterPeerPicker or RegisterPerGroupPeerPicker should be
|
||||
// called exactly once, but not both.
|
||||
func RegisterPeerPicker(fn func() PeerPicker) {
|
||||
if portPicker != nil {
|
||||
panic("RegisterPeerPicker called more than once")
|
||||
}
|
||||
portPicker = func(_ string) PeerPicker { return fn() }
|
||||
}
|
||||
|
||||
// RegisterPerGroupPeerPicker registers the peer initialization function,
|
||||
// which takes the groupName, to be used in choosing a PeerPicker.
|
||||
// It is called once, when the first group is created.
|
||||
// Either RegisterPeerPicker or RegisterPerGroupPeerPicker should be
|
||||
// called exactly once, but not both.
|
||||
func RegisterPerGroupPeerPicker(fn func(groupName string) PeerPicker) {
|
||||
if portPicker != nil {
|
||||
panic("RegisterPeerPicker called more than once")
|
||||
}
|
||||
portPicker = fn
|
||||
}
|
||||
|
||||
func getPeers(groupName string) PeerPicker {
|
||||
if portPicker == nil {
|
||||
return NoPeers{}
|
||||
}
|
||||
pk := portPicker(groupName)
|
||||
if pk == nil {
|
||||
pk = NoPeers{}
|
||||
}
|
||||
return pk
|
||||
}
|
||||
322
vendor/github.com/golang/groupcache/sinks.go
generated
vendored
322
vendor/github.com/golang/groupcache/sinks.go
generated
vendored
|
|
@ -1,322 +0,0 @@
|
|||
/*
|
||||
Copyright 2012 Google Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package groupcache
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
// A Sink receives data from a Get call.
|
||||
//
|
||||
// Implementation of Getter must call exactly one of the Set methods
|
||||
// on success.
|
||||
type Sink interface {
|
||||
// SetString sets the value to s.
|
||||
SetString(s string) error
|
||||
|
||||
// SetBytes sets the value to the contents of v.
|
||||
// The caller retains ownership of v.
|
||||
SetBytes(v []byte) error
|
||||
|
||||
// SetProto sets the value to the encoded version of m.
|
||||
// The caller retains ownership of m.
|
||||
SetProto(m proto.Message) error
|
||||
|
||||
// view returns a frozen view of the bytes for caching.
|
||||
view() (ByteView, error)
|
||||
}
|
||||
|
||||
func cloneBytes(b []byte) []byte {
|
||||
c := make([]byte, len(b))
|
||||
copy(c, b)
|
||||
return c
|
||||
}
|
||||
|
||||
func setSinkView(s Sink, v ByteView) error {
|
||||
// A viewSetter is a Sink that can also receive its value from
|
||||
// a ByteView. This is a fast path to minimize copies when the
|
||||
// item was already cached locally in memory (where it's
|
||||
// cached as a ByteView)
|
||||
type viewSetter interface {
|
||||
setView(v ByteView) error
|
||||
}
|
||||
if vs, ok := s.(viewSetter); ok {
|
||||
return vs.setView(v)
|
||||
}
|
||||
if v.b != nil {
|
||||
return s.SetBytes(v.b)
|
||||
}
|
||||
return s.SetString(v.s)
|
||||
}
|
||||
|
||||
// StringSink returns a Sink that populates the provided string pointer.
|
||||
func StringSink(sp *string) Sink {
|
||||
return &stringSink{sp: sp}
|
||||
}
|
||||
|
||||
type stringSink struct {
|
||||
sp *string
|
||||
v ByteView
|
||||
// TODO(bradfitz): track whether any Sets were called.
|
||||
}
|
||||
|
||||
func (s *stringSink) view() (ByteView, error) {
|
||||
// TODO(bradfitz): return an error if no Set was called
|
||||
return s.v, nil
|
||||
}
|
||||
|
||||
func (s *stringSink) SetString(v string) error {
|
||||
s.v.b = nil
|
||||
s.v.s = v
|
||||
*s.sp = v
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *stringSink) SetBytes(v []byte) error {
|
||||
return s.SetString(string(v))
|
||||
}
|
||||
|
||||
func (s *stringSink) SetProto(m proto.Message) error {
|
||||
b, err := proto.Marshal(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.v.b = b
|
||||
*s.sp = string(b)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ByteViewSink returns a Sink that populates a ByteView.
|
||||
func ByteViewSink(dst *ByteView) Sink {
|
||||
if dst == nil {
|
||||
panic("nil dst")
|
||||
}
|
||||
return &byteViewSink{dst: dst}
|
||||
}
|
||||
|
||||
type byteViewSink struct {
|
||||
dst *ByteView
|
||||
|
||||
// if this code ever ends up tracking that at least one set*
|
||||
// method was called, don't make it an error to call set
|
||||
// methods multiple times. Lorry's payload.go does that, and
|
||||
// it makes sense. The comment at the top of this file about
|
||||
// "exactly one of the Set methods" is overly strict. We
|
||||
// really care about at least once (in a handler), but if
|
||||
// multiple handlers fail (or multiple functions in a program
|
||||
// using a Sink), it's okay to re-use the same one.
|
||||
}
|
||||
|
||||
func (s *byteViewSink) setView(v ByteView) error {
|
||||
*s.dst = v
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *byteViewSink) view() (ByteView, error) {
|
||||
return *s.dst, nil
|
||||
}
|
||||
|
||||
func (s *byteViewSink) SetProto(m proto.Message) error {
|
||||
b, err := proto.Marshal(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*s.dst = ByteView{b: b}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *byteViewSink) SetBytes(b []byte) error {
|
||||
*s.dst = ByteView{b: cloneBytes(b)}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *byteViewSink) SetString(v string) error {
|
||||
*s.dst = ByteView{s: v}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProtoSink returns a sink that unmarshals binary proto values into m.
|
||||
func ProtoSink(m proto.Message) Sink {
|
||||
return &protoSink{
|
||||
dst: m,
|
||||
}
|
||||
}
|
||||
|
||||
type protoSink struct {
|
||||
dst proto.Message // authoritative value
|
||||
typ string
|
||||
|
||||
v ByteView // encoded
|
||||
}
|
||||
|
||||
func (s *protoSink) view() (ByteView, error) {
|
||||
return s.v, nil
|
||||
}
|
||||
|
||||
func (s *protoSink) SetBytes(b []byte) error {
|
||||
err := proto.Unmarshal(b, s.dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.v.b = cloneBytes(b)
|
||||
s.v.s = ""
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *protoSink) SetString(v string) error {
|
||||
b := []byte(v)
|
||||
err := proto.Unmarshal(b, s.dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.v.b = b
|
||||
s.v.s = ""
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *protoSink) SetProto(m proto.Message) error {
|
||||
b, err := proto.Marshal(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO(bradfitz): optimize for same-task case more and write
|
||||
// right through? would need to document ownership rules at
|
||||
// the same time. but then we could just assign *dst = *m
|
||||
// here. This works for now:
|
||||
err = proto.Unmarshal(b, s.dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.v.b = b
|
||||
s.v.s = ""
|
||||
return nil
|
||||
}
|
||||
|
||||
// AllocatingByteSliceSink returns a Sink that allocates
|
||||
// a byte slice to hold the received value and assigns
|
||||
// it to *dst. The memory is not retained by groupcache.
|
||||
func AllocatingByteSliceSink(dst *[]byte) Sink {
|
||||
return &allocBytesSink{dst: dst}
|
||||
}
|
||||
|
||||
type allocBytesSink struct {
|
||||
dst *[]byte
|
||||
v ByteView
|
||||
}
|
||||
|
||||
func (s *allocBytesSink) view() (ByteView, error) {
|
||||
return s.v, nil
|
||||
}
|
||||
|
||||
func (s *allocBytesSink) setView(v ByteView) error {
|
||||
if v.b != nil {
|
||||
*s.dst = cloneBytes(v.b)
|
||||
} else {
|
||||
*s.dst = []byte(v.s)
|
||||
}
|
||||
s.v = v
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *allocBytesSink) SetProto(m proto.Message) error {
|
||||
b, err := proto.Marshal(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return s.setBytesOwned(b)
|
||||
}
|
||||
|
||||
func (s *allocBytesSink) SetBytes(b []byte) error {
|
||||
return s.setBytesOwned(cloneBytes(b))
|
||||
}
|
||||
|
||||
func (s *allocBytesSink) setBytesOwned(b []byte) error {
|
||||
if s.dst == nil {
|
||||
return errors.New("nil AllocatingByteSliceSink *[]byte dst")
|
||||
}
|
||||
*s.dst = cloneBytes(b) // another copy, protecting the read-only s.v.b view
|
||||
s.v.b = b
|
||||
s.v.s = ""
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *allocBytesSink) SetString(v string) error {
|
||||
if s.dst == nil {
|
||||
return errors.New("nil AllocatingByteSliceSink *[]byte dst")
|
||||
}
|
||||
*s.dst = []byte(v)
|
||||
s.v.b = nil
|
||||
s.v.s = v
|
||||
return nil
|
||||
}
|
||||
|
||||
// TruncatingByteSliceSink returns a Sink that writes up to len(*dst)
|
||||
// bytes to *dst. If more bytes are available, they're silently
|
||||
// truncated. If fewer bytes are available than len(*dst), *dst
|
||||
// is shrunk to fit the number of bytes available.
|
||||
func TruncatingByteSliceSink(dst *[]byte) Sink {
|
||||
return &truncBytesSink{dst: dst}
|
||||
}
|
||||
|
||||
type truncBytesSink struct {
|
||||
dst *[]byte
|
||||
v ByteView
|
||||
}
|
||||
|
||||
func (s *truncBytesSink) view() (ByteView, error) {
|
||||
return s.v, nil
|
||||
}
|
||||
|
||||
func (s *truncBytesSink) SetProto(m proto.Message) error {
|
||||
b, err := proto.Marshal(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return s.setBytesOwned(b)
|
||||
}
|
||||
|
||||
func (s *truncBytesSink) SetBytes(b []byte) error {
|
||||
return s.setBytesOwned(cloneBytes(b))
|
||||
}
|
||||
|
||||
func (s *truncBytesSink) setBytesOwned(b []byte) error {
|
||||
if s.dst == nil {
|
||||
return errors.New("nil TruncatingByteSliceSink *[]byte dst")
|
||||
}
|
||||
n := copy(*s.dst, b)
|
||||
if n < len(*s.dst) {
|
||||
*s.dst = (*s.dst)[:n]
|
||||
}
|
||||
s.v.b = b
|
||||
s.v.s = ""
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *truncBytesSink) SetString(v string) error {
|
||||
if s.dst == nil {
|
||||
return errors.New("nil TruncatingByteSliceSink *[]byte dst")
|
||||
}
|
||||
n := copy(*s.dst, v)
|
||||
if n < len(*s.dst) {
|
||||
*s.dst = (*s.dst)[:n]
|
||||
}
|
||||
s.v.b = nil
|
||||
s.v.s = v
|
||||
return nil
|
||||
}
|
||||
17
vendor/github.com/golang/protobuf/.gitignore
generated
vendored
17
vendor/github.com/golang/protobuf/.gitignore
generated
vendored
|
|
@ -1,17 +0,0 @@
|
|||
.DS_Store
|
||||
*.[568ao]
|
||||
*.ao
|
||||
*.so
|
||||
*.pyc
|
||||
._*
|
||||
.nfs.*
|
||||
[568a].out
|
||||
*~
|
||||
*.orig
|
||||
core
|
||||
_obj
|
||||
_test
|
||||
_testmain.go
|
||||
|
||||
# Conformance test output and transient files.
|
||||
conformance/failing_tests.txt
|
||||
32
vendor/github.com/golang/protobuf/.travis.yml
generated
vendored
32
vendor/github.com/golang/protobuf/.travis.yml
generated
vendored
|
|
@ -1,32 +0,0 @@
|
|||
sudo: false
|
||||
language: go
|
||||
go:
|
||||
- 1.9.x
|
||||
- 1.10.x
|
||||
- 1.11.x
|
||||
- 1.x
|
||||
|
||||
install:
|
||||
- go get -v -d google.golang.org/grpc
|
||||
- go get -v -d -t github.com/golang/protobuf/...
|
||||
- curl -L https://github.com/google/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip -o /tmp/protoc.zip
|
||||
- unzip /tmp/protoc.zip -d "$HOME"/protoc
|
||||
- mkdir -p "$HOME"/src && ln -s "$HOME"/protoc "$HOME"/src/protobuf
|
||||
|
||||
env:
|
||||
- PATH=$HOME/protoc/bin:$PATH
|
||||
|
||||
script:
|
||||
- make all
|
||||
- make regenerate
|
||||
# TODO(tamird): When https://github.com/travis-ci/gimme/pull/130 is
|
||||
# released, make this look for "1.x".
|
||||
- if [[ "$TRAVIS_GO_VERSION" == 1.10* ]]; then
|
||||
if [[ "$(git status --porcelain 2>&1)" != "" ]]; then
|
||||
git status >&2;
|
||||
git diff -a >&2;
|
||||
exit 1;
|
||||
fi;
|
||||
echo "git status is clean.";
|
||||
fi;
|
||||
- make test
|
||||
49
vendor/github.com/golang/protobuf/Makefile
generated
vendored
49
vendor/github.com/golang/protobuf/Makefile
generated
vendored
|
|
@ -1,49 +0,0 @@
|
|||
# Go support for Protocol Buffers - Google's data interchange format
|
||||
#
|
||||
# Copyright 2010 The Go Authors. All rights reserved.
|
||||
# https://github.com/golang/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
all: install
|
||||
|
||||
install:
|
||||
go install ./proto ./jsonpb ./ptypes ./protoc-gen-go
|
||||
|
||||
test:
|
||||
go test ./... ./protoc-gen-go/testdata
|
||||
go test -tags purego ./... ./protoc-gen-go/testdata
|
||||
go build ./protoc-gen-go/testdata/grpc/grpc.pb.go
|
||||
|
||||
clean:
|
||||
go clean ./...
|
||||
|
||||
nuke:
|
||||
go clean -i ./...
|
||||
|
||||
regenerate:
|
||||
./regenerate.sh
|
||||
289
vendor/github.com/golang/protobuf/README.md
generated
vendored
289
vendor/github.com/golang/protobuf/README.md
generated
vendored
|
|
@ -1,289 +0,0 @@
|
|||
# Go support for Protocol Buffers - Google's data interchange format
|
||||
|
||||
[](https://travis-ci.org/golang/protobuf)
|
||||
[](https://godoc.org/github.com/golang/protobuf)
|
||||
|
||||
Google's data interchange format.
|
||||
Copyright 2010 The Go Authors.
|
||||
https://github.com/golang/protobuf
|
||||
|
||||
This package and the code it generates requires at least Go 1.9.
|
||||
|
||||
This software implements Go bindings for protocol buffers. For
|
||||
information about protocol buffers themselves, see
|
||||
https://developers.google.com/protocol-buffers/
|
||||
|
||||
## Installation ##
|
||||
|
||||
To use this software, you must:
|
||||
- Install the standard C++ implementation of protocol buffers from
|
||||
https://developers.google.com/protocol-buffers/
|
||||
- Of course, install the Go compiler and tools from
|
||||
https://golang.org/
|
||||
See
|
||||
https://golang.org/doc/install
|
||||
for details or, if you are using gccgo, follow the instructions at
|
||||
https://golang.org/doc/install/gccgo
|
||||
- Grab the code from the repository and install the `proto` package.
|
||||
The simplest way is to run `go get -u github.com/golang/protobuf/protoc-gen-go`.
|
||||
The compiler plugin, `protoc-gen-go`, will be installed in `$GOPATH/bin`
|
||||
unless `$GOBIN` is set. It must be in your `$PATH` for the protocol
|
||||
compiler, `protoc`, to find it.
|
||||
- If you need a particular version of `protoc-gen-go` (e.g., to match your
|
||||
`proto` package version), one option is
|
||||
```shell
|
||||
GIT_TAG="v1.2.0" # change as needed
|
||||
go get -d -u github.com/golang/protobuf/protoc-gen-go
|
||||
git -C "$(go env GOPATH)"/src/github.com/golang/protobuf checkout $GIT_TAG
|
||||
go install github.com/golang/protobuf/protoc-gen-go
|
||||
```
|
||||
|
||||
This software has two parts: a 'protocol compiler plugin' that
|
||||
generates Go source files that, once compiled, can access and manage
|
||||
protocol buffers; and a library that implements run-time support for
|
||||
encoding (marshaling), decoding (unmarshaling), and accessing protocol
|
||||
buffers.
|
||||
|
||||
There is support for gRPC in Go using protocol buffers.
|
||||
See the note at the bottom of this file for details.
|
||||
|
||||
There are no insertion points in the plugin.
|
||||
|
||||
|
||||
## Using protocol buffers with Go ##
|
||||
|
||||
Once the software is installed, there are two steps to using it.
|
||||
First you must compile the protocol buffer definitions and then import
|
||||
them, with the support library, into your program.
|
||||
|
||||
To compile the protocol buffer definition, run protoc with the --go_out
|
||||
parameter set to the directory you want to output the Go code to.
|
||||
|
||||
protoc --go_out=. *.proto
|
||||
|
||||
The generated files will be suffixed .pb.go. See the Test code below
|
||||
for an example using such a file.
|
||||
|
||||
## Packages and input paths ##
|
||||
|
||||
The protocol buffer language has a concept of "packages" which does not
|
||||
correspond well to the Go notion of packages. In generated Go code,
|
||||
each source `.proto` file is associated with a single Go package. The
|
||||
name and import path for this package is specified with the `go_package`
|
||||
proto option:
|
||||
|
||||
option go_package = "github.com/golang/protobuf/ptypes/any";
|
||||
|
||||
The protocol buffer compiler will attempt to derive a package name and
|
||||
import path if a `go_package` option is not present, but it is
|
||||
best to always specify one explicitly.
|
||||
|
||||
There is a one-to-one relationship between source `.proto` files and
|
||||
generated `.pb.go` files, but any number of `.pb.go` files may be
|
||||
contained in the same Go package.
|
||||
|
||||
The output name of a generated file is produced by replacing the
|
||||
`.proto` suffix with `.pb.go` (e.g., `foo.proto` produces `foo.pb.go`).
|
||||
However, the output directory is selected in one of two ways. Let
|
||||
us say we have `inputs/x.proto` with a `go_package` option of
|
||||
`github.com/golang/protobuf/p`. The corresponding output file may
|
||||
be:
|
||||
|
||||
- Relative to the import path:
|
||||
|
||||
```shell
|
||||
protoc --go_out=. inputs/x.proto
|
||||
# writes ./github.com/golang/protobuf/p/x.pb.go
|
||||
```
|
||||
|
||||
(This can work well with `--go_out=$GOPATH`.)
|
||||
|
||||
- Relative to the input file:
|
||||
|
||||
```shell
|
||||
protoc --go_out=paths=source_relative:. inputs/x.proto
|
||||
# generate ./inputs/x.pb.go
|
||||
```
|
||||
|
||||
## Generated code ##
|
||||
|
||||
The package comment for the proto library contains text describing
|
||||
the interface provided in Go for protocol buffers. Here is an edited
|
||||
version.
|
||||
|
||||
The proto package converts data structures to and from the
|
||||
wire format of protocol buffers. It works in concert with the
|
||||
Go source code generated for .proto files by the protocol compiler.
|
||||
|
||||
A summary of the properties of the protocol buffer interface
|
||||
for a protocol buffer variable v:
|
||||
|
||||
- Names are turned from camel_case to CamelCase for export.
|
||||
- There are no methods on v to set fields; just treat
|
||||
them as structure fields.
|
||||
- There are getters that return a field's value if set,
|
||||
and return the field's default value if unset.
|
||||
The getters work even if the receiver is a nil message.
|
||||
- The zero value for a struct is its correct initialization state.
|
||||
All desired fields must be set before marshaling.
|
||||
- A Reset() method will restore a protobuf struct to its zero state.
|
||||
- Non-repeated fields are pointers to the values; nil means unset.
|
||||
That is, optional or required field int32 f becomes F *int32.
|
||||
- Repeated fields are slices.
|
||||
- Helper functions are available to aid the setting of fields.
|
||||
Helpers for getting values are superseded by the
|
||||
GetFoo methods and their use is deprecated.
|
||||
msg.Foo = proto.String("hello") // set field
|
||||
- Constants are defined to hold the default values of all fields that
|
||||
have them. They have the form Default_StructName_FieldName.
|
||||
Because the getter methods handle defaulted values,
|
||||
direct use of these constants should be rare.
|
||||
- Enums are given type names and maps from names to values.
|
||||
Enum values are prefixed with the enum's type name. Enum types have
|
||||
a String method, and a Enum method to assist in message construction.
|
||||
- Nested groups and enums have type names prefixed with the name of
|
||||
the surrounding message type.
|
||||
- Extensions are given descriptor names that start with E_,
|
||||
followed by an underscore-delimited list of the nested messages
|
||||
that contain it (if any) followed by the CamelCased name of the
|
||||
extension field itself. HasExtension, ClearExtension, GetExtension
|
||||
and SetExtension are functions for manipulating extensions.
|
||||
- Oneof field sets are given a single field in their message,
|
||||
with distinguished wrapper types for each possible field value.
|
||||
- Marshal and Unmarshal are functions to encode and decode the wire format.
|
||||
|
||||
When the .proto file specifies `syntax="proto3"`, there are some differences:
|
||||
|
||||
- Non-repeated fields of non-message type are values instead of pointers.
|
||||
- Enum types do not get an Enum method.
|
||||
|
||||
Consider file test.proto, containing
|
||||
|
||||
```proto
|
||||
syntax = "proto2";
|
||||
package example;
|
||||
|
||||
enum FOO { X = 17; };
|
||||
|
||||
message Test {
|
||||
required string label = 1;
|
||||
optional int32 type = 2 [default=77];
|
||||
repeated int64 reps = 3;
|
||||
}
|
||||
```
|
||||
|
||||
To create and play with a Test object from the example package,
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"path/to/example"
|
||||
)
|
||||
|
||||
func main() {
|
||||
test := &example.Test{
|
||||
Label: proto.String("hello"),
|
||||
Type: proto.Int32(17),
|
||||
Reps: []int64{1, 2, 3},
|
||||
}
|
||||
data, err := proto.Marshal(test)
|
||||
if err != nil {
|
||||
log.Fatal("marshaling error: ", err)
|
||||
}
|
||||
newTest := &example.Test{}
|
||||
err = proto.Unmarshal(data, newTest)
|
||||
if err != nil {
|
||||
log.Fatal("unmarshaling error: ", err)
|
||||
}
|
||||
// Now test and newTest contain the same data.
|
||||
if test.GetLabel() != newTest.GetLabel() {
|
||||
log.Fatalf("data mismatch %q != %q", test.GetLabel(), newTest.GetLabel())
|
||||
}
|
||||
// etc.
|
||||
}
|
||||
```
|
||||
|
||||
## Parameters ##
|
||||
|
||||
To pass extra parameters to the plugin, use a comma-separated
|
||||
parameter list separated from the output directory by a colon:
|
||||
|
||||
protoc --go_out=plugins=grpc,import_path=mypackage:. *.proto
|
||||
|
||||
- `paths=(import | source_relative)` - specifies how the paths of
|
||||
generated files are structured. See the "Packages and imports paths"
|
||||
section above. The default is `import`.
|
||||
- `plugins=plugin1+plugin2` - specifies the list of sub-plugins to
|
||||
load. The only plugin in this repo is `grpc`.
|
||||
- `Mfoo/bar.proto=quux/shme` - declares that foo/bar.proto is
|
||||
associated with Go package quux/shme. This is subject to the
|
||||
import_prefix parameter.
|
||||
|
||||
The following parameters are deprecated and should not be used:
|
||||
|
||||
- `import_prefix=xxx` - a prefix that is added onto the beginning of
|
||||
all imports.
|
||||
- `import_path=foo/bar` - used as the package if no input files
|
||||
declare `go_package`. If it contains slashes, everything up to the
|
||||
rightmost slash is ignored.
|
||||
|
||||
## gRPC Support ##
|
||||
|
||||
If a proto file specifies RPC services, protoc-gen-go can be instructed to
|
||||
generate code compatible with gRPC (http://www.grpc.io/). To do this, pass
|
||||
the `plugins` parameter to protoc-gen-go; the usual way is to insert it into
|
||||
the --go_out argument to protoc:
|
||||
|
||||
protoc --go_out=plugins=grpc:. *.proto
|
||||
|
||||
## Compatibility ##
|
||||
|
||||
The library and the generated code are expected to be stable over time.
|
||||
However, we reserve the right to make breaking changes without notice for the
|
||||
following reasons:
|
||||
|
||||
- Security. A security issue in the specification or implementation may come to
|
||||
light whose resolution requires breaking compatibility. We reserve the right
|
||||
to address such security issues.
|
||||
- Unspecified behavior. There are some aspects of the Protocol Buffers
|
||||
specification that are undefined. Programs that depend on such unspecified
|
||||
behavior may break in future releases.
|
||||
- Specification errors or changes. If it becomes necessary to address an
|
||||
inconsistency, incompleteness, or change in the Protocol Buffers
|
||||
specification, resolving the issue could affect the meaning or legality of
|
||||
existing programs. We reserve the right to address such issues, including
|
||||
updating the implementations.
|
||||
- Bugs. If the library has a bug that violates the specification, a program
|
||||
that depends on the buggy behavior may break if the bug is fixed. We reserve
|
||||
the right to fix such bugs.
|
||||
- Adding methods or fields to generated structs. These may conflict with field
|
||||
names that already exist in a schema, causing applications to break. When the
|
||||
code generator encounters a field in the schema that would collide with a
|
||||
generated field or method name, the code generator will append an underscore
|
||||
to the generated field or method name.
|
||||
- Adding, removing, or changing methods or fields in generated structs that
|
||||
start with `XXX`. These parts of the generated code are exported out of
|
||||
necessity, but should not be considered part of the public API.
|
||||
- Adding, removing, or changing unexported symbols in generated code.
|
||||
|
||||
Any breaking changes outside of these will be announced 6 months in advance to
|
||||
protobuf@googlegroups.com.
|
||||
|
||||
You should, whenever possible, use generated code created by the `protoc-gen-go`
|
||||
tool built at the same commit as the `proto` package. The `proto` package
|
||||
declares package-level constants in the form `ProtoPackageIsVersionX`.
|
||||
Application code and generated code may depend on one of these constants to
|
||||
ensure that compilation will fail if the available version of the proto library
|
||||
is too old. Whenever we make a change to the generated code that requires newer
|
||||
library support, in the same commit we will increment the version number of the
|
||||
generated code and declare a new package-level constant whose name incorporates
|
||||
the latest version number. Removing a compatibility constant is considered a
|
||||
breaking change and would be subject to the announcement policy stated above.
|
||||
|
||||
The `protoc-gen-go/generator` package exposes a plugin interface,
|
||||
which is used by the gRPC code generation. This interface is not
|
||||
supported and is subject to incompatible changes without notice.
|
||||
1
vendor/github.com/golang/protobuf/go.mod
generated
vendored
1
vendor/github.com/golang/protobuf/go.mod
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
module github.com/golang/protobuf
|
||||
0
vendor/github.com/golang/protobuf/go.sum
generated
vendored
0
vendor/github.com/golang/protobuf/go.sum
generated
vendored
51
vendor/github.com/golang/protobuf/protoc-gen-go/doc.go
generated
vendored
51
vendor/github.com/golang/protobuf/protoc-gen-go/doc.go
generated
vendored
|
|
@ -1,51 +0,0 @@
|
|||
// Go support for Protocol Buffers - Google's data interchange format
|
||||
//
|
||||
// Copyright 2010 The Go Authors. All rights reserved.
|
||||
// https://github.com/golang/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
/*
|
||||
A plugin for the Google protocol buffer compiler to generate Go code.
|
||||
Run it by building this program and putting it in your path with the name
|
||||
protoc-gen-go
|
||||
That word 'go' at the end becomes part of the option string set for the
|
||||
protocol compiler, so once the protocol compiler (protoc) is installed
|
||||
you can run
|
||||
protoc --go_out=output_directory input_directory/file.proto
|
||||
to generate Go bindings for the protocol defined by file.proto.
|
||||
With that input, the output will be written to
|
||||
output_directory/file.pb.go
|
||||
|
||||
The generated code is documented in the package comment for
|
||||
the library.
|
||||
|
||||
See the README and documentation for protocol buffers to learn more:
|
||||
https://developers.google.com/protocol-buffers/
|
||||
|
||||
*/
|
||||
package documentation
|
||||
34
vendor/github.com/golang/protobuf/protoc-gen-go/link_grpc.go
generated
vendored
34
vendor/github.com/golang/protobuf/protoc-gen-go/link_grpc.go
generated
vendored
|
|
@ -1,34 +0,0 @@
|
|||
// Go support for Protocol Buffers - Google's data interchange format
|
||||
//
|
||||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// https://github.com/golang/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package main
|
||||
|
||||
import _ "github.com/golang/protobuf/protoc-gen-go/grpc"
|
||||
98
vendor/github.com/golang/protobuf/protoc-gen-go/main.go
generated
vendored
98
vendor/github.com/golang/protobuf/protoc-gen-go/main.go
generated
vendored
|
|
@ -1,98 +0,0 @@
|
|||
// Go support for Protocol Buffers - Google's data interchange format
|
||||
//
|
||||
// Copyright 2010 The Go Authors. All rights reserved.
|
||||
// https://github.com/golang/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// protoc-gen-go is a plugin for the Google protocol buffer compiler to generate
|
||||
// Go code. Run it by building this program and putting it in your path with
|
||||
// the name
|
||||
// protoc-gen-go
|
||||
// That word 'go' at the end becomes part of the option string set for the
|
||||
// protocol compiler, so once the protocol compiler (protoc) is installed
|
||||
// you can run
|
||||
// protoc --go_out=output_directory input_directory/file.proto
|
||||
// to generate Go bindings for the protocol defined by file.proto.
|
||||
// With that input, the output will be written to
|
||||
// output_directory/file.pb.go
|
||||
//
|
||||
// The generated code is documented in the package comment for
|
||||
// the library.
|
||||
//
|
||||
// See the README and documentation for protocol buffers to learn more:
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/golang/protobuf/protoc-gen-go/generator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Begin by allocating a generator. The request and response structures are stored there
|
||||
// so we can do error handling easily - the response structure contains the field to
|
||||
// report failure.
|
||||
g := generator.New()
|
||||
|
||||
data, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
g.Error(err, "reading input")
|
||||
}
|
||||
|
||||
if err := proto.Unmarshal(data, g.Request); err != nil {
|
||||
g.Error(err, "parsing input proto")
|
||||
}
|
||||
|
||||
if len(g.Request.FileToGenerate) == 0 {
|
||||
g.Fail("no files to generate")
|
||||
}
|
||||
|
||||
g.CommandLineParameters(g.Request.GetParameter())
|
||||
|
||||
// Create a wrapped version of the Descriptors and EnumDescriptors that
|
||||
// point to the file that defines them.
|
||||
g.WrapTypes()
|
||||
|
||||
g.SetPackageNames()
|
||||
g.BuildTypeNameMap()
|
||||
|
||||
g.GenerateAllFiles()
|
||||
|
||||
// Send back the results.
|
||||
data, err = proto.Marshal(g.Response)
|
||||
if err != nil {
|
||||
g.Error(err, "failed to marshal output proto")
|
||||
}
|
||||
_, err = os.Stdout.Write(data)
|
||||
if err != nil {
|
||||
g.Error(err, "failed to write output proto")
|
||||
}
|
||||
}
|
||||
52
vendor/github.com/golang/protobuf/regenerate.sh
generated
vendored
52
vendor/github.com/golang/protobuf/regenerate.sh
generated
vendored
|
|
@ -1,52 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Install the working tree's protoc-gen-gen in a tempdir.
|
||||
tmpdir=$(mktemp -d -t regen-wkt.XXXXXX)
|
||||
trap 'rm -rf $tmpdir' EXIT
|
||||
mkdir -p $tmpdir/bin
|
||||
PATH=$tmpdir/bin:$PATH
|
||||
GOBIN=$tmpdir/bin go install ./protoc-gen-go
|
||||
|
||||
# Public imports require at least Go 1.9.
|
||||
supportTypeAliases=""
|
||||
if go list -f '{{context.ReleaseTags}}' runtime | grep -q go1.9; then
|
||||
supportTypeAliases=1
|
||||
fi
|
||||
|
||||
# Generate various test protos.
|
||||
PROTO_DIRS=(
|
||||
jsonpb/jsonpb_test_proto
|
||||
proto
|
||||
protoc-gen-go/testdata
|
||||
)
|
||||
for dir in ${PROTO_DIRS[@]}; do
|
||||
for p in `find $dir -name "*.proto"`; do
|
||||
if [[ $p == */import_public/* && ! $supportTypeAliases ]]; then
|
||||
echo "# $p (skipped)"
|
||||
continue;
|
||||
fi
|
||||
echo "# $p"
|
||||
protoc -I$dir --go_out=plugins=grpc,paths=source_relative:$dir $p
|
||||
done
|
||||
done
|
||||
|
||||
# Deriving the location of the source protos from the path to the
|
||||
# protoc binary may be a bit odd, but this is what protoc itself does.
|
||||
PROTO_INCLUDE=$(dirname $(dirname $(which protoc)))/include
|
||||
|
||||
# Well-known types.
|
||||
WKT_PROTOS=(any duration empty struct timestamp wrappers)
|
||||
for p in ${WKT_PROTOS[@]}; do
|
||||
echo "# google/protobuf/$p.proto"
|
||||
protoc --go_out=paths=source_relative:$tmpdir google/protobuf/$p.proto
|
||||
cp $tmpdir/google/protobuf/$p.pb.go ptypes/$p
|
||||
cp $PROTO_INCLUDE/google/protobuf/$p.proto ptypes/$p
|
||||
done
|
||||
|
||||
# descriptor.proto.
|
||||
echo "# google/protobuf/descriptor.proto"
|
||||
protoc --go_out=paths=source_relative:$tmpdir google/protobuf/descriptor.proto
|
||||
cp $tmpdir/google/protobuf/descriptor.pb.go protoc-gen-go/descriptor
|
||||
cp $PROTO_INCLUDE/google/protobuf/descriptor.proto protoc-gen-go/descriptor
|
||||
Loading…
Add table
Add a link
Reference in a new issue