├── .gitignore ├── Gopkg.lock ├── Gopkg.toml ├── README.md ├── config.yaml ├── daemon.go ├── daemon_test.go ├── defs.go ├── proxy.go ├── proxy_call.go ├── proxy_delete.go ├── proxy_insert.go ├── proxy_ping.go ├── proxy_select.go ├── proxy_update.go ├── schema.go └── vendor ├── github.com ├── golang │ └── protobuf │ │ ├── AUTHORS │ │ ├── CONTRIBUTORS │ │ ├── LICENSE │ │ └── proto │ │ ├── Makefile │ │ ├── clone.go │ │ ├── decode.go │ │ ├── discard.go │ │ ├── encode.go │ │ ├── equal.go │ │ ├── extensions.go │ │ ├── lib.go │ │ ├── message_set.go │ │ ├── pointer_reflect.go │ │ ├── pointer_unsafe.go │ │ ├── properties.go │ │ ├── text.go │ │ └── text_parser.go ├── quipo │ └── statsd │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── bufferedclient.go │ │ ├── client.go │ │ ├── event │ │ ├── absolute.go │ │ ├── fabsolute.go │ │ ├── fgauge.go │ │ ├── fgaugedelta.go │ │ ├── gauge.go │ │ ├── gaugedelta.go │ │ ├── increment.go │ │ ├── interface.go │ │ ├── precisiontiming.go │ │ ├── timing.go │ │ └── total.go │ │ ├── interface.go │ │ ├── noopclient.go │ │ └── stdoutclient.go └── tarantool │ └── go-tarantool │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── auth.go │ ├── client_tools.go │ ├── config.lua │ ├── connection.go │ ├── const.go │ ├── deadline_io.go │ ├── errors.go │ ├── request.go │ ├── response.go │ ├── schema.go │ └── smallbuf.go ├── golang.org └── x │ └── net │ ├── AUTHORS │ ├── CONTRIBUTORS │ ├── LICENSE │ ├── PATENTS │ └── context │ ├── context.go │ ├── go17.go │ ├── go19.go │ ├── pre_go17.go │ └── pre_go19.go ├── google.golang.org └── appengine │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── appengine.go │ ├── appengine_vm.go │ ├── datastore │ ├── datastore.go │ ├── doc.go │ ├── key.go │ ├── load.go │ ├── metadata.go │ ├── prop.go │ ├── query.go │ ├── save.go │ └── transaction.go │ ├── errors.go │ ├── identity.go │ ├── internal │ ├── api.go │ ├── api_classic.go │ ├── api_common.go │ ├── app_id.go │ ├── app_identity │ │ ├── app_identity_service.pb.go │ │ └── app_identity_service.proto │ ├── base │ │ ├── api_base.pb.go │ │ └── api_base.proto │ ├── datastore │ │ ├── datastore_v3.pb.go │ │ └── datastore_v3.proto │ ├── identity.go │ ├── identity_classic.go │ ├── identity_vm.go │ ├── internal.go │ ├── log │ │ ├── log_service.pb.go │ │ └── log_service.proto │ ├── main.go │ ├── main_vm.go │ ├── metadata.go │ ├── modules │ │ ├── modules_service.pb.go │ │ └── modules_service.proto │ ├── net.go │ ├── regen.sh │ ├── remote_api │ │ ├── remote_api.pb.go │ │ └── remote_api.proto │ └── transaction.go │ ├── namespace.go │ └── timeout.go └── gopkg.in ├── vmihailenco └── msgpack.v2 │ ├── .travis.yml │ ├── LICENSE │ ├── Makefile │ ├── README.md │ ├── appengine.go │ ├── codes │ └── codes.go │ ├── decode.go │ ├── decode_map.go │ ├── decode_number.go │ ├── decode_query.go │ ├── decode_slice.go │ ├── decode_string.go │ ├── decode_value.go │ ├── encode.go │ ├── encode_map.go │ ├── encode_number.go │ ├── encode_slice.go │ ├── encode_value.go │ ├── ext.go │ ├── msgpack.go │ ├── tags.go │ ├── time.go │ └── types.go └── yaml.v2 ├── .travis.yml ├── LICENSE ├── LICENSE.libyaml ├── NOTICE ├── README.md ├── apic.go ├── decode.go ├── emitterc.go ├── encode.go ├── go.mod ├── parserc.go ├── readerc.go ├── resolve.go ├── scannerc.go ├── sorter.go ├── writerc.go ├── yaml.go ├── yamlh.go └── yamlprivateh.go /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe 2 | tarantool-proxy 3 | 4 | -------------------------------------------------------------------------------- /Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | name = "github.com/golang/protobuf" 6 | packages = ["proto"] 7 | revision = "925541529c1fa6821df4e44ce2723319eb2be768" 8 | version = "v1.0.0" 9 | 10 | [[projects]] 11 | name = "github.com/quipo/statsd" 12 | packages = [ 13 | ".", 14 | "event" 15 | ] 16 | revision = "977fadbd5cda9975ab87279994ea2029efdbd436" 17 | version = "1.4.0" 18 | 19 | [[projects]] 20 | branch = "master" 21 | name = "github.com/tarantool/go-tarantool" 22 | packages = ["."] 23 | revision = "5de9a66537ce6f0d98834cebd9c1348b68042107" 24 | 25 | [[projects]] 26 | branch = "master" 27 | name = "golang.org/x/net" 28 | packages = ["context"] 29 | revision = "61147c48b25b599e5b561d2e9c4f3e1ef489ca41" 30 | 31 | [[projects]] 32 | name = "google.golang.org/appengine" 33 | packages = [ 34 | ".", 35 | "datastore", 36 | "internal", 37 | "internal/app_identity", 38 | "internal/base", 39 | "internal/datastore", 40 | "internal/log", 41 | "internal/modules", 42 | "internal/remote_api" 43 | ] 44 | revision = "150dc57a1b433e64154302bdc40b6bb8aefa313a" 45 | version = "v1.0.0" 46 | 47 | [[projects]] 48 | name = "gopkg.in/vmihailenco/msgpack.v2" 49 | packages = [ 50 | ".", 51 | "codes" 52 | ] 53 | revision = "f4f8982de4ef0de18be76456617cc3f5d8d8141e" 54 | version = "v2.9.1" 55 | 56 | [[projects]] 57 | name = "gopkg.in/yaml.v2" 58 | packages = ["."] 59 | revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" 60 | version = "v2.2.1" 61 | 62 | [solve-meta] 63 | analyzer-name = "dep" 64 | analyzer-version = 1 65 | inputs-digest = "57276fef4290d7b4c7944d3fe69ab90a2f0e090dc4db13bc8b08c5af3b72a9a7" 66 | solver-name = "gps-cdcl" 67 | solver-version = 1 68 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | # Gopkg.toml example 2 | # 3 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md 4 | # for detailed Gopkg.toml documentation. 5 | # 6 | # required = ["github.com/user/thing/cmd/thing"] 7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 8 | # 9 | # [[constraint]] 10 | # name = "github.com/user/project" 11 | # version = "1.0.0" 12 | # 13 | # [[constraint]] 14 | # name = "github.com/user/project2" 15 | # branch = "dev" 16 | # source = "github.com/myfork/project2" 17 | # 18 | # [[override]] 19 | # name = "github.com/x/y" 20 | # version = "2.4.0" 21 | # 22 | # [prune] 23 | # non-go = false 24 | # go-tests = true 25 | # unused-packages = true 26 | 27 | 28 | [[constraint]] 29 | branch = "master" 30 | name = "github.com/tarantool/go-tarantool" 31 | 32 | [[constraint]] 33 | name = "gopkg.in/vmihailenco/msgpack.v2" 34 | version = "2.9.1" 35 | 36 | [[constraint]] 37 | name = "gopkg.in/yaml.v2" 38 | version = "2.2.1" 39 | 40 | [prune] 41 | go-tests = true 42 | unused-packages = true 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tarantool-proxy 2 | tarantool-proxy for 15 to 16 3 | 4 | repo: https://github.com/shveenkov/tarantool-proxy.git 5 | 6 | ## Features 7 | 8 | * proxy for tarantool iproto 1.5 to tarantool msgpack 1.6 9 | * optional sharding, for scale 10 | 11 | ## Migrate problems to tarantool 1.6 12 | select by key list: 13 | ``` 14 | select where id in (X, Y, Z) 15 | ``` 16 | 17 | you should be rewritten like this: 18 | ``` 19 | for id in (X, Y, Z): 20 | select where id=? 21 | ``` 22 | 23 | sharding specifics and lua calls. 24 | 25 | ## Dependencies 26 | ``` 27 | $ go get github.com/tarantool/go-tarantool 28 | $ go get gopkg.in/yaml.v2 29 | ``` 30 | 31 | ## Run proxy for test 32 | ``` 33 | $ cd $GOPATH/src 34 | $ git clone https://github.com/shveenkov/tarantool-proxy.git 35 | $ cd tarantool-proxy 36 | $ go build 37 | $ ./tarantool-proxy -config config.yaml 38 | ``` 39 | 40 | ## Example config.yaml 41 | 42 | ```yaml 43 | # host:port for create tarantool 1.5 iproto connection and listen requests 44 | listen: 45 | - 127.0.0.1:22033 46 | 47 | # host:port shard for proxy pass data into tarantool 1.6 connection 48 | tarantool: 49 | - ['127.0.0.1:3302'] 50 | 51 | # enable sharding 52 | sharding_enabled: true 53 | 54 | # enable send report to statsd 55 | statsd: 56 | server: '127.0.0.1:8125' 57 | prefix: 'tarantool.%HOST%.proxy' 58 | 59 | # schema space for 1.5 and 1.6 communicate 60 | space: 61 | - id: 0 62 | name: key_value 63 | fields: ['key:str', 'value:str'] 64 | index: 65 | - id: 0 66 | name: pk 67 | columns: [0] 68 | ``` 69 | -------------------------------------------------------------------------------- /config.yaml: -------------------------------------------------------------------------------- 1 | 2 | # host:port for create tarantool 1.5 iproto connection and listen requests 3 | listen: 4 | - 127.0.0.1:22033 5 | - 127.0.0.1:22034 6 | 7 | # host:port shard for proxy pass data into tarantool 1.6 connection 8 | tarantool: 9 | - ['127.0.0.1:3302', '127.0.0.1:3302'] 10 | - ['127.0.0.1:3303', '127.0.0.1:3303'] 11 | 12 | # credentials for tarantool database 13 | # user: "tntuser" 14 | # password: "tntpassword" 15 | 16 | # enable sharding 17 | sharding_enabled: true 18 | 19 | # enable send report to statsd 20 | statsd: 21 | server: '127.0.0.1:8125' 22 | prefix: 'tarantool.%HOST%.proxy' 23 | 24 | # schema space for 1.5 and 1.6 communicate 25 | space: 26 | - id: 0 27 | name: key_value 28 | fields: ['key:str', 'value:str'] 29 | index: 30 | - id: 0 31 | name: pk 32 | columns: [0] 33 | 34 | - id: 1 35 | name: list 36 | fields: ['uniq_key:str', 'not_uniq_key:str', 'value:str'] 37 | index: 38 | - id: 0 39 | name: pk 40 | columns: [0] 41 | - id: 1 42 | name: fk 43 | columns: [1] 44 | -------------------------------------------------------------------------------- /daemon_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | _ "fmt" 6 | "gopkg.in/vmihailenco/msgpack.v2" 7 | "testing" 8 | ) 9 | 10 | type myStruct struct { 11 | S string 12 | I int 13 | B bool 14 | } 15 | 16 | func TestMsgPack(t *testing.T) { 17 | // t.Errorf("foo test %d", 10) 18 | // msgpack.RegisterExt(1, myStruct{}) 19 | 20 | s := myStruct{S: "Str", I: 10, B: false} 21 | b, err := msgpack.Marshal(&s) 22 | if err != nil { 23 | t.Errorf("marshaling error: %s", err) 24 | } 25 | 26 | var v interface{} 27 | err = msgpack.Unmarshal(b, &v) 28 | if err != nil { 29 | t.Errorf("unmarshaling error: %s", err) 30 | } 31 | // fmt.Printf("%[1]T : %#[1]v", v) 32 | } 33 | 34 | func a1() []int { 35 | a := make([]int, 10) 36 | a[1] = 2 37 | a[8] = 3 38 | a[7], a[0] = a[1], a[8] 39 | 40 | return a 41 | } 42 | 43 | func BenchmarkFoo(b *testing.B) { 44 | // b.N 45 | for i := 0; i < b.N; i++ { 46 | k := a1() 47 | _ = k 48 | //fmt.Sprintf("a:%d", a[1]) 49 | } 50 | } 51 | 52 | var s string 53 | 54 | func BenchmarkStringCreate(b *testing.B) { 55 | var array = []byte{'m', 'a', 'r', 'k', 'o', '1', 0} 56 | 57 | for i := 0; i < b.N; i++ { 58 | //s := string(array) 59 | buf := bytes.NewBuffer(array) 60 | s = BytesToString(buf.Next(5)) 61 | buf.ReadByte() 62 | } 63 | } 64 | 65 | func BenchmarkStringCreateAlloc(b *testing.B) { 66 | var array = []byte{'m', 'a', 'r', 'k', 'o', '1', 0} 67 | 68 | for i := 0; i < b.N; i++ { 69 | //s := string(array) 70 | buf := bytes.NewBuffer(array) 71 | s = string(buf.Next(5)) 72 | buf.ReadByte() 73 | } 74 | } 75 | 76 | func BenchmarkBufWrite(b *testing.B) { 77 | var array = []byte{'m', 'a', 'r', 'k', 'o', '1', 0} 78 | for i := 0; i < b.N; i++ { 79 | buf := &bytes.Buffer{} 80 | buf.Write(array) 81 | buf.Write(array) 82 | buf.Write(array) 83 | buf.Write(array) 84 | buf.Write(array) 85 | buf.Write(array) 86 | buf.Write(array) 87 | buf.Write(array) 88 | buf.Write(array) 89 | buf.Write(array) 90 | } 91 | } 92 | 93 | func BenchmarkBytesBufWrite(b *testing.B) { 94 | var array = []byte{'m', 'a', 'r', 'k', 'o', '1', 0} 95 | for i := 0; i < b.N; i++ { 96 | var buf []byte 97 | 98 | buf = append(buf, array...) 99 | buf = append(buf, array...) 100 | buf = append(buf, array...) 101 | buf = append(buf, array...) 102 | buf = append(buf, array...) 103 | buf = append(buf, array...) 104 | buf = append(buf, array...) 105 | buf = append(buf, array...) 106 | buf = append(buf, array...) 107 | buf = append(buf, array...) 108 | } 109 | } 110 | 111 | var bufr *bytes.Reader 112 | 113 | func BenchmarkBufReader(b *testing.B) { 114 | var array = []byte{'m', 'a', 'r', 'k', 'o', '1', 0} 115 | for i := 0; i < b.N; i++ { 116 | bufr = bytes.NewReader(array) 117 | } 118 | } 119 | 120 | var bufw *bytes.Buffer 121 | 122 | func BenchmarkBufWriter(b *testing.B) { 123 | var array = []byte{'m', 'a', 'r', 'k', 'o', '1', 0} 124 | for i := 0; i < b.N; i++ { 125 | bufw = bytes.NewBuffer(array) 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /defs.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io" 5 | ) 6 | 7 | // proxy constants 8 | const ( 9 | Version = "0.0.1" 10 | 11 | // proxy count connections for CPU util 12 | Tnt16PoolSize = 1 13 | 14 | // request type list for iproto 15 15 | RequestTypeInsert = 13 16 | RequestTypeSelect = 17 17 | RequestTypeUpdate = 19 18 | RequestTypeDelete = 21 19 | RequestTypeCall = 22 20 | RequestTypePing = 65280 21 | 22 | ErrorUnpackData = 10022 23 | 24 | BadResponse15Status = 2 25 | 26 | FlagReturnTuple = 1 27 | FlagAdd = 2 28 | FlagReplace = 4 29 | FlagPing = 8 30 | ) 31 | 32 | // UpdateOperationCode map code for RequestUpdate 33 | var UpdateOperationCode = map[uint8]string{ 34 | 0: "=", 35 | 1: "+", 36 | 2: "&", 37 | 3: "^", 38 | 4: "|", 39 | 5: ":", 40 | } 41 | 42 | // IprotoReader reader interface for iproto 43 | type IprotoReader interface { 44 | io.ByteReader 45 | io.Reader 46 | Next(n int) []byte 47 | } 48 | 49 | // IprotoWriter writer interface for iproto 50 | type IprotoWriter interface { 51 | io.Writer 52 | WriteString(s string) (n int, err error) 53 | } 54 | 55 | // ProxyConfigStruct yaml config struct 56 | type ProxyConfigStruct struct { 57 | Listen15 []string `yaml:"listen,flow"` 58 | Pass16 [][]string `yaml:"tarantool,flow"` 59 | Sharding bool `yaml:"sharding_enabled,omitempty"` 60 | User string `yaml:"user,omitempty"` 61 | Password string `yaml:"password,omitempty"` 62 | Space []struct { 63 | ID uint32 `yaml:"id"` 64 | Name string `yaml:"name"` 65 | Fields []string `yaml:"fields,flow"` 66 | Index []struct { 67 | ID uint32 `yaml:"id"` 68 | Name string `yaml:"name"` 69 | Columns []uint32 `yaml:"columns,flow"` 70 | } 71 | } `yaml:"space,flow"` 72 | Statsd struct { 73 | Server string `yaml:"server"` 74 | Prefix string `yaml:"prefix"` 75 | } `yaml:"statsd,omitempty"` 76 | } 77 | -------------------------------------------------------------------------------- /proxy_call.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/tarantool/go-tarantool" 5 | ) 6 | 7 | func (p *ProxyConnection) executeRequestCall(requestType uint32, requestID uint32, 8 | reader IprotoReader) (flags uint32, response *tarantool.Response, err error) { 9 | //|--------------- header ----------------|-----request_body -------| 10 | // 11 | var ( 12 | cardinality uint32 13 | args []interface{} 14 | param interface{} 15 | ) 16 | 17 | // parse flags 18 | err = unpackUint32(reader, &flags) 19 | if err != nil { 20 | return 21 | } 22 | 23 | // tarantool 1.5 "request call" always return tuple 24 | flags |= FlagReturnTuple 25 | 26 | // parse proc_name 27 | fieldLen, err := unpackUint64BER(reader, 64) 28 | if err != nil { 29 | return 30 | } 31 | procName := BytesToString(reader.Next(int(fieldLen))) 32 | 33 | // parse proc params tuple 34 | err = unpackUint32(reader, &cardinality) 35 | if err != nil { 36 | return 37 | } 38 | 39 | for fieldNo := uint32(0); fieldNo < cardinality; fieldNo++ { 40 | param, err = p.unpackFieldByDefs(reader, requestType, fieldNo, SchemaTypeStr) 41 | if err != nil { 42 | return 43 | } 44 | args = append(args, param) 45 | } //end for 46 | 47 | var tnt16 *tarantool.Connection 48 | if len(args) > 0 { 49 | tnt16 = p.getTnt16Master(args[0]) 50 | } else { 51 | tnt16 = p.getTnt16Master(procName) 52 | } 53 | 54 | response, err = tnt16.Call(procName, args) 55 | p.statsdClient.Incr("call", 1) 56 | if err != nil { 57 | p.statsdClient.Incr("error_16", 1) 58 | } 59 | return 60 | } 61 | -------------------------------------------------------------------------------- /proxy_delete.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/tarantool/go-tarantool" 5 | ) 6 | 7 | func (p *ProxyConnection) executeRequestDelete(requestType uint32, requestID uint32, 8 | reader IprotoReader) (flags uint32, response *tarantool.Response, err error) { 9 | //|--------------- header ----------------|--------- body ---------| 10 | // 11 | var ( 12 | cardinality uint32 13 | spaceNo uint32 14 | param interface{} 15 | args []interface{} 16 | ) 17 | 18 | unpackUint32(reader, &spaceNo) // parse space_no 19 | unpackUint32(reader, &flags) // parse flags 20 | unpackUint32(reader, &cardinality) // parse insert tuple 21 | 22 | space, err := p.schema.GetSpaceInfo(spaceNo) 23 | if err != nil { 24 | return 25 | } 26 | 27 | // tnt15 delete default by indexNo=0 28 | indexName, err := space.GetIndexName(0) 29 | if err != nil { 30 | return 31 | } 32 | 33 | indexDefs, err := space.GetIndexDefs(0) 34 | if err != nil { 35 | return 36 | } 37 | 38 | for fieldNo := uint32(0); fieldNo < cardinality; fieldNo++ { 39 | param, err = p.unpackFieldByDefs(reader, requestType, fieldNo, indexDefs[fieldNo]) 40 | if err != nil { 41 | return 42 | } 43 | args = append(args, param) 44 | } //end for 45 | 46 | tnt16 := p.getTnt16Master(args[0]) 47 | 48 | response, err = tnt16.Delete(space.name, indexName, args) 49 | p.statsdClient.Incr("delete", 1) 50 | if err != nil { 51 | p.statsdClient.Incr("error_16", 1) 52 | } 53 | return 54 | } 55 | -------------------------------------------------------------------------------- /proxy_insert.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/tarantool/go-tarantool" 5 | ) 6 | 7 | func (p *ProxyConnection) executeRequestInsert(requestType uint32, requestID uint32, 8 | reader IprotoReader) (flags uint32, response *tarantool.Response, err error) { 9 | //|--------------- header ----------------|--------- body ---------| 10 | // 11 | var ( 12 | cardinality uint32 13 | spaceNo uint32 14 | args []interface{} 15 | param interface{} 16 | ) 17 | 18 | unpackUint32(reader, &spaceNo) // parse space_no 19 | unpackUint32(reader, &flags) // parse flags 20 | unpackUint32(reader, &cardinality) // parse insert tuple 21 | 22 | space, err := p.schema.GetSpaceInfo(spaceNo) 23 | if err != nil { 24 | return 25 | } 26 | fieldDefs := space.typeFieldsMap 27 | 28 | for fieldNo := uint32(0); fieldNo < cardinality; fieldNo++ { 29 | param, err = p.unpackFieldByDefs(reader, requestType, fieldNo, fieldDefs[fieldNo]) 30 | if err != nil { 31 | return 32 | } 33 | args = append(args, param) 34 | } //end for 35 | 36 | tnt16 := p.getTnt16Master(args[0]) 37 | switch { 38 | case flags&FlagAdd != 0: 39 | response, err = tnt16.Insert(space.name, args) 40 | case flags&FlagReplace != 0: 41 | response, err = tnt16.Replace(space.name, args) 42 | default: 43 | // use upsert default 44 | var upsertArgs []interface{} 45 | for fieldNo, fieldVal := range args { 46 | upsertArgs = append(upsertArgs, []interface{}{"=", fieldNo, fieldVal}) 47 | } 48 | response, err = tnt16.Upsert(space.name, args, upsertArgs) 49 | } 50 | p.statsdClient.Incr("insert", 1) 51 | if err != nil { 52 | p.statsdClient.Incr("error_16", 1) 53 | } 54 | return 55 | } 56 | -------------------------------------------------------------------------------- /proxy_ping.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/tarantool/go-tarantool" 5 | ) 6 | 7 | func (p *ProxyConnection) executeRequestPing(requestType uint32, requestID uint32, 8 | reader IprotoReader) (flags uint32, response *tarantool.Response, err error) { 9 | //Ping body is empty, so body_length == 0 and there's no body 10 | //|--------------- header ----------------| 11 | // 12 | flags = FlagPing 13 | 14 | tnt16 := p.getTnt16Master("ping") 15 | response, err = tnt16.Ping() 16 | p.statsdClient.Incr("ping", 1) 17 | if err != nil { 18 | p.statsdClient.Incr("error_16", 1) 19 | } 20 | return 21 | } 22 | -------------------------------------------------------------------------------- /proxy_select.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/tarantool/go-tarantool" 5 | ) 6 | 7 | func (p *ProxyConnection) executeRequestSelect(requestType uint32, requestID uint32, 8 | reader IprotoReader) (flags uint32, response *tarantool.Response, err error) { 9 | //|--------------- header ----------------|---------------request_body ---------------------...| 10 | // + 11 | var ( 12 | spaceNo uint32 13 | indexNo uint32 14 | offset uint32 15 | limit uint32 16 | count uint32 17 | cardinality uint32 18 | args []interface{} 19 | param interface{} 20 | ) 21 | 22 | unpackUint32(reader, &spaceNo) 23 | unpackUint32(reader, &indexNo) 24 | unpackUint32(reader, &offset) 25 | unpackUint32(reader, &limit) 26 | unpackUint32(reader, &count) 27 | 28 | flags = FlagReturnTuple 29 | 30 | space, err := p.schema.GetSpaceInfo(spaceNo) 31 | if err != nil { 32 | return 33 | } 34 | 35 | indexName, err := space.GetIndexName(indexNo) 36 | if err != nil { 37 | return 38 | } 39 | 40 | indexDefs, err := space.GetIndexDefs(indexNo) 41 | if err != nil { 42 | return 43 | } 44 | 45 | // далее лежат упакованные iproto tuple-ы 46 | for i := uint32(0); i < count; i++ { 47 | err = unpackUint32(reader, &cardinality) 48 | if err != nil { 49 | return 50 | } 51 | 52 | for fieldNo := uint32(0); fieldNo < cardinality; fieldNo++ { 53 | param, err = p.unpackFieldByDefs(reader, requestType, fieldNo, indexDefs[fieldNo]) 54 | if err != nil { 55 | return 56 | } 57 | args = append(args, param) 58 | } //end for 59 | } //end for 60 | 61 | //sharding for key0 62 | tnt16 := p.getTnt16(args[0]) 63 | response, err = tnt16.Select(space.name, indexName, offset, limit, tarantool.IterEq, args) 64 | if err == nil { 65 | p.statsdClient.Incr("select", 1) 66 | return 67 | } 68 | 69 | // make fault tollerance requests 70 | for _, tnt16i := range p.getTnt16Pool(args[0]) { 71 | if tnt16i == tnt16 { 72 | continue 73 | } 74 | 75 | response, err = tnt16i.Select(space.name, indexName, offset, limit, tarantool.IterEq, args) 76 | if err == nil { 77 | p.statsdClient.Incr("select", 1) 78 | break 79 | } 80 | } 81 | p.statsdClient.Incr("error_16", 1) 82 | return 83 | } 84 | -------------------------------------------------------------------------------- /proxy_update.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "github.com/tarantool/go-tarantool" 6 | ) 7 | 8 | func (p *ProxyConnection) executeRequestUpdate(requestType uint32, requestID uint32, 9 | reader IprotoReader) (flags uint32, response *tarantool.Response, err error) { 10 | // |--------------- header ----------------|---------------request_body --------------...| 11 | // + 12 | // | | | 13 | // Key to search in primary index -----+ | +-- list of operations 14 | // (tuple with cardinality=1) +-- number of operations 15 | var ( 16 | cardinality uint32 17 | spaceNo uint32 18 | opCount uint32 19 | opCode uint8 20 | args []interface{} 21 | param interface{} 22 | fieldNo uint32 23 | keyTuple []interface{} 24 | ) 25 | 26 | unpackUint32(reader, &spaceNo) // parse space_no 27 | unpackUint32(reader, &flags) // parse flags 28 | 29 | space, err := p.schema.GetSpaceInfo(spaceNo) 30 | if err != nil { 31 | return 32 | } 33 | fieldDefs := space.typeFieldsMap 34 | 35 | // tnt15 update default by indexNo=0 primary 36 | indexName, err := space.GetIndexName(0) 37 | if err != nil { 38 | return 39 | } 40 | 41 | indexDefs, err := space.GetIndexDefs(0) 42 | if err != nil { 43 | return 44 | } 45 | 46 | unpackUint32(reader, &cardinality) // parse key tuple 47 | 48 | for fieldNo := uint32(0); fieldNo < cardinality; fieldNo++ { 49 | param, err = p.unpackFieldByDefs(reader, requestType, fieldNo, indexDefs[fieldNo]) 50 | if err != nil { 51 | return 52 | } 53 | keyTuple = append(keyTuple, param) 54 | } //end for 55 | 56 | //parse op count 57 | unpackUint32(reader, &opCount) 58 | 59 | //parse op list 60 | for opNo := uint32(0); opNo < opCount; opNo++ { 61 | err = unpackUint32(reader, &fieldNo) 62 | if err != nil { 63 | return 64 | } 65 | 66 | err = unpackUint8(reader, &opCode) 67 | if err != nil { 68 | return 69 | } 70 | 71 | opSymbol, ok := UpdateOperationCode[opCode] 72 | if !ok { 73 | err = fmt.Errorf("error operation code: %d for update request", opCode) 74 | return 75 | } 76 | 77 | param, err = p.unpackFieldByDefs(reader, requestType, fieldNo, fieldDefs[fieldNo]) 78 | if err != nil { 79 | return 80 | } 81 | args = append(args, []interface{}{opSymbol, fieldNo, param}) 82 | } //end for opCount 83 | 84 | tnt16 := p.getTnt16Master(keyTuple[0]) 85 | 86 | response, err = tnt16.Update(space.name, indexName, keyTuple, args) 87 | p.statsdClient.Incr("update", 1) 88 | if err != nil { 89 | p.statsdClient.Incr("error_16", 1) 90 | } 91 | return 92 | } 93 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/LICENSE: -------------------------------------------------------------------------------- 1 | Go support for Protocol Buffers - Google's data interchange format 2 | 3 | Copyright 2010 The Go Authors. All rights reserved. 4 | https://github.com/golang/protobuf 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following disclaimer 14 | in the documentation and/or other materials provided with the 15 | distribution. 16 | * Neither the name of Google Inc. nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/proto/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | install: 33 | go install 34 | 35 | test: install generate-test-pbs 36 | go test 37 | 38 | 39 | generate-test-pbs: 40 | make install 41 | make -C testdata 42 | protoc --go_out=Mtestdata/test.proto=github.com/golang/protobuf/proto/testdata,Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. proto3_proto/proto3.proto 43 | make 44 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/proto/discard.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2017 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package proto 33 | 34 | import ( 35 | "fmt" 36 | "reflect" 37 | "strings" 38 | ) 39 | 40 | // DiscardUnknown recursively discards all unknown fields from this message 41 | // and all embedded messages. 42 | // 43 | // When unmarshaling a message with unrecognized fields, the tags and values 44 | // of such fields are preserved in the Message. This allows a later call to 45 | // marshal to be able to produce a message that continues to have those 46 | // unrecognized fields. To avoid this, DiscardUnknown is used to 47 | // explicitly clear the unknown fields after unmarshaling. 48 | // 49 | // For proto2 messages, the unknown fields of message extensions are only 50 | // discarded from messages that have been accessed via GetExtension. 51 | func DiscardUnknown(m Message) { 52 | discardLegacy(m) 53 | } 54 | 55 | func discardLegacy(m Message) { 56 | v := reflect.ValueOf(m) 57 | if v.Kind() != reflect.Ptr || v.IsNil() { 58 | return 59 | } 60 | v = v.Elem() 61 | if v.Kind() != reflect.Struct { 62 | return 63 | } 64 | t := v.Type() 65 | 66 | for i := 0; i < v.NumField(); i++ { 67 | f := t.Field(i) 68 | if strings.HasPrefix(f.Name, "XXX_") { 69 | continue 70 | } 71 | vf := v.Field(i) 72 | tf := f.Type 73 | 74 | // Unwrap tf to get its most basic type. 75 | var isPointer, isSlice bool 76 | if tf.Kind() == reflect.Slice && tf.Elem().Kind() != reflect.Uint8 { 77 | isSlice = true 78 | tf = tf.Elem() 79 | } 80 | if tf.Kind() == reflect.Ptr { 81 | isPointer = true 82 | tf = tf.Elem() 83 | } 84 | if isPointer && isSlice && tf.Kind() != reflect.Struct { 85 | panic(fmt.Sprintf("%T.%s cannot be a slice of pointers to primitive types", m, f.Name)) 86 | } 87 | 88 | switch tf.Kind() { 89 | case reflect.Struct: 90 | switch { 91 | case !isPointer: 92 | panic(fmt.Sprintf("%T.%s cannot be a direct struct value", m, f.Name)) 93 | case isSlice: // E.g., []*pb.T 94 | for j := 0; j < vf.Len(); j++ { 95 | discardLegacy(vf.Index(j).Interface().(Message)) 96 | } 97 | default: // E.g., *pb.T 98 | discardLegacy(vf.Interface().(Message)) 99 | } 100 | case reflect.Map: 101 | switch { 102 | case isPointer || isSlice: 103 | panic(fmt.Sprintf("%T.%s cannot be a pointer to a map or a slice of map values", m, f.Name)) 104 | default: // E.g., map[K]V 105 | tv := vf.Type().Elem() 106 | if tv.Kind() == reflect.Ptr && tv.Implements(protoMessageType) { // Proto struct (e.g., *T) 107 | for _, key := range vf.MapKeys() { 108 | val := vf.MapIndex(key) 109 | discardLegacy(val.Interface().(Message)) 110 | } 111 | } 112 | } 113 | case reflect.Interface: 114 | // Must be oneof field. 115 | switch { 116 | case isPointer || isSlice: 117 | panic(fmt.Sprintf("%T.%s cannot be a pointer to a interface or a slice of interface values", m, f.Name)) 118 | default: // E.g., test_proto.isCommunique_Union interface 119 | if !vf.IsNil() && f.Tag.Get("protobuf_oneof") != "" { 120 | vf = vf.Elem() // E.g., *test_proto.Communique_Msg 121 | if !vf.IsNil() { 122 | vf = vf.Elem() // E.g., test_proto.Communique_Msg 123 | vf = vf.Field(0) // E.g., Proto struct (e.g., *T) or primitive value 124 | if vf.Kind() == reflect.Ptr { 125 | discardLegacy(vf.Interface().(Message)) 126 | } 127 | } 128 | } 129 | } 130 | } 131 | } 132 | 133 | if vf := v.FieldByName("XXX_unrecognized"); vf.IsValid() { 134 | if vf.Type() != reflect.TypeOf([]byte{}) { 135 | panic("expected XXX_unrecognized to be of type []byte") 136 | } 137 | vf.Set(reflect.ValueOf([]byte(nil))) 138 | } 139 | 140 | // For proto2 messages, only discard unknown fields in message extensions 141 | // that have been accessed via GetExtension. 142 | if em, ok := extendable(m); ok { 143 | // Ignore lock since discardLegacy is not concurrency safe. 144 | emm, _ := em.extensionsRead() 145 | for _, mx := range emm { 146 | if m, ok := mx.value.(Message); ok { 147 | discardLegacy(m) 148 | } 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /vendor/github.com/quipo/statsd/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.8.x 5 | - master 6 | -------------------------------------------------------------------------------- /vendor/github.com/quipo/statsd/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Lorenzo Alberton 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /vendor/github.com/quipo/statsd/README.md: -------------------------------------------------------------------------------- 1 | # StatsD client (Golang) 2 | 3 | [![Build Status](https://travis-ci.org/quipo/statsd.png?branch=master)](https://travis-ci.org/quipo/statsd) 4 | [![GoDoc](https://godoc.org/github.com/quipo/statsd?status.png)](http://godoc.org/github.com/quipo/statsd) 5 | 6 | ## Introduction 7 | 8 | Go Client library for [StatsD](https://github.com/etsy/statsd/). Contains a direct and a buffered client. 9 | The buffered version will hold and aggregate values for the same key in memory before flushing them at the defined frequency. 10 | 11 | This client library was inspired by the one embedded in the [Bit.ly NSQ](https://github.com/bitly/nsq/blob/master/util/statsd_client.go) project, and extended to support some extra custom events used at DataSift. 12 | 13 | ## Installation 14 | 15 | go get github.com/quipo/statsd 16 | 17 | ## Supported event types 18 | 19 | * `Increment` - Count occurrences per second/minute of a specific event 20 | * `Decrement` - Count occurrences per second/minute of a specific event 21 | * `Timing` - To track a duration event 22 | * `PrecisionTiming - To track a duration event 23 | * `Gauge` (int) / `FGauge` (float) - Gauges are a constant data type. They are not subject to averaging, and they don’t change unless you change them. That is, once you set a gauge value, it will be a flat line on the graph until you change it again 24 | * `GaugeDelta` (int) / `FGaugeDelta` (float) - Same as above, but as a delta change to the previous value rather than a new absolute value 25 | * `Absolute` (int) / `FAbsolute` (float) - Absolute-valued metric (not averaged/aggregated) 26 | * `Total` - Continously increasing value, e.g. read operations since boot 27 | 28 | 29 | ## Sample usage 30 | 31 | ```go 32 | package main 33 | 34 | import ( 35 | "log" 36 | "os" 37 | "time" 38 | 39 | "github.com/quipo/statsd" 40 | ) 41 | 42 | func main() { 43 | // init 44 | prefix := "myproject." 45 | statsdclient := statsd.NewStatsdClient("localhost:8125", prefix) 46 | err := statsdclient.CreateSocket() 47 | if nil != err { 48 | log.Println(err) 49 | os.Exit(1) 50 | } 51 | interval := time.Second * 2 // aggregate stats and flush every 2 seconds 52 | stats := statsd.NewStatsdBuffer(interval, statsdclient) 53 | defer stats.Close() 54 | 55 | // not buffered: send immediately 56 | statsdclient.Incr("mymetric", 4) 57 | 58 | // buffered: aggregate in memory before flushing 59 | stats.Incr("mymetric", 1) 60 | stats.Incr("mymetric", 3) 61 | stats.Incr("mymetric", 1) 62 | stats.Incr("mymetric", 1) 63 | } 64 | ``` 65 | 66 | The string `%HOST%` in the metric name will automatically be replaced with the hostname of the server the event is sent from. 67 | 68 | 69 | ## [Changelog](https://github.com/quipo/statsd/releases) 70 | 71 | * `HEAD`: 72 | 73 | * Fixed behaviour of Gauge with positive numbers: the previous behaviour was the same as GaugeDelta 74 | (FGauge already had the correct behaviour) 75 | * Added more tests 76 | * Small optimisation: replace string formatting with concatenation (thanks to @agnivade) 77 | 78 | * [`v.1.3.0`](https://github.com/quipo/statsd/releases/tag/v.1.3.0): 79 | 80 | * Added stdout client ("echo" service for debugging) 81 | * Fixed [issue #23](https://github.com/quipo/statsd/issues/23): GaugeDelta event Stats() should not send an absolute value of 0 82 | * Fixed FGauge's collation in the buffered client to only preserve the last value in the batch (it mistakenly had the same implementation of FGaugeDelta's collation) 83 | * Fixed FGaugeDelta with negative value not to send a 0 value first (it mistakenly had the same implementation of FGauge) 84 | * Added many tests 85 | * Added compile-time checks that the default events implement the Event interface 86 | 87 | * [`v.1.2.0`](https://github.com/quipo/statsd/releases/tag/1.2.0): Sample rate support (thanks to [Hongjian Zhu](https://github.com/hongjianzhu)) 88 | * [`v.1.1.0`](https://github.com/quipo/statsd/releases/tag/1.1.0): 89 | 90 | * Added `SendEvents` function to `Statsd` interface; 91 | * Using interface in buffered client constructor; 92 | * Added/Fixed tests 93 | 94 | * [`v.1.0.0`](https://github.com/quipo/statsd/releases/tag/1.0.0): First stable release 95 | * `v.0.0.9`: Added memoization to reduce memory allocations 96 | * `v.0.0.8`: Pre-release 97 | 98 | ## Author 99 | 100 | Lorenzo Alberton 101 | 102 | * Web: [http://alberton.info](http://alberton.info) 103 | * Twitter: [@lorenzoalberton](https://twitter.com/lorenzoalberton) 104 | * Linkedin: [/in/lorenzoalberton](https://www.linkedin.com/in/lorenzoalberton) 105 | 106 | 107 | ## Copyright 108 | 109 | See [LICENSE](LICENSE) document 110 | -------------------------------------------------------------------------------- /vendor/github.com/quipo/statsd/event/absolute.go: -------------------------------------------------------------------------------- 1 | package event 2 | 3 | import "fmt" 4 | 5 | // Absolute is a metric that is not averaged/aggregated. 6 | // We keep each value distinct and then we flush them all individually. 7 | type Absolute struct { 8 | Name string 9 | Values []int64 10 | } 11 | 12 | // Update the event with metrics coming from a new one of the same type and with the same key 13 | func (e *Absolute) Update(e2 Event) error { 14 | if e.Type() != e2.Type() { 15 | return fmt.Errorf("statsd event type conflict: %s vs %s ", e.String(), e2.String()) 16 | } 17 | e.Values = append(e.Values, e2.Payload().([]int64)...) 18 | return nil 19 | } 20 | 21 | // Payload returns the aggregated value for this event 22 | func (e Absolute) Payload() interface{} { 23 | return e.Values 24 | } 25 | 26 | // Stats returns an array of StatsD events as they travel over UDP 27 | func (e Absolute) Stats() []string { 28 | ret := make([]string, 0, len(e.Values)) 29 | for _, v := range e.Values { 30 | ret = append(ret, fmt.Sprintf("%s:%d|a", e.Name, v)) 31 | } 32 | return ret 33 | } 34 | 35 | // Key returns the name of this metric 36 | func (e Absolute) Key() string { 37 | return e.Name 38 | } 39 | 40 | // SetKey sets the name of this metric 41 | func (e *Absolute) SetKey(key string) { 42 | e.Name = key 43 | } 44 | 45 | // Type returns an integer identifier for this type of metric 46 | func (e Absolute) Type() int { 47 | return EventAbsolute 48 | } 49 | 50 | // TypeString returns a name for this type of metric 51 | func (e Absolute) TypeString() string { 52 | return "Absolute" 53 | } 54 | 55 | // String returns a debug-friendly representation of this metric 56 | func (e Absolute) String() string { 57 | return fmt.Sprintf("{Type: %s, Key: %s, Values: %v}", e.TypeString(), e.Name, e.Values) 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/quipo/statsd/event/fabsolute.go: -------------------------------------------------------------------------------- 1 | package event 2 | 3 | import "fmt" 4 | 5 | // FAbsolute is a metric that is not averaged/aggregated. 6 | // We keep each value distinct and then we flush them all individually. 7 | type FAbsolute struct { 8 | Name string 9 | Values []float64 10 | } 11 | 12 | // Update the event with metrics coming from a new one of the same type and with the same key 13 | func (e *FAbsolute) Update(e2 Event) error { 14 | if e.Type() != e2.Type() { 15 | return fmt.Errorf("statsd event type conflict: %s vs %s ", e.String(), e2.String()) 16 | } 17 | e.Values = append(e.Values, e2.Payload().([]float64)...) 18 | return nil 19 | } 20 | 21 | // Payload returns the aggregated value for this event 22 | func (e FAbsolute) Payload() interface{} { 23 | return e.Values 24 | } 25 | 26 | // Stats returns an array of StatsD events as they travel over UDP 27 | func (e FAbsolute) Stats() []string { 28 | ret := make([]string, 0, len(e.Values)) 29 | for _, v := range e.Values { 30 | ret = append(ret, fmt.Sprintf("%s:%g|a", e.Name, v)) 31 | } 32 | return ret 33 | } 34 | 35 | // Key returns the name of this metric 36 | func (e FAbsolute) Key() string { 37 | return e.Name 38 | } 39 | 40 | // SetKey sets the name of this metric 41 | func (e *FAbsolute) SetKey(key string) { 42 | e.Name = key 43 | } 44 | 45 | // Type returns an integer identifier for this type of metric 46 | func (e FAbsolute) Type() int { 47 | return EventFAbsolute 48 | } 49 | 50 | // TypeString returns a name for this type of metric 51 | func (e FAbsolute) TypeString() string { 52 | return "FAbsolute" 53 | } 54 | 55 | // String returns a debug-friendly representation of this metric 56 | func (e FAbsolute) String() string { 57 | return fmt.Sprintf("{Type: %s, Key: %s, Values: %v}", e.TypeString(), e.Name, e.Values) 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/quipo/statsd/event/fgauge.go: -------------------------------------------------------------------------------- 1 | package event 2 | 3 | import "fmt" 4 | 5 | // FGauge - Gauges are a constant data type. They are not subject to averaging, 6 | // and they don’t change unless you change them. That is, once you set a gauge value, 7 | // it will be a flat line on the graph until you change it again 8 | type FGauge struct { 9 | Name string 10 | Value float64 11 | } 12 | 13 | // Update the event with metrics coming from a new one of the same type and with the same key 14 | func (e *FGauge) Update(e2 Event) error { 15 | if e.Type() != e2.Type() { 16 | return fmt.Errorf("statsd event type conflict: %s vs %s ", e.String(), e2.String()) 17 | } 18 | e.Value = e2.Payload().(float64) 19 | return nil 20 | } 21 | 22 | // Payload returns the aggregated value for this event 23 | func (e FGauge) Payload() interface{} { 24 | return e.Value 25 | } 26 | 27 | // Stats returns an array of StatsD events as they travel over UDP 28 | func (e FGauge) Stats() []string { 29 | if e.Value < 0 { 30 | // because a leading '+' or '-' in the value of a gauge denotes a delta, to send 31 | // a negative gauge value we first set the gauge absolutely to 0, then send the 32 | // negative value as a delta from 0 (that's just how the spec works :-) 33 | return []string{ 34 | fmt.Sprintf("%s:%d|g", e.Name, 0), 35 | fmt.Sprintf("%s:%g|g", e.Name, e.Value), 36 | } 37 | } 38 | return []string{fmt.Sprintf("%s:%g|g", e.Name, e.Value)} 39 | } 40 | 41 | // Key returns the name of this metric 42 | func (e FGauge) Key() string { 43 | return e.Name 44 | } 45 | 46 | // SetKey sets the name of this metric 47 | func (e *FGauge) SetKey(key string) { 48 | e.Name = key 49 | } 50 | 51 | // Type returns an integer identifier for this type of metric 52 | func (e FGauge) Type() int { 53 | return EventFGauge 54 | } 55 | 56 | // TypeString returns a name for this type of metric 57 | func (e FGauge) TypeString() string { 58 | return "FGauge" 59 | } 60 | 61 | // String returns a debug-friendly representation of this metric 62 | func (e FGauge) String() string { 63 | return fmt.Sprintf("{Type: %s, Key: %s, Value: %g}", e.TypeString(), e.Name, e.Value) 64 | } 65 | -------------------------------------------------------------------------------- /vendor/github.com/quipo/statsd/event/fgaugedelta.go: -------------------------------------------------------------------------------- 1 | package event 2 | 3 | import "fmt" 4 | 5 | // FGaugeDelta - Gauges are a constant data type. They are not subject to averaging, 6 | // and they don’t change unless you change them. That is, once you set a gauge value, 7 | // it will be a flat line on the graph until you change it again 8 | type FGaugeDelta struct { 9 | Name string 10 | Value float64 11 | } 12 | 13 | // Update the event with metrics coming from a new one of the same type and with the same key 14 | func (e *FGaugeDelta) Update(e2 Event) error { 15 | if e.Type() != e2.Type() { 16 | return fmt.Errorf("statsd event type conflict: %s vs %s ", e.String(), e2.String()) 17 | } 18 | e.Value += e2.Payload().(float64) 19 | return nil 20 | } 21 | 22 | // Payload returns the aggregated value for this event 23 | func (e FGaugeDelta) Payload() interface{} { 24 | return e.Value 25 | } 26 | 27 | // Stats returns an array of StatsD events as they travel over UDP 28 | func (e FGaugeDelta) Stats() []string { 29 | return []string{fmt.Sprintf("%s:%+g|g", e.Name, e.Value)} 30 | } 31 | 32 | // Key returns the name of this metric 33 | func (e FGaugeDelta) Key() string { 34 | return e.Name 35 | } 36 | 37 | // SetKey sets the name of this metric 38 | func (e *FGaugeDelta) SetKey(key string) { 39 | e.Name = key 40 | } 41 | 42 | // Type returns an integer identifier for this type of metric 43 | func (e FGaugeDelta) Type() int { 44 | return EventFGaugeDelta 45 | } 46 | 47 | // TypeString returns a name for this type of metric 48 | func (e FGaugeDelta) TypeString() string { 49 | return "FGaugeDelta" 50 | } 51 | 52 | // String returns a debug-friendly representation of this metric 53 | func (e FGaugeDelta) String() string { 54 | return fmt.Sprintf("{Type: %s, Key: %s, Value: %g}", e.TypeString(), e.Name, e.Value) 55 | } 56 | -------------------------------------------------------------------------------- /vendor/github.com/quipo/statsd/event/gauge.go: -------------------------------------------------------------------------------- 1 | package event 2 | 3 | import "fmt" 4 | 5 | // Gauge - Gauges are a constant data type. They are not subject to averaging, 6 | // and they don’t change unless you change them. That is, once you set a gauge value, 7 | // it will be a flat line on the graph until you change it again 8 | type Gauge struct { 9 | Name string 10 | Value int64 11 | } 12 | 13 | // Update the event with metrics coming from a new one of the same type and with the same key 14 | func (e *Gauge) Update(e2 Event) error { 15 | if e.Type() != e2.Type() { 16 | return fmt.Errorf("statsd event type conflict: %s vs %s ", e.String(), e2.String()) 17 | } 18 | e.Value = e2.Payload().(int64) 19 | return nil 20 | } 21 | 22 | // Payload returns the aggregated value for this event 23 | func (e Gauge) Payload() interface{} { 24 | return e.Value 25 | } 26 | 27 | // Stats returns an array of StatsD events as they travel over UDP 28 | func (e Gauge) Stats() []string { 29 | if e.Value < 0 { 30 | // because a leading '+' or '-' in the value of a gauge denotes a delta, to send 31 | // a negative gauge value we first set the gauge absolutely to 0, then send the 32 | // negative value as a delta from 0 (that's just how the spec works :-) 33 | return []string{ 34 | fmt.Sprintf("%s:%d|g", e.Name, 0), 35 | fmt.Sprintf("%s:%d|g", e.Name, e.Value), 36 | } 37 | } 38 | return []string{fmt.Sprintf("%s:%d|g", e.Name, e.Value)} 39 | } 40 | 41 | // Key returns the name of this metric 42 | func (e Gauge) Key() string { 43 | return e.Name 44 | } 45 | 46 | // SetKey sets the name of this metric 47 | func (e *Gauge) SetKey(key string) { 48 | e.Name = key 49 | } 50 | 51 | // Type returns an integer identifier for this type of metric 52 | func (e Gauge) Type() int { 53 | return EventGauge 54 | } 55 | 56 | // TypeString returns a name for this type of metric 57 | func (e Gauge) TypeString() string { 58 | return "Gauge" 59 | } 60 | 61 | // String returns a debug-friendly representation of this metric 62 | func (e Gauge) String() string { 63 | return fmt.Sprintf("{Type: %s, Key: %s, Value: %d}", e.TypeString(), e.Name, e.Value) 64 | } 65 | -------------------------------------------------------------------------------- /vendor/github.com/quipo/statsd/event/gaugedelta.go: -------------------------------------------------------------------------------- 1 | package event 2 | 3 | import "fmt" 4 | 5 | // GaugeDelta - Gauges are a constant data type. They are not subject to averaging, 6 | // and they don’t change unless you change them. That is, once you set a gauge value, 7 | // it will be a flat line on the graph until you change it again 8 | type GaugeDelta struct { 9 | Name string 10 | Value int64 11 | } 12 | 13 | // Update the event with metrics coming from a new one of the same type and with the same key 14 | func (e *GaugeDelta) Update(e2 Event) error { 15 | if e.Type() != e2.Type() { 16 | return fmt.Errorf("statsd event type conflict: %s vs %s ", e.String(), e2.String()) 17 | } 18 | e.Value += e2.Payload().(int64) 19 | return nil 20 | } 21 | 22 | // Payload returns the aggregated value for this event 23 | func (e GaugeDelta) Payload() interface{} { 24 | return e.Value 25 | } 26 | 27 | // Stats returns an array of StatsD events as they travel over UDP 28 | func (e GaugeDelta) Stats() []string { 29 | return []string{fmt.Sprintf("%s:%+d|g", e.Name, e.Value)} 30 | } 31 | 32 | // Key returns the name of this metric 33 | func (e GaugeDelta) Key() string { 34 | return e.Name 35 | } 36 | 37 | // SetKey sets the name of this metric 38 | func (e *GaugeDelta) SetKey(key string) { 39 | e.Name = key 40 | } 41 | 42 | // Type returns an integer identifier for this type of metric 43 | func (e GaugeDelta) Type() int { 44 | return EventGaugeDelta 45 | } 46 | 47 | // TypeString returns a name for this type of metric 48 | func (e GaugeDelta) TypeString() string { 49 | return "GaugeDelta" 50 | } 51 | 52 | // String returns a debug-friendly representation of this metric 53 | func (e GaugeDelta) String() string { 54 | return fmt.Sprintf("{Type: %s, Key: %s, Value: %d}", e.TypeString(), e.Name, e.Value) 55 | } 56 | -------------------------------------------------------------------------------- /vendor/github.com/quipo/statsd/event/increment.go: -------------------------------------------------------------------------------- 1 | package event 2 | 3 | import "fmt" 4 | 5 | // Increment represents a metric whose value is averaged over a minute 6 | type Increment struct { 7 | Name string 8 | Value int64 9 | } 10 | 11 | // Update the event with metrics coming from a new one of the same type and with the same key 12 | func (e *Increment) Update(e2 Event) error { 13 | if e.Type() != e2.Type() { 14 | return fmt.Errorf("statsd event type conflict: %s vs %s ", e.String(), e2.String()) 15 | } 16 | e.Value += e2.Payload().(int64) 17 | return nil 18 | } 19 | 20 | // Payload returns the aggregated value for this event 21 | func (e Increment) Payload() interface{} { 22 | return e.Value 23 | } 24 | 25 | // Stats returns an array of StatsD events as they travel over UDP 26 | func (e Increment) Stats() []string { 27 | return []string{fmt.Sprintf("%s:%d|c", e.Name, e.Value)} 28 | } 29 | 30 | // Key returns the name of this metric 31 | func (e Increment) Key() string { 32 | return e.Name 33 | } 34 | 35 | // SetKey sets the name of this metric 36 | func (e *Increment) SetKey(key string) { 37 | e.Name = key 38 | } 39 | 40 | // Type returns an integer identifier for this type of metric 41 | func (e Increment) Type() int { 42 | return EventIncr 43 | } 44 | 45 | // TypeString returns a name for this type of metric 46 | func (e Increment) TypeString() string { 47 | return "Increment" 48 | } 49 | 50 | // String returns a debug-friendly representation of this metric 51 | func (e Increment) String() string { 52 | return fmt.Sprintf("{Type: %s, Key: %s, Value: %d}", e.TypeString(), e.Name, e.Value) 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/quipo/statsd/event/interface.go: -------------------------------------------------------------------------------- 1 | package event 2 | 3 | // constant event type identifiers 4 | const ( 5 | EventIncr = iota 6 | EventTiming 7 | EventAbsolute 8 | EventTotal 9 | EventGauge 10 | EventGaugeDelta 11 | EventFGauge 12 | EventFGaugeDelta 13 | EventFAbsolute 14 | EventPrecisionTiming 15 | ) 16 | 17 | // Event is an interface to a generic StatsD event, used by the buffered client collator 18 | type Event interface { 19 | Stats() []string 20 | Type() int 21 | TypeString() string 22 | Payload() interface{} 23 | Update(e2 Event) error 24 | String() string 25 | Key() string 26 | SetKey(string) 27 | } 28 | 29 | // compile-time assertion to verify default events implement the Event interface 30 | func _() { 31 | var _ Event = (*Absolute)(nil) // assert *Absolute implements Event 32 | var _ Event = (*FAbsolute)(nil) // assert *FAbsolute implements Event 33 | var _ Event = (*Gauge)(nil) // assert *Gauge implements Event 34 | var _ Event = (*FGauge)(nil) // assert *FGauge implements Event 35 | var _ Event = (*GaugeDelta)(nil) // assert *GaugeDelta implements Event 36 | var _ Event = (*FGaugeDelta)(nil) // assert *FGaugeDelta implements Event 37 | var _ Event = (*Increment)(nil) // assert *Increment implements Event 38 | var _ Event = (*PrecisionTiming)(nil) // assert *PrecisionTiming implements Event 39 | var _ Event = (*Timing)(nil) // assert *Timing implements Event 40 | var _ Event = (*Total)(nil) // assert *Total implements Event 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/quipo/statsd/event/precisiontiming.go: -------------------------------------------------------------------------------- 1 | package event 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | // PrecisionTiming keeps min/max/avg information about a timer over a certain interval 9 | type PrecisionTiming struct { 10 | Name string 11 | Min time.Duration 12 | Max time.Duration 13 | Value time.Duration 14 | Count int64 15 | } 16 | 17 | // NewPrecisionTiming is a factory for a Timing event, setting the Count to 1 to prevent div_by_0 errors 18 | func NewPrecisionTiming(k string, delta time.Duration) *PrecisionTiming { 19 | return &PrecisionTiming{Name: k, Min: delta, Max: delta, Value: delta, Count: 1} 20 | } 21 | 22 | // Update the event with metrics coming from a new one of the same type and with the same key 23 | func (e *PrecisionTiming) Update(e2 Event) error { 24 | if e.Type() != e2.Type() { 25 | return fmt.Errorf("statsd event type conflict: %s vs %s ", e.String(), e2.String()) 26 | } 27 | p := e2.Payload().(PrecisionTiming) 28 | e.Count += p.Count 29 | e.Value += p.Value 30 | e.Min = time.Duration(minInt64(int64(e.Min), int64(p.Min))) 31 | e.Max = time.Duration(maxInt64(int64(e.Max), int64(p.Min))) 32 | return nil 33 | } 34 | 35 | // Payload returns the aggregated value for this event 36 | func (e PrecisionTiming) Payload() interface{} { 37 | return e 38 | } 39 | 40 | // Stats returns an array of StatsD events as they travel over UDP 41 | func (e PrecisionTiming) Stats() []string { 42 | return []string{ 43 | fmt.Sprintf("%s.count:%d|c", e.Name, e.Count), 44 | fmt.Sprintf("%s.avg:%.6f|ms", e.Name, float64(int64(e.Value)/e.Count)/1000000), // make sure e.Count != 0 45 | fmt.Sprintf("%s.min:%.6f|ms", e.Name, e.durationToMs(e.Min)), 46 | fmt.Sprintf("%s.max:%.6f|ms", e.Name, e.durationToMs(e.Max)), 47 | } 48 | } 49 | 50 | // durationToMs converts time.Duration into the corresponding value in milliseconds 51 | func (e PrecisionTiming) durationToMs(x time.Duration) float64 { 52 | return float64(x) / float64(time.Millisecond) 53 | } 54 | 55 | // Key returns the name of this metric 56 | func (e PrecisionTiming) Key() string { 57 | return e.Name 58 | } 59 | 60 | // SetKey sets the name of this metric 61 | func (e *PrecisionTiming) SetKey(key string) { 62 | e.Name = key 63 | } 64 | 65 | // Type returns an integer identifier for this type of metric 66 | func (e PrecisionTiming) Type() int { 67 | return EventPrecisionTiming 68 | } 69 | 70 | // TypeString returns a name for this type of metric 71 | func (e PrecisionTiming) TypeString() string { 72 | return "PrecisionTiming" 73 | } 74 | 75 | // String returns a debug-friendly representation of this metric 76 | func (e PrecisionTiming) String() string { 77 | return fmt.Sprintf("{Type: %s, Key: %s, Value: %+v}", e.TypeString(), e.Name, e.Payload()) 78 | } 79 | -------------------------------------------------------------------------------- /vendor/github.com/quipo/statsd/event/timing.go: -------------------------------------------------------------------------------- 1 | package event 2 | 3 | import "fmt" 4 | 5 | // Timing keeps min/max/avg information about a timer over a certain interval 6 | type Timing struct { 7 | Name string 8 | Min int64 9 | Max int64 10 | Value int64 11 | Count int64 12 | } 13 | 14 | // NewTiming is a factory for a Timing event, setting the Count to 1 to prevent div_by_0 errors 15 | func NewTiming(k string, delta int64) *Timing { 16 | return &Timing{Name: k, Min: delta, Max: delta, Value: delta, Count: 1} 17 | } 18 | 19 | // Update the event with metrics coming from a new one of the same type and with the same key 20 | func (e *Timing) Update(e2 Event) error { 21 | if e.Type() != e2.Type() { 22 | return fmt.Errorf("statsd event type conflict: %s vs %s ", e.String(), e2.String()) 23 | } 24 | p := e2.Payload().(map[string]int64) 25 | e.Count += p["cnt"] 26 | e.Value += p["val"] 27 | e.Min = minInt64(e.Min, p["min"]) 28 | e.Max = maxInt64(e.Max, p["max"]) 29 | return nil 30 | } 31 | 32 | // Payload returns the aggregated value for this event 33 | func (e Timing) Payload() interface{} { 34 | return map[string]int64{ 35 | "min": e.Min, 36 | "max": e.Max, 37 | "val": e.Value, 38 | "cnt": e.Count, 39 | } 40 | } 41 | 42 | // Stats returns an array of StatsD events as they travel over UDP 43 | func (e Timing) Stats() []string { 44 | return []string{ 45 | fmt.Sprintf("%s.count:%d|c", e.Name, e.Count), 46 | fmt.Sprintf("%s.avg:%d|ms", e.Name, int64(e.Value/e.Count)), // make sure e.Count != 0 47 | fmt.Sprintf("%s.min:%d|ms", e.Name, e.Min), 48 | fmt.Sprintf("%s.max:%d|ms", e.Name, e.Max), 49 | } 50 | } 51 | 52 | // Key returns the name of this metric 53 | func (e Timing) Key() string { 54 | return e.Name 55 | } 56 | 57 | // SetKey sets the name of this metric 58 | func (e *Timing) SetKey(key string) { 59 | e.Name = key 60 | } 61 | 62 | // Type returns an integer identifier for this type of metric 63 | func (e Timing) Type() int { 64 | return EventTiming 65 | } 66 | 67 | // TypeString returns a name for this type of metric 68 | func (e Timing) TypeString() string { 69 | return "Timing" 70 | } 71 | 72 | // String returns a debug-friendly representation of this metric 73 | func (e Timing) String() string { 74 | return fmt.Sprintf("{Type: %s, Key: %s, Value: %+v}", e.TypeString(), e.Name, e.Payload()) 75 | } 76 | 77 | func minInt64(v1, v2 int64) int64 { 78 | if v1 <= v2 { 79 | return v1 80 | } 81 | return v2 82 | } 83 | func maxInt64(v1, v2 int64) int64 { 84 | if v1 >= v2 { 85 | return v1 86 | } 87 | return v2 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/quipo/statsd/event/total.go: -------------------------------------------------------------------------------- 1 | package event 2 | 3 | import "fmt" 4 | 5 | // Total represents a metric that is continously increasing, e.g. read operations since boot 6 | type Total struct { 7 | Name string 8 | Value int64 9 | } 10 | 11 | // Update the event with metrics coming from a new one of the same type and with the same key 12 | func (e *Total) Update(e2 Event) error { 13 | if e.Type() != e2.Type() { 14 | return fmt.Errorf("statsd event type conflict: %s vs %s ", e.String(), e2.String()) 15 | } 16 | e.Value += e2.Payload().(int64) 17 | return nil 18 | } 19 | 20 | // Payload returns the aggregated value for this event 21 | func (e Total) Payload() interface{} { 22 | return e.Value 23 | } 24 | 25 | // Stats returns an array of StatsD events as they travel over UDP 26 | func (e Total) Stats() []string { 27 | return []string{fmt.Sprintf("%s:%d|t", e.Name, e.Value)} 28 | } 29 | 30 | // Key returns the name of this metric 31 | func (e Total) Key() string { 32 | return e.Name 33 | } 34 | 35 | // SetKey sets the name of this metric 36 | func (e *Total) SetKey(key string) { 37 | e.Name = key 38 | } 39 | 40 | // Type returns an integer identifier for this type of metric 41 | func (e Total) Type() int { 42 | return EventTotal 43 | } 44 | 45 | // TypeString returns a name for this type of metric 46 | func (e Total) TypeString() string { 47 | return "Total" 48 | } 49 | 50 | // String returns a debug-friendly representation of this metric 51 | func (e Total) String() string { 52 | return fmt.Sprintf("{Type: %s, Key: %s, Value: %d}", e.TypeString(), e.Name, e.Value) 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/quipo/statsd/interface.go: -------------------------------------------------------------------------------- 1 | package statsd 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/quipo/statsd/event" 7 | ) 8 | 9 | // Statsd is an interface to a StatsD client (buffered/unbuffered) 10 | type Statsd interface { 11 | CreateSocket() error 12 | CreateTCPSocket() error 13 | Close() error 14 | Incr(stat string, count int64) error 15 | Decr(stat string, count int64) error 16 | Timing(stat string, delta int64) error 17 | PrecisionTiming(stat string, delta time.Duration) error 18 | Gauge(stat string, value int64) error 19 | GaugeDelta(stat string, value int64) error 20 | Absolute(stat string, value int64) error 21 | Total(stat string, value int64) error 22 | 23 | FGauge(stat string, value float64) error 24 | FGaugeDelta(stat string, value float64) error 25 | FAbsolute(stat string, value float64) error 26 | 27 | SendEvents(events map[string]event.Event) error 28 | } 29 | -------------------------------------------------------------------------------- /vendor/github.com/quipo/statsd/noopclient.go: -------------------------------------------------------------------------------- 1 | package statsd 2 | 3 | //@author https://github.com/wyndhblb/statsd 4 | 5 | import ( 6 | "time" 7 | 8 | "github.com/quipo/statsd/event" 9 | ) 10 | 11 | // NoopClient implements a "no-op" statsd in case there is no statsd server 12 | type NoopClient struct{} 13 | 14 | // CreateSocket does nothing 15 | func (s NoopClient) CreateSocket() error { 16 | return nil 17 | } 18 | 19 | // CreateTCPSocket does nothing 20 | func (s NoopClient) CreateTCPSocket() error { 21 | return nil 22 | } 23 | 24 | // Close does nothing 25 | func (s NoopClient) Close() error { 26 | return nil 27 | } 28 | 29 | // Incr does nothing 30 | func (s NoopClient) Incr(stat string, count int64) error { 31 | return nil 32 | } 33 | 34 | // Decr does nothing 35 | func (s NoopClient) Decr(stat string, count int64) error { 36 | return nil 37 | } 38 | 39 | // Timing does nothing 40 | func (s NoopClient) Timing(stat string, count int64) error { 41 | return nil 42 | } 43 | 44 | // PrecisionTiming does nothing 45 | func (s NoopClient) PrecisionTiming(stat string, delta time.Duration) error { 46 | return nil 47 | } 48 | 49 | // Gauge does nothing 50 | func (s NoopClient) Gauge(stat string, value int64) error { 51 | return nil 52 | } 53 | 54 | // GaugeDelta does nothing 55 | func (s NoopClient) GaugeDelta(stat string, value int64) error { 56 | return nil 57 | } 58 | 59 | // Absolute does nothing 60 | func (s NoopClient) Absolute(stat string, value int64) error { 61 | return nil 62 | } 63 | 64 | // Total does nothing 65 | func (s NoopClient) Total(stat string, value int64) error { 66 | return nil 67 | } 68 | 69 | // FGauge does nothing 70 | func (s NoopClient) FGauge(stat string, value float64) error { 71 | return nil 72 | } 73 | 74 | // FGaugeDelta does nothing 75 | func (s NoopClient) FGaugeDelta(stat string, value float64) error { 76 | return nil 77 | } 78 | 79 | // FAbsolute does nothing 80 | func (s NoopClient) FAbsolute(stat string, value float64) error { 81 | return nil 82 | } 83 | 84 | // SendEvents does nothing 85 | func (s NoopClient) SendEvents(events map[string]event.Event) error { 86 | return nil 87 | } 88 | -------------------------------------------------------------------------------- /vendor/github.com/tarantool/go-tarantool/.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | *.swp 3 | .idea/ 4 | snap 5 | xlog 6 | -------------------------------------------------------------------------------- /vendor/github.com/tarantool/go-tarantool/LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2014-2017, Tarantool AUTHORS 4 | Copyright (c) 2014-2017, Dmitry Smal 5 | Copyright (c) 2014-2017, Yura Sokolov aka funny_falcon 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright notice, this 12 | list of conditions and the following disclaimer. 13 | 14 | * Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation 16 | and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/tarantool/go-tarantool/auth.go: -------------------------------------------------------------------------------- 1 | package tarantool 2 | 3 | import ( 4 | "crypto/sha1" 5 | "encoding/base64" 6 | ) 7 | 8 | func scramble(encodedSalt, pass string) (scramble []byte, err error) { 9 | /* ================================================================== 10 | According to: http://tarantool.org/doc/dev_guide/box-protocol.html 11 | 12 | salt = base64_decode(encodedSalt); 13 | step1 = sha1(password); 14 | step2 = sha1(step1); 15 | step3 = sha1(salt, step2); 16 | scramble = xor(step1, step3); 17 | return scramble; 18 | 19 | ===================================================================== */ 20 | scrambleSize := sha1.Size // == 20 21 | 22 | salt, err := base64.StdEncoding.DecodeString(encodedSalt) 23 | if err != nil { 24 | return 25 | } 26 | step1 := sha1.Sum([]byte(pass)) 27 | step2 := sha1.Sum(step1[0:]) 28 | hash := sha1.New() // may be create it once per connection ? 29 | hash.Write(salt[0:scrambleSize]) 30 | hash.Write(step2[0:]) 31 | step3 := hash.Sum(nil) 32 | 33 | return xor(step1[0:], step3[0:], scrambleSize), nil 34 | } 35 | 36 | func xor(left, right []byte, size int) []byte { 37 | result := make([]byte, size) 38 | for i := 0; i < size; i++ { 39 | result[i] = left[i] ^ right[i] 40 | } 41 | return result 42 | } 43 | -------------------------------------------------------------------------------- /vendor/github.com/tarantool/go-tarantool/client_tools.go: -------------------------------------------------------------------------------- 1 | package tarantool 2 | 3 | import ( 4 | "gopkg.in/vmihailenco/msgpack.v2" 5 | ) 6 | 7 | // IntKey is utility type for passing integer key to Select*, Update* and Delete* 8 | // It serializes to array with single integer element. 9 | type IntKey struct { 10 | I int 11 | } 12 | 13 | func (k IntKey) EncodeMsgpack(enc *msgpack.Encoder) error { 14 | enc.EncodeSliceLen(1) 15 | enc.EncodeInt(k.I) 16 | return nil 17 | } 18 | 19 | // UintKey is utility type for passing unsigned integer key to Select*, Update* and Delete* 20 | // It serializes to array with single integer element. 21 | type UintKey struct { 22 | I uint 23 | } 24 | 25 | func (k UintKey) EncodeMsgpack(enc *msgpack.Encoder) error { 26 | enc.EncodeSliceLen(1) 27 | enc.EncodeUint(k.I) 28 | return nil 29 | } 30 | 31 | // UintKey is utility type for passing string key to Select*, Update* and Delete* 32 | // It serializes to array with single string element. 33 | type StringKey struct { 34 | S string 35 | } 36 | 37 | func (k StringKey) EncodeMsgpack(enc *msgpack.Encoder) error { 38 | enc.EncodeSliceLen(1) 39 | enc.EncodeString(k.S) 40 | return nil 41 | } 42 | 43 | // IntIntKey is utility type for passing two integer keys to Select*, Update* and Delete* 44 | // It serializes to array with two integer elements 45 | type IntIntKey struct { 46 | I1, I2 int 47 | } 48 | 49 | func (k IntIntKey) EncodeMsgpack(enc *msgpack.Encoder) error { 50 | enc.EncodeSliceLen(2) 51 | enc.EncodeInt(k.I1) 52 | enc.EncodeInt(k.I2) 53 | return nil 54 | } 55 | 56 | // Op - is update operation 57 | type Op struct { 58 | Op string 59 | Field int 60 | Arg interface{} 61 | } 62 | 63 | func (o Op) EncodeMsgpack(enc *msgpack.Encoder) error { 64 | enc.EncodeSliceLen(3) 65 | enc.EncodeString(o.Op) 66 | enc.EncodeInt(o.Field) 67 | return enc.Encode(o.Arg) 68 | } 69 | 70 | type OpSplice struct { 71 | Op string 72 | Field int 73 | Pos int 74 | Len int 75 | Replace string 76 | } 77 | 78 | func (o OpSplice) EncodeMsgpack(enc *msgpack.Encoder) error { 79 | enc.EncodeSliceLen(5) 80 | enc.EncodeString(o.Op) 81 | enc.EncodeInt(o.Field) 82 | enc.EncodeInt(o.Pos) 83 | enc.EncodeInt(o.Len) 84 | enc.EncodeString(o.Replace) 85 | return nil 86 | } 87 | -------------------------------------------------------------------------------- /vendor/github.com/tarantool/go-tarantool/config.lua: -------------------------------------------------------------------------------- 1 | box.cfg{ 2 | listen = 3013, 3 | wal_dir='xlog', 4 | snap_dir='snap', 5 | } 6 | 7 | box.once("init", function() 8 | local s = box.schema.space.create('test', { 9 | id = 512, 10 | if_not_exists = true, 11 | }) 12 | s:create_index('primary', {type = 'tree', parts = {1, 'uint'}, if_not_exists = true}) 13 | 14 | local st = box.schema.space.create('schematest', { 15 | id = 514, 16 | temporary = true, 17 | if_not_exists = true, 18 | field_count = 7, 19 | format = { 20 | {name = "name0", type = "unsigned"}, 21 | {name = "name1", type = "unsigned"}, 22 | {name = "name2", type = "string"}, 23 | {name = "name3", type = "unsigned"}, 24 | {name = "name4", type = "unsigned"}, 25 | {name = "name5", type = "string"}, 26 | }, 27 | }) 28 | st:create_index('primary', { 29 | type = 'hash', 30 | parts = {1, 'uint'}, 31 | unique = true, 32 | if_not_exists = true, 33 | }) 34 | st:create_index('secondary', { 35 | id = 3, 36 | type = 'tree', 37 | unique = false, 38 | parts = { 2, 'uint', 3, 'string' }, 39 | if_not_exists = true, 40 | }) 41 | st:truncate() 42 | 43 | --box.schema.user.grant('guest', 'read,write,execute', 'universe') 44 | box.schema.func.create('box.info') 45 | box.schema.func.create('simple_incr') 46 | 47 | -- auth testing: access control 48 | box.schema.user.create('test', {password = 'test'}) 49 | box.schema.user.grant('test', 'execute', 'universe') 50 | box.schema.user.grant('test', 'read,write', 'space', 'test') 51 | box.schema.user.grant('test', 'read,write', 'space', 'schematest') 52 | end) 53 | 54 | function simple_incr(a) 55 | return a+1 56 | end 57 | 58 | box.space.test:truncate() 59 | local console = require 'console' 60 | console.listen '0.0.0.0:33015' 61 | 62 | --box.schema.user.revoke('guest', 'read,write,execute', 'universe') 63 | 64 | -------------------------------------------------------------------------------- /vendor/github.com/tarantool/go-tarantool/const.go: -------------------------------------------------------------------------------- 1 | package tarantool 2 | 3 | const ( 4 | SelectRequest = 1 5 | InsertRequest = 2 6 | ReplaceRequest = 3 7 | UpdateRequest = 4 8 | DeleteRequest = 5 9 | CallRequest = 6 /* call in 1.6 format */ 10 | AuthRequest = 7 11 | EvalRequest = 8 12 | UpsertRequest = 9 13 | Call17Request = 10 14 | PingRequest = 64 15 | SubscribeRequest = 66 16 | 17 | KeyCode = 0x00 18 | KeySync = 0x01 19 | KeySpaceNo = 0x10 20 | KeyIndexNo = 0x11 21 | KeyLimit = 0x12 22 | KeyOffset = 0x13 23 | KeyIterator = 0x14 24 | KeyKey = 0x20 25 | KeyTuple = 0x21 26 | KeyFunctionName = 0x22 27 | KeyUserName = 0x23 28 | KeyExpression = 0x27 29 | KeyDefTuple = 0x28 30 | KeyData = 0x30 31 | KeyError = 0x31 32 | 33 | // https://github.com/fl00r/go-tarantool-1.6/issues/2 34 | 35 | IterEq = uint32(0) // key == x ASC order 36 | IterReq = uint32(1) // key == x DESC order 37 | IterAll = uint32(2) // all tuples 38 | IterLt = uint32(3) // key < x 39 | IterLe = uint32(4) // key <= x 40 | IterGe = uint32(5) // key >= x 41 | IterGt = uint32(6) // key > x 42 | IterBitsAllSet = uint32(7) // all bits from x are set in key 43 | IterBitsAnySet = uint32(8) // at least one x's bit is set 44 | IterBitsAllNotSet = uint32(9) // all bits are not set 45 | 46 | RLimitDrop = 1 47 | RLimitWait = 2 48 | 49 | OkCode = uint32(0) 50 | ErrorCodeBit = 0x8000 51 | PacketLengthBytes = 5 52 | ) 53 | -------------------------------------------------------------------------------- /vendor/github.com/tarantool/go-tarantool/deadline_io.go: -------------------------------------------------------------------------------- 1 | package tarantool 2 | 3 | import ( 4 | "net" 5 | "time" 6 | ) 7 | 8 | type DeadlineIO struct { 9 | to time.Duration 10 | c net.Conn 11 | } 12 | 13 | func (d *DeadlineIO) Write(b []byte) (n int, err error) { 14 | if d.to > 0 { 15 | d.c.SetWriteDeadline(time.Now().Add(d.to)) 16 | } 17 | n, err = d.c.Write(b) 18 | return 19 | } 20 | 21 | func (d *DeadlineIO) Read(b []byte) (n int, err error) { 22 | if d.to > 0 { 23 | d.c.SetReadDeadline(time.Now().Add(d.to)) 24 | } 25 | n, err = d.c.Read(b) 26 | return 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/tarantool/go-tarantool/response.go: -------------------------------------------------------------------------------- 1 | package tarantool 2 | 3 | import ( 4 | "fmt" 5 | "gopkg.in/vmihailenco/msgpack.v2" 6 | ) 7 | 8 | type Response struct { 9 | RequestId uint32 10 | Code uint32 11 | Error string // error message 12 | // Data contains deserialized data for untyped requests 13 | Data []interface{} 14 | buf smallBuf 15 | } 16 | 17 | func (resp *Response) fill(b []byte) { 18 | resp.buf.b = b 19 | } 20 | 21 | func (resp *Response) smallInt(d *msgpack.Decoder) (i int, err error) { 22 | b, err := resp.buf.ReadByte() 23 | if err != nil { 24 | return 25 | } 26 | if b <= 127 { 27 | return int(b), nil 28 | } 29 | resp.buf.UnreadByte() 30 | return d.DecodeInt() 31 | } 32 | 33 | func (resp *Response) decodeHeader(d *msgpack.Decoder) (err error) { 34 | var l int 35 | d.Reset(&resp.buf) 36 | if l, err = d.DecodeMapLen(); err != nil { 37 | return 38 | } 39 | for ; l > 0; l-- { 40 | var cd int 41 | if cd, err = resp.smallInt(d); err != nil { 42 | return 43 | } 44 | switch cd { 45 | case KeySync: 46 | var rid uint64 47 | if rid, err = d.DecodeUint64(); err != nil { 48 | return 49 | } 50 | resp.RequestId = uint32(rid) 51 | case KeyCode: 52 | var rcode uint64 53 | if rcode, err = d.DecodeUint64(); err != nil { 54 | return 55 | } 56 | resp.Code = uint32(rcode) 57 | default: 58 | if err = d.Skip(); err != nil { 59 | return 60 | } 61 | } 62 | } 63 | return nil 64 | } 65 | 66 | func (resp *Response) decodeBody() (err error) { 67 | if resp.buf.Len() > 2 { 68 | var l int 69 | d := msgpack.NewDecoder(&resp.buf) 70 | if l, err = d.DecodeMapLen(); err != nil { 71 | return err 72 | } 73 | for ; l > 0; l-- { 74 | var cd int 75 | if cd, err = resp.smallInt(d); err != nil { 76 | return err 77 | } 78 | switch cd { 79 | case KeyData: 80 | var res interface{} 81 | var ok bool 82 | if res, err = d.DecodeInterface(); err != nil { 83 | return err 84 | } 85 | if resp.Data, ok = res.([]interface{}); !ok { 86 | return fmt.Errorf("result is not array: %v", res) 87 | } 88 | case KeyError: 89 | if resp.Error, err = d.DecodeString(); err != nil { 90 | return err 91 | } 92 | default: 93 | if err = d.Skip(); err != nil { 94 | return err 95 | } 96 | } 97 | } 98 | if resp.Code != OkCode { 99 | resp.Code &^= ErrorCodeBit 100 | err = Error{resp.Code, resp.Error} 101 | } 102 | } 103 | return 104 | } 105 | 106 | func (resp *Response) decodeBodyTyped(res interface{}) (err error) { 107 | if resp.buf.Len() > 0 { 108 | var l int 109 | d := msgpack.NewDecoder(&resp.buf) 110 | if l, err = d.DecodeMapLen(); err != nil { 111 | return err 112 | } 113 | for ; l > 0; l-- { 114 | var cd int 115 | if cd, err = resp.smallInt(d); err != nil { 116 | return err 117 | } 118 | switch cd { 119 | case KeyData: 120 | if err = d.Decode(res); err != nil { 121 | return err 122 | } 123 | case KeyError: 124 | if resp.Error, err = d.DecodeString(); err != nil { 125 | return err 126 | } 127 | default: 128 | if err = d.Skip(); err != nil { 129 | return err 130 | } 131 | } 132 | } 133 | if resp.Code != OkCode { 134 | resp.Code &^= ErrorCodeBit 135 | err = Error{resp.Code, resp.Error} 136 | } 137 | } 138 | return 139 | } 140 | 141 | // String implements Stringer interface 142 | func (resp *Response) String() (str string) { 143 | if resp.Code == OkCode { 144 | return fmt.Sprintf("<%d OK %v>", resp.RequestId, resp.Data) 145 | } 146 | return fmt.Sprintf("<%d ERR 0x%x %s>", resp.RequestId, resp.Code, resp.Error) 147 | } 148 | 149 | // Tuples converts result of Eval and Call17 to same format 150 | // as other actions returns (ie array of arrays). 151 | func (resp *Response) Tuples() (res [][]interface{}) { 152 | res = make([][]interface{}, len(resp.Data)) 153 | for i, t := range resp.Data { 154 | switch t := t.(type) { 155 | case []interface{}: 156 | res[i] = t 157 | default: 158 | res[i] = []interface{}{t} 159 | } 160 | } 161 | return res 162 | } 163 | -------------------------------------------------------------------------------- /vendor/github.com/tarantool/go-tarantool/smallbuf.go: -------------------------------------------------------------------------------- 1 | package tarantool 2 | 3 | import ( 4 | "errors" 5 | "io" 6 | ) 7 | 8 | type smallBuf struct { 9 | b []byte 10 | p int 11 | } 12 | 13 | func (s *smallBuf) Read(d []byte) (l int, err error) { 14 | l = len(s.b) - s.p 15 | if l == 0 && len(d) > 0 { 16 | return 0, io.EOF 17 | } 18 | if l > len(d) { 19 | l = len(d) 20 | } 21 | copy(d, s.b[s.p:]) 22 | s.p += l 23 | return l, nil 24 | } 25 | 26 | func (s *smallBuf) ReadByte() (b byte, err error) { 27 | if s.p == len(s.b) { 28 | return 0, io.EOF 29 | } 30 | b = s.b[s.p] 31 | s.p++ 32 | return b, nil 33 | } 34 | 35 | func (s *smallBuf) UnreadByte() error { 36 | if s.p == 0 { 37 | return errors.New("Could not unread") 38 | } 39 | s.p-- 40 | return nil 41 | } 42 | 43 | func (s *smallBuf) Len() int { 44 | return len(s.b) - s.p 45 | } 46 | 47 | func (s *smallBuf) Bytes() []byte { 48 | if len(s.b) > s.p { 49 | return s.b[s.p:] 50 | } 51 | return nil 52 | } 53 | 54 | type smallWBuf []byte 55 | 56 | func (s *smallWBuf) Write(b []byte) (int, error) { 57 | *s = append(*s, b...) 58 | return len(b), nil 59 | } 60 | 61 | func (s *smallWBuf) WriteByte(b byte) error { 62 | *s = append(*s, b) 63 | return nil 64 | } 65 | 66 | func (s *smallWBuf) WriteString(ss string) (int, error) { 67 | *s = append(*s, ss...) 68 | return len(ss), nil 69 | } 70 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/context/context.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package context defines the Context type, which carries deadlines, 6 | // cancelation signals, and other request-scoped values across API boundaries 7 | // and between processes. 8 | // As of Go 1.7 this package is available in the standard library under the 9 | // name context. https://golang.org/pkg/context. 10 | // 11 | // Incoming requests to a server should create a Context, and outgoing calls to 12 | // servers should accept a Context. The chain of function calls between must 13 | // propagate the Context, optionally replacing it with a modified copy created 14 | // using WithDeadline, WithTimeout, WithCancel, or WithValue. 15 | // 16 | // Programs that use Contexts should follow these rules to keep interfaces 17 | // consistent across packages and enable static analysis tools to check context 18 | // propagation: 19 | // 20 | // Do not store Contexts inside a struct type; instead, pass a Context 21 | // explicitly to each function that needs it. The Context should be the first 22 | // parameter, typically named ctx: 23 | // 24 | // func DoSomething(ctx context.Context, arg Arg) error { 25 | // // ... use ctx ... 26 | // } 27 | // 28 | // Do not pass a nil Context, even if a function permits it. Pass context.TODO 29 | // if you are unsure about which Context to use. 30 | // 31 | // Use context Values only for request-scoped data that transits processes and 32 | // APIs, not for passing optional parameters to functions. 33 | // 34 | // The same Context may be passed to functions running in different goroutines; 35 | // Contexts are safe for simultaneous use by multiple goroutines. 36 | // 37 | // See http://blog.golang.org/context for example code for a server that uses 38 | // Contexts. 39 | package context // import "golang.org/x/net/context" 40 | 41 | // Background returns a non-nil, empty Context. It is never canceled, has no 42 | // values, and has no deadline. It is typically used by the main function, 43 | // initialization, and tests, and as the top-level Context for incoming 44 | // requests. 45 | func Background() Context { 46 | return background 47 | } 48 | 49 | // TODO returns a non-nil, empty Context. Code should use context.TODO when 50 | // it's unclear which Context to use or it is not yet available (because the 51 | // surrounding function has not yet been extended to accept a Context 52 | // parameter). TODO is recognized by static analysis tools that determine 53 | // whether Contexts are propagated correctly in a program. 54 | func TODO() Context { 55 | return todo 56 | } 57 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/context/go17.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.7 6 | 7 | package context 8 | 9 | import ( 10 | "context" // standard library's context, as of Go 1.7 11 | "time" 12 | ) 13 | 14 | var ( 15 | todo = context.TODO() 16 | background = context.Background() 17 | ) 18 | 19 | // Canceled is the error returned by Context.Err when the context is canceled. 20 | var Canceled = context.Canceled 21 | 22 | // DeadlineExceeded is the error returned by Context.Err when the context's 23 | // deadline passes. 24 | var DeadlineExceeded = context.DeadlineExceeded 25 | 26 | // WithCancel returns a copy of parent with a new Done channel. The returned 27 | // context's Done channel is closed when the returned cancel function is called 28 | // or when the parent context's Done channel is closed, whichever happens first. 29 | // 30 | // Canceling this context releases resources associated with it, so code should 31 | // call cancel as soon as the operations running in this Context complete. 32 | func WithCancel(parent Context) (ctx Context, cancel CancelFunc) { 33 | ctx, f := context.WithCancel(parent) 34 | return ctx, CancelFunc(f) 35 | } 36 | 37 | // WithDeadline returns a copy of the parent context with the deadline adjusted 38 | // to be no later than d. If the parent's deadline is already earlier than d, 39 | // WithDeadline(parent, d) is semantically equivalent to parent. The returned 40 | // context's Done channel is closed when the deadline expires, when the returned 41 | // cancel function is called, or when the parent context's Done channel is 42 | // closed, whichever happens first. 43 | // 44 | // Canceling this context releases resources associated with it, so code should 45 | // call cancel as soon as the operations running in this Context complete. 46 | func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) { 47 | ctx, f := context.WithDeadline(parent, deadline) 48 | return ctx, CancelFunc(f) 49 | } 50 | 51 | // WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)). 52 | // 53 | // Canceling this context releases resources associated with it, so code should 54 | // call cancel as soon as the operations running in this Context complete: 55 | // 56 | // func slowOperationWithTimeout(ctx context.Context) (Result, error) { 57 | // ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond) 58 | // defer cancel() // releases resources if slowOperation completes before timeout elapses 59 | // return slowOperation(ctx) 60 | // } 61 | func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) { 62 | return WithDeadline(parent, time.Now().Add(timeout)) 63 | } 64 | 65 | // WithValue returns a copy of parent in which the value associated with key is 66 | // val. 67 | // 68 | // Use context Values only for request-scoped data that transits processes and 69 | // APIs, not for passing optional parameters to functions. 70 | func WithValue(parent Context, key interface{}, val interface{}) Context { 71 | return context.WithValue(parent, key, val) 72 | } 73 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/context/go19.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.9 6 | 7 | package context 8 | 9 | import "context" // standard library's context, as of Go 1.7 10 | 11 | // A Context carries a deadline, a cancelation signal, and other values across 12 | // API boundaries. 13 | // 14 | // Context's methods may be called by multiple goroutines simultaneously. 15 | type Context = context.Context 16 | 17 | // A CancelFunc tells an operation to abandon its work. 18 | // A CancelFunc does not wait for the work to stop. 19 | // After the first call, subsequent calls to a CancelFunc do nothing. 20 | type CancelFunc = context.CancelFunc 21 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/context/pre_go19.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.9 6 | 7 | package context 8 | 9 | import "time" 10 | 11 | // A Context carries a deadline, a cancelation signal, and other values across 12 | // API boundaries. 13 | // 14 | // Context's methods may be called by multiple goroutines simultaneously. 15 | type Context interface { 16 | // Deadline returns the time when work done on behalf of this context 17 | // should be canceled. Deadline returns ok==false when no deadline is 18 | // set. Successive calls to Deadline return the same results. 19 | Deadline() (deadline time.Time, ok bool) 20 | 21 | // Done returns a channel that's closed when work done on behalf of this 22 | // context should be canceled. Done may return nil if this context can 23 | // never be canceled. Successive calls to Done return the same value. 24 | // 25 | // WithCancel arranges for Done to be closed when cancel is called; 26 | // WithDeadline arranges for Done to be closed when the deadline 27 | // expires; WithTimeout arranges for Done to be closed when the timeout 28 | // elapses. 29 | // 30 | // Done is provided for use in select statements: 31 | // 32 | // // Stream generates values with DoSomething and sends them to out 33 | // // until DoSomething returns an error or ctx.Done is closed. 34 | // func Stream(ctx context.Context, out chan<- Value) error { 35 | // for { 36 | // v, err := DoSomething(ctx) 37 | // if err != nil { 38 | // return err 39 | // } 40 | // select { 41 | // case <-ctx.Done(): 42 | // return ctx.Err() 43 | // case out <- v: 44 | // } 45 | // } 46 | // } 47 | // 48 | // See http://blog.golang.org/pipelines for more examples of how to use 49 | // a Done channel for cancelation. 50 | Done() <-chan struct{} 51 | 52 | // Err returns a non-nil error value after Done is closed. Err returns 53 | // Canceled if the context was canceled or DeadlineExceeded if the 54 | // context's deadline passed. No other values for Err are defined. 55 | // After Done is closed, successive calls to Err return the same value. 56 | Err() error 57 | 58 | // Value returns the value associated with this context for key, or nil 59 | // if no value is associated with key. Successive calls to Value with 60 | // the same key returns the same result. 61 | // 62 | // Use context values only for request-scoped data that transits 63 | // processes and API boundaries, not for passing optional parameters to 64 | // functions. 65 | // 66 | // A key identifies a specific value in a Context. Functions that wish 67 | // to store values in Context typically allocate a key in a global 68 | // variable then use that key as the argument to context.WithValue and 69 | // Context.Value. A key can be any type that supports equality; 70 | // packages should define keys as an unexported type to avoid 71 | // collisions. 72 | // 73 | // Packages that define a Context key should provide type-safe accessors 74 | // for the values stores using that key: 75 | // 76 | // // Package user defines a User type that's stored in Contexts. 77 | // package user 78 | // 79 | // import "golang.org/x/net/context" 80 | // 81 | // // User is the type of value stored in the Contexts. 82 | // type User struct {...} 83 | // 84 | // // key is an unexported type for keys defined in this package. 85 | // // This prevents collisions with keys defined in other packages. 86 | // type key int 87 | // 88 | // // userKey is the key for user.User values in Contexts. It is 89 | // // unexported; clients use user.NewContext and user.FromContext 90 | // // instead of using this key directly. 91 | // var userKey key = 0 92 | // 93 | // // NewContext returns a new Context that carries value u. 94 | // func NewContext(ctx context.Context, u *User) context.Context { 95 | // return context.WithValue(ctx, userKey, u) 96 | // } 97 | // 98 | // // FromContext returns the User value stored in ctx, if any. 99 | // func FromContext(ctx context.Context) (*User, bool) { 100 | // u, ok := ctx.Value(userKey).(*User) 101 | // return u, ok 102 | // } 103 | Value(key interface{}) interface{} 104 | } 105 | 106 | // A CancelFunc tells an operation to abandon its work. 107 | // A CancelFunc does not wait for the work to stop. 108 | // After the first call, subsequent calls to a CancelFunc do nothing. 109 | type CancelFunc func() 110 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.6.3 5 | - 1.7.1 6 | 7 | install: 8 | - go get -v -t -d google.golang.org/appengine/... 9 | - mkdir sdk 10 | - curl -o sdk.zip "https://storage.googleapis.com/appengine-sdks/featured/go_appengine_sdk_linux_amd64-1.9.40.zip" 11 | - unzip -q sdk.zip -d sdk 12 | - export APPENGINE_DEV_APPSERVER=$(pwd)/sdk/go_appengine/dev_appserver.py 13 | 14 | script: 15 | - go version 16 | - go test -v google.golang.org/appengine/... 17 | - go test -v -race google.golang.org/appengine/... 18 | - sdk/go_appengine/goapp test -v google.golang.org/appengine/... 19 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/README.md: -------------------------------------------------------------------------------- 1 | # Go App Engine packages 2 | 3 | [![Build Status](https://travis-ci.org/golang/appengine.svg)](https://travis-ci.org/golang/appengine) 4 | 5 | This repository supports the Go runtime on App Engine, 6 | including both the standard App Engine and the 7 | "App Engine flexible environment" (formerly known as "Managed VMs"). 8 | It provides APIs for interacting with App Engine services. 9 | Its canonical import path is `google.golang.org/appengine`. 10 | 11 | See https://cloud.google.com/appengine/docs/go/ 12 | for more information. 13 | 14 | File issue reports and feature requests on the [Google App Engine issue 15 | tracker](https://code.google.com/p/googleappengine/issues/entry?template=Go%20defect). 16 | 17 | ## Directory structure 18 | The top level directory of this repository is the `appengine` package. It 19 | contains the 20 | basic APIs (e.g. `appengine.NewContext`) that apply across APIs. Specific API 21 | packages are in subdirectories (e.g. `datastore`). 22 | 23 | There is an `internal` subdirectory that contains service protocol buffers, 24 | plus packages required for connectivity to make API calls. App Engine apps 25 | should not directly import any package under `internal`. 26 | 27 | ## Updating a Go App Engine app 28 | 29 | This section describes how to update an older Go App Engine app to use 30 | these packages. A provided tool, `aefix`, can help automate steps 2 and 3 31 | (run `go get google.golang.org/appengine/cmd/aefix` to install it), but 32 | read the details below since `aefix` can't perform all the changes. 33 | 34 | ### 1. Update YAML files (App Engine flexible environment / Managed VMs only) 35 | 36 | The `app.yaml` file (and YAML files for modules) should have these new lines added: 37 | ``` 38 | vm: true 39 | ``` 40 | See https://cloud.google.com/appengine/docs/go/modules/#Go_Instance_scaling_and_class for details. 41 | 42 | ### 2. Update import paths 43 | 44 | The import paths for App Engine packages are now fully qualified, based at `google.golang.org/appengine`. 45 | You will need to update your code to use import paths starting with that; for instance, 46 | code importing `appengine/datastore` will now need to import `google.golang.org/appengine/datastore`. 47 | 48 | ### 3. Update code using deprecated, removed or modified APIs 49 | 50 | Most App Engine services are available with exactly the same API. 51 | A few APIs were cleaned up, and some are not available yet. 52 | This list summarises the differences: 53 | 54 | * `appengine.Context` has been replaced with the `Context` type from `golang.org/x/net/context`. 55 | * Logging methods that were on `appengine.Context` are now functions in `google.golang.org/appengine/log`. 56 | * `appengine.Timeout` has been removed. Use `context.WithTimeout` instead. 57 | * `appengine.Datacenter` now takes a `context.Context` argument. 58 | * `datastore.PropertyLoadSaver` has been simplified to use slices in place of channels. 59 | * `delay.Call` now returns an error. 60 | * `search.FieldLoadSaver` now handles document metadata. 61 | * `urlfetch.Transport` no longer has a Deadline field; set a deadline on the 62 | `context.Context` instead. 63 | * `aetest` no longer declares its own Context type, and uses the standard one instead. 64 | * `taskqueue.QueueStats` no longer takes a maxTasks argument. That argument has been 65 | deprecated and unused for a long time. 66 | * `appengine.BackendHostname` and `appengine.BackendInstance` were for the deprecated backends feature. 67 | Use `appengine.ModuleHostname`and `appengine.ModuleName` instead. 68 | * Most of `appengine/file` and parts of `appengine/blobstore` are deprecated. 69 | Use [Google Cloud Storage](https://godoc.org/cloud.google.com/go/storage) if the 70 | feature you require is not present in the new 71 | [blobstore package](https://google.golang.org/appengine/blobstore). 72 | * `appengine/socket` is not required on App Engine flexible environment / Managed VMs. 73 | Use the standard `net` package instead. 74 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/appengine.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package appengine provides basic functionality for Google App Engine. 6 | // 7 | // For more information on how to write Go apps for Google App Engine, see: 8 | // https://cloud.google.com/appengine/docs/go/ 9 | package appengine // import "google.golang.org/appengine" 10 | 11 | import ( 12 | "net/http" 13 | 14 | "github.com/golang/protobuf/proto" 15 | "golang.org/x/net/context" 16 | 17 | "google.golang.org/appengine/internal" 18 | ) 19 | 20 | // The gophers party all night; the rabbits provide the beats. 21 | 22 | // Main is the principal entry point for an app running in App Engine. 23 | // 24 | // On App Engine Flexible it installs a trivial health checker if one isn't 25 | // already registered, and starts listening on port 8080 (overridden by the 26 | // $PORT environment variable). 27 | // 28 | // See https://cloud.google.com/appengine/docs/flexible/custom-runtimes#health_check_requests 29 | // for details on how to do your own health checking. 30 | // 31 | // Main is not yet supported on App Engine Standard. 32 | // 33 | // Main never returns. 34 | // 35 | // Main is designed so that the app's main package looks like this: 36 | // 37 | // package main 38 | // 39 | // import ( 40 | // "google.golang.org/appengine" 41 | // 42 | // _ "myapp/package0" 43 | // _ "myapp/package1" 44 | // ) 45 | // 46 | // func main() { 47 | // appengine.Main() 48 | // } 49 | // 50 | // The "myapp/packageX" packages are expected to register HTTP handlers 51 | // in their init functions. 52 | func Main() { 53 | internal.Main() 54 | } 55 | 56 | // IsDevAppServer reports whether the App Engine app is running in the 57 | // development App Server. 58 | func IsDevAppServer() bool { 59 | return internal.IsDevAppServer() 60 | } 61 | 62 | // NewContext returns a context for an in-flight HTTP request. 63 | // This function is cheap. 64 | func NewContext(req *http.Request) context.Context { 65 | return WithContext(context.Background(), req) 66 | } 67 | 68 | // WithContext returns a copy of the parent context 69 | // and associates it with an in-flight HTTP request. 70 | // This function is cheap. 71 | func WithContext(parent context.Context, req *http.Request) context.Context { 72 | return internal.WithContext(parent, req) 73 | } 74 | 75 | // TODO(dsymonds): Add a Call function here? Otherwise other packages can't access internal.Call. 76 | 77 | // BlobKey is a key for a blobstore blob. 78 | // 79 | // Conceptually, this type belongs in the blobstore package, but it lives in 80 | // the appengine package to avoid a circular dependency: blobstore depends on 81 | // datastore, and datastore needs to refer to the BlobKey type. 82 | type BlobKey string 83 | 84 | // GeoPoint represents a location as latitude/longitude in degrees. 85 | type GeoPoint struct { 86 | Lat, Lng float64 87 | } 88 | 89 | // Valid returns whether a GeoPoint is within [-90, 90] latitude and [-180, 180] longitude. 90 | func (g GeoPoint) Valid() bool { 91 | return -90 <= g.Lat && g.Lat <= 90 && -180 <= g.Lng && g.Lng <= 180 92 | } 93 | 94 | // APICallFunc defines a function type for handling an API call. 95 | // See WithCallOverride. 96 | type APICallFunc func(ctx context.Context, service, method string, in, out proto.Message) error 97 | 98 | // WithAPICallFunc returns a copy of the parent context 99 | // that will cause API calls to invoke f instead of their normal operation. 100 | // 101 | // This is intended for advanced users only. 102 | func WithAPICallFunc(ctx context.Context, f APICallFunc) context.Context { 103 | return internal.WithCallOverride(ctx, internal.CallOverrideFunc(f)) 104 | } 105 | 106 | // APICall performs an API call. 107 | // 108 | // This is not intended for general use; it is exported for use in conjunction 109 | // with WithAPICallFunc. 110 | func APICall(ctx context.Context, service, method string, in, out proto.Message) error { 111 | return internal.Call(ctx, service, method, in, out) 112 | } 113 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/appengine_vm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !appengine 6 | 7 | package appengine 8 | 9 | import ( 10 | "golang.org/x/net/context" 11 | 12 | "google.golang.org/appengine/internal" 13 | ) 14 | 15 | // BackgroundContext returns a context not associated with a request. 16 | // This should only be used when not servicing a request. 17 | // This only works in App Engine "flexible environment". 18 | func BackgroundContext() context.Context { 19 | return internal.BackgroundContext() 20 | } 21 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/datastore/metadata.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | package datastore 6 | 7 | import "golang.org/x/net/context" 8 | 9 | // Datastore kinds for the metadata entities. 10 | const ( 11 | namespaceKind = "__namespace__" 12 | kindKind = "__kind__" 13 | propertyKind = "__property__" 14 | ) 15 | 16 | // Namespaces returns all the datastore namespaces. 17 | func Namespaces(ctx context.Context) ([]string, error) { 18 | // TODO(djd): Support range queries. 19 | q := NewQuery(namespaceKind).KeysOnly() 20 | keys, err := q.GetAll(ctx, nil) 21 | if err != nil { 22 | return nil, err 23 | } 24 | // The empty namespace key uses a numeric ID (==1), but luckily 25 | // the string ID defaults to "" for numeric IDs anyway. 26 | return keyNames(keys), nil 27 | } 28 | 29 | // Kinds returns the names of all the kinds in the current namespace. 30 | func Kinds(ctx context.Context) ([]string, error) { 31 | // TODO(djd): Support range queries. 32 | q := NewQuery(kindKind).KeysOnly() 33 | keys, err := q.GetAll(ctx, nil) 34 | if err != nil { 35 | return nil, err 36 | } 37 | return keyNames(keys), nil 38 | } 39 | 40 | // keyNames returns a slice of the provided keys' names (string IDs). 41 | func keyNames(keys []*Key) []string { 42 | n := make([]string, 0, len(keys)) 43 | for _, k := range keys { 44 | n = append(n, k.StringID()) 45 | } 46 | return n 47 | } 48 | 49 | // KindProperties returns all the indexed properties for the given kind. 50 | // The properties are returned as a map of property names to a slice of the 51 | // representation types. The representation types for the supported Go property 52 | // types are: 53 | // "INT64": signed integers and time.Time 54 | // "DOUBLE": float32 and float64 55 | // "BOOLEAN": bool 56 | // "STRING": string, []byte and ByteString 57 | // "POINT": appengine.GeoPoint 58 | // "REFERENCE": *Key 59 | // "USER": (not used in the Go runtime) 60 | func KindProperties(ctx context.Context, kind string) (map[string][]string, error) { 61 | // TODO(djd): Support range queries. 62 | kindKey := NewKey(ctx, kindKind, kind, 0, nil) 63 | q := NewQuery(propertyKind).Ancestor(kindKey) 64 | 65 | propMap := map[string][]string{} 66 | props := []struct { 67 | Repr []string `datastore:property_representation` 68 | }{} 69 | 70 | keys, err := q.GetAll(ctx, &props) 71 | if err != nil { 72 | return nil, err 73 | } 74 | for i, p := range props { 75 | propMap[keys[i].StringID()] = p.Repr 76 | } 77 | return propMap, nil 78 | } 79 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/datastore/transaction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | package datastore 6 | 7 | import ( 8 | "errors" 9 | 10 | "golang.org/x/net/context" 11 | 12 | "google.golang.org/appengine/internal" 13 | pb "google.golang.org/appengine/internal/datastore" 14 | ) 15 | 16 | func init() { 17 | internal.RegisterTransactionSetter(func(x *pb.Query, t *pb.Transaction) { 18 | x.Transaction = t 19 | }) 20 | internal.RegisterTransactionSetter(func(x *pb.GetRequest, t *pb.Transaction) { 21 | x.Transaction = t 22 | }) 23 | internal.RegisterTransactionSetter(func(x *pb.PutRequest, t *pb.Transaction) { 24 | x.Transaction = t 25 | }) 26 | internal.RegisterTransactionSetter(func(x *pb.DeleteRequest, t *pb.Transaction) { 27 | x.Transaction = t 28 | }) 29 | } 30 | 31 | // ErrConcurrentTransaction is returned when a transaction is rolled back due 32 | // to a conflict with a concurrent transaction. 33 | var ErrConcurrentTransaction = errors.New("datastore: concurrent transaction") 34 | 35 | // RunInTransaction runs f in a transaction. It calls f with a transaction 36 | // context tc that f should use for all App Engine operations. 37 | // 38 | // If f returns nil, RunInTransaction attempts to commit the transaction, 39 | // returning nil if it succeeds. If the commit fails due to a conflicting 40 | // transaction, RunInTransaction retries f, each time with a new transaction 41 | // context. It gives up and returns ErrConcurrentTransaction after three 42 | // failed attempts. The number of attempts can be configured by specifying 43 | // TransactionOptions.Attempts. 44 | // 45 | // If f returns non-nil, then any datastore changes will not be applied and 46 | // RunInTransaction returns that same error. The function f is not retried. 47 | // 48 | // Note that when f returns, the transaction is not yet committed. Calling code 49 | // must be careful not to assume that any of f's changes have been committed 50 | // until RunInTransaction returns nil. 51 | // 52 | // Since f may be called multiple times, f should usually be idempotent. 53 | // datastore.Get is not idempotent when unmarshaling slice fields. 54 | // 55 | // Nested transactions are not supported; c may not be a transaction context. 56 | func RunInTransaction(c context.Context, f func(tc context.Context) error, opts *TransactionOptions) error { 57 | xg := false 58 | if opts != nil { 59 | xg = opts.XG 60 | } 61 | attempts := 3 62 | if opts != nil && opts.Attempts > 0 { 63 | attempts = opts.Attempts 64 | } 65 | for i := 0; i < attempts; i++ { 66 | if err := internal.RunTransactionOnce(c, f, xg); err != internal.ErrConcurrentTransaction { 67 | return err 68 | } 69 | } 70 | return ErrConcurrentTransaction 71 | } 72 | 73 | // TransactionOptions are the options for running a transaction. 74 | type TransactionOptions struct { 75 | // XG is whether the transaction can cross multiple entity groups. In 76 | // comparison, a single group transaction is one where all datastore keys 77 | // used have the same root key. Note that cross group transactions do not 78 | // have the same behavior as single group transactions. In particular, it 79 | // is much more likely to see partially applied transactions in different 80 | // entity groups, in global queries. 81 | // It is valid to set XG to true even if the transaction is within a 82 | // single entity group. 83 | XG bool 84 | // Attempts controls the number of retries to perform when commits fail 85 | // due to a conflicting transaction. If omitted, it defaults to 3. 86 | Attempts int 87 | } 88 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | // This file provides error functions for common API failure modes. 6 | 7 | package appengine 8 | 9 | import ( 10 | "fmt" 11 | 12 | "google.golang.org/appengine/internal" 13 | ) 14 | 15 | // IsOverQuota reports whether err represents an API call failure 16 | // due to insufficient available quota. 17 | func IsOverQuota(err error) bool { 18 | callErr, ok := err.(*internal.CallError) 19 | return ok && callErr.Code == 4 20 | } 21 | 22 | // MultiError is returned by batch operations when there are errors with 23 | // particular elements. Errors will be in a one-to-one correspondence with 24 | // the input elements; successful elements will have a nil entry. 25 | type MultiError []error 26 | 27 | func (m MultiError) Error() string { 28 | s, n := "", 0 29 | for _, e := range m { 30 | if e != nil { 31 | if n == 0 { 32 | s = e.Error() 33 | } 34 | n++ 35 | } 36 | } 37 | switch n { 38 | case 0: 39 | return "(0 errors)" 40 | case 1: 41 | return s 42 | case 2: 43 | return s + " (and 1 other error)" 44 | } 45 | return fmt.Sprintf("%s (and %d other errors)", s, n-1) 46 | } 47 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/api_classic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build appengine 6 | 7 | package internal 8 | 9 | import ( 10 | "errors" 11 | "fmt" 12 | "net/http" 13 | "time" 14 | 15 | "appengine" 16 | "appengine_internal" 17 | basepb "appengine_internal/base" 18 | 19 | "github.com/golang/protobuf/proto" 20 | netcontext "golang.org/x/net/context" 21 | ) 22 | 23 | var contextKey = "holds an appengine.Context" 24 | 25 | func fromContext(ctx netcontext.Context) appengine.Context { 26 | c, _ := ctx.Value(&contextKey).(appengine.Context) 27 | return c 28 | } 29 | 30 | // This is only for classic App Engine adapters. 31 | func ClassicContextFromContext(ctx netcontext.Context) appengine.Context { 32 | return fromContext(ctx) 33 | } 34 | 35 | func withContext(parent netcontext.Context, c appengine.Context) netcontext.Context { 36 | ctx := netcontext.WithValue(parent, &contextKey, c) 37 | 38 | s := &basepb.StringProto{} 39 | c.Call("__go__", "GetNamespace", &basepb.VoidProto{}, s, nil) 40 | if ns := s.GetValue(); ns != "" { 41 | ctx = NamespacedContext(ctx, ns) 42 | } 43 | 44 | return ctx 45 | } 46 | 47 | func IncomingHeaders(ctx netcontext.Context) http.Header { 48 | if c := fromContext(ctx); c != nil { 49 | if req, ok := c.Request().(*http.Request); ok { 50 | return req.Header 51 | } 52 | } 53 | return nil 54 | } 55 | 56 | func WithContext(parent netcontext.Context, req *http.Request) netcontext.Context { 57 | c := appengine.NewContext(req) 58 | return withContext(parent, c) 59 | } 60 | 61 | type testingContext struct { 62 | appengine.Context 63 | 64 | req *http.Request 65 | } 66 | 67 | func (t *testingContext) FullyQualifiedAppID() string { return "dev~testcontext" } 68 | func (t *testingContext) Call(service, method string, _, _ appengine_internal.ProtoMessage, _ *appengine_internal.CallOptions) error { 69 | if service == "__go__" && method == "GetNamespace" { 70 | return nil 71 | } 72 | return fmt.Errorf("testingContext: unsupported Call") 73 | } 74 | func (t *testingContext) Request() interface{} { return t.req } 75 | 76 | func ContextForTesting(req *http.Request) netcontext.Context { 77 | return withContext(netcontext.Background(), &testingContext{req: req}) 78 | } 79 | 80 | func Call(ctx netcontext.Context, service, method string, in, out proto.Message) error { 81 | if ns := NamespaceFromContext(ctx); ns != "" { 82 | if fn, ok := NamespaceMods[service]; ok { 83 | fn(in, ns) 84 | } 85 | } 86 | 87 | if f, ctx, ok := callOverrideFromContext(ctx); ok { 88 | return f(ctx, service, method, in, out) 89 | } 90 | 91 | // Handle already-done contexts quickly. 92 | select { 93 | case <-ctx.Done(): 94 | return ctx.Err() 95 | default: 96 | } 97 | 98 | c := fromContext(ctx) 99 | if c == nil { 100 | // Give a good error message rather than a panic lower down. 101 | return errors.New("not an App Engine context") 102 | } 103 | 104 | // Apply transaction modifications if we're in a transaction. 105 | if t := transactionFromContext(ctx); t != nil { 106 | if t.finished { 107 | return errors.New("transaction context has expired") 108 | } 109 | applyTransaction(in, &t.transaction) 110 | } 111 | 112 | var opts *appengine_internal.CallOptions 113 | if d, ok := ctx.Deadline(); ok { 114 | opts = &appengine_internal.CallOptions{ 115 | Timeout: d.Sub(time.Now()), 116 | } 117 | } 118 | 119 | err := c.Call(service, method, in, out, opts) 120 | switch v := err.(type) { 121 | case *appengine_internal.APIError: 122 | return &APIError{ 123 | Service: v.Service, 124 | Detail: v.Detail, 125 | Code: v.Code, 126 | } 127 | case *appengine_internal.CallError: 128 | return &CallError{ 129 | Detail: v.Detail, 130 | Code: v.Code, 131 | Timeout: v.Timeout, 132 | } 133 | } 134 | return err 135 | } 136 | 137 | func handleHTTP(w http.ResponseWriter, r *http.Request) { 138 | panic("handleHTTP called; this should be impossible") 139 | } 140 | 141 | func logf(c appengine.Context, level int64, format string, args ...interface{}) { 142 | var fn func(format string, args ...interface{}) 143 | switch level { 144 | case 0: 145 | fn = c.Debugf 146 | case 1: 147 | fn = c.Infof 148 | case 2: 149 | fn = c.Warningf 150 | case 3: 151 | fn = c.Errorf 152 | case 4: 153 | fn = c.Criticalf 154 | default: 155 | // This shouldn't happen. 156 | fn = c.Criticalf 157 | } 158 | fn(format, args...) 159 | } 160 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/api_common.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | package internal 6 | 7 | import ( 8 | "github.com/golang/protobuf/proto" 9 | netcontext "golang.org/x/net/context" 10 | ) 11 | 12 | type CallOverrideFunc func(ctx netcontext.Context, service, method string, in, out proto.Message) error 13 | 14 | var callOverrideKey = "holds []CallOverrideFunc" 15 | 16 | func WithCallOverride(ctx netcontext.Context, f CallOverrideFunc) netcontext.Context { 17 | // We avoid appending to any existing call override 18 | // so we don't risk overwriting a popped stack below. 19 | var cofs []CallOverrideFunc 20 | if uf, ok := ctx.Value(&callOverrideKey).([]CallOverrideFunc); ok { 21 | cofs = append(cofs, uf...) 22 | } 23 | cofs = append(cofs, f) 24 | return netcontext.WithValue(ctx, &callOverrideKey, cofs) 25 | } 26 | 27 | func callOverrideFromContext(ctx netcontext.Context) (CallOverrideFunc, netcontext.Context, bool) { 28 | cofs, _ := ctx.Value(&callOverrideKey).([]CallOverrideFunc) 29 | if len(cofs) == 0 { 30 | return nil, nil, false 31 | } 32 | // We found a list of overrides; grab the last, and reconstitute a 33 | // context that will hide it. 34 | f := cofs[len(cofs)-1] 35 | ctx = netcontext.WithValue(ctx, &callOverrideKey, cofs[:len(cofs)-1]) 36 | return f, ctx, true 37 | } 38 | 39 | type logOverrideFunc func(level int64, format string, args ...interface{}) 40 | 41 | var logOverrideKey = "holds a logOverrideFunc" 42 | 43 | func WithLogOverride(ctx netcontext.Context, f logOverrideFunc) netcontext.Context { 44 | return netcontext.WithValue(ctx, &logOverrideKey, f) 45 | } 46 | 47 | var appIDOverrideKey = "holds a string, being the full app ID" 48 | 49 | func WithAppIDOverride(ctx netcontext.Context, appID string) netcontext.Context { 50 | return netcontext.WithValue(ctx, &appIDOverrideKey, appID) 51 | } 52 | 53 | var namespaceKey = "holds the namespace string" 54 | 55 | func withNamespace(ctx netcontext.Context, ns string) netcontext.Context { 56 | return netcontext.WithValue(ctx, &namespaceKey, ns) 57 | } 58 | 59 | func NamespaceFromContext(ctx netcontext.Context) string { 60 | // If there's no namespace, return the empty string. 61 | ns, _ := ctx.Value(&namespaceKey).(string) 62 | return ns 63 | } 64 | 65 | // FullyQualifiedAppID returns the fully-qualified application ID. 66 | // This may contain a partition prefix (e.g. "s~" for High Replication apps), 67 | // or a domain prefix (e.g. "example.com:"). 68 | func FullyQualifiedAppID(ctx netcontext.Context) string { 69 | if id, ok := ctx.Value(&appIDOverrideKey).(string); ok { 70 | return id 71 | } 72 | return fullyQualifiedAppID(ctx) 73 | } 74 | 75 | func Logf(ctx netcontext.Context, level int64, format string, args ...interface{}) { 76 | if f, ok := ctx.Value(&logOverrideKey).(logOverrideFunc); ok { 77 | f(level, format, args...) 78 | return 79 | } 80 | logf(fromContext(ctx), level, format, args...) 81 | } 82 | 83 | // NamespacedContext wraps a Context to support namespaces. 84 | func NamespacedContext(ctx netcontext.Context, namespace string) netcontext.Context { 85 | return withNamespace(ctx, namespace) 86 | } 87 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/app_id.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | package internal 6 | 7 | import ( 8 | "strings" 9 | ) 10 | 11 | func parseFullAppID(appid string) (partition, domain, displayID string) { 12 | if i := strings.Index(appid, "~"); i != -1 { 13 | partition, appid = appid[:i], appid[i+1:] 14 | } 15 | if i := strings.Index(appid, ":"); i != -1 { 16 | domain, appid = appid[:i], appid[i+1:] 17 | } 18 | return partition, domain, appid 19 | } 20 | 21 | // appID returns "appid" or "domain.com:appid". 22 | func appID(fullAppID string) string { 23 | _, dom, dis := parseFullAppID(fullAppID) 24 | if dom != "" { 25 | return dom + ":" + dis 26 | } 27 | return dis 28 | } 29 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/app_identity/app_identity_service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | option go_package = "app_identity"; 3 | 4 | package appengine; 5 | 6 | message AppIdentityServiceError { 7 | enum ErrorCode { 8 | SUCCESS = 0; 9 | UNKNOWN_SCOPE = 9; 10 | BLOB_TOO_LARGE = 1000; 11 | DEADLINE_EXCEEDED = 1001; 12 | NOT_A_VALID_APP = 1002; 13 | UNKNOWN_ERROR = 1003; 14 | NOT_ALLOWED = 1005; 15 | NOT_IMPLEMENTED = 1006; 16 | } 17 | } 18 | 19 | message SignForAppRequest { 20 | optional bytes bytes_to_sign = 1; 21 | } 22 | 23 | message SignForAppResponse { 24 | optional string key_name = 1; 25 | optional bytes signature_bytes = 2; 26 | } 27 | 28 | message GetPublicCertificateForAppRequest { 29 | } 30 | 31 | message PublicCertificate { 32 | optional string key_name = 1; 33 | optional string x509_certificate_pem = 2; 34 | } 35 | 36 | message GetPublicCertificateForAppResponse { 37 | repeated PublicCertificate public_certificate_list = 1; 38 | optional int64 max_client_cache_time_in_second = 2; 39 | } 40 | 41 | message GetServiceAccountNameRequest { 42 | } 43 | 44 | message GetServiceAccountNameResponse { 45 | optional string service_account_name = 1; 46 | } 47 | 48 | message GetAccessTokenRequest { 49 | repeated string scope = 1; 50 | optional int64 service_account_id = 2; 51 | optional string service_account_name = 3; 52 | } 53 | 54 | message GetAccessTokenResponse { 55 | optional string access_token = 1; 56 | optional int64 expiration_time = 2; 57 | } 58 | 59 | message GetDefaultGcsBucketNameRequest { 60 | } 61 | 62 | message GetDefaultGcsBucketNameResponse { 63 | optional string default_gcs_bucket_name = 1; 64 | } 65 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/base/api_base.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. 2 | // source: google.golang.org/appengine/internal/base/api_base.proto 3 | // DO NOT EDIT! 4 | 5 | /* 6 | Package base is a generated protocol buffer package. 7 | 8 | It is generated from these files: 9 | google.golang.org/appengine/internal/base/api_base.proto 10 | 11 | It has these top-level messages: 12 | StringProto 13 | Integer32Proto 14 | Integer64Proto 15 | BoolProto 16 | DoubleProto 17 | BytesProto 18 | VoidProto 19 | */ 20 | package base 21 | 22 | import proto "github.com/golang/protobuf/proto" 23 | import fmt "fmt" 24 | import math "math" 25 | 26 | // Reference imports to suppress errors if they are not otherwise used. 27 | var _ = proto.Marshal 28 | var _ = fmt.Errorf 29 | var _ = math.Inf 30 | 31 | type StringProto struct { 32 | Value *string `protobuf:"bytes,1,req,name=value" json:"value,omitempty"` 33 | XXX_unrecognized []byte `json:"-"` 34 | } 35 | 36 | func (m *StringProto) Reset() { *m = StringProto{} } 37 | func (m *StringProto) String() string { return proto.CompactTextString(m) } 38 | func (*StringProto) ProtoMessage() {} 39 | 40 | func (m *StringProto) GetValue() string { 41 | if m != nil && m.Value != nil { 42 | return *m.Value 43 | } 44 | return "" 45 | } 46 | 47 | type Integer32Proto struct { 48 | Value *int32 `protobuf:"varint,1,req,name=value" json:"value,omitempty"` 49 | XXX_unrecognized []byte `json:"-"` 50 | } 51 | 52 | func (m *Integer32Proto) Reset() { *m = Integer32Proto{} } 53 | func (m *Integer32Proto) String() string { return proto.CompactTextString(m) } 54 | func (*Integer32Proto) ProtoMessage() {} 55 | 56 | func (m *Integer32Proto) GetValue() int32 { 57 | if m != nil && m.Value != nil { 58 | return *m.Value 59 | } 60 | return 0 61 | } 62 | 63 | type Integer64Proto struct { 64 | Value *int64 `protobuf:"varint,1,req,name=value" json:"value,omitempty"` 65 | XXX_unrecognized []byte `json:"-"` 66 | } 67 | 68 | func (m *Integer64Proto) Reset() { *m = Integer64Proto{} } 69 | func (m *Integer64Proto) String() string { return proto.CompactTextString(m) } 70 | func (*Integer64Proto) ProtoMessage() {} 71 | 72 | func (m *Integer64Proto) GetValue() int64 { 73 | if m != nil && m.Value != nil { 74 | return *m.Value 75 | } 76 | return 0 77 | } 78 | 79 | type BoolProto struct { 80 | Value *bool `protobuf:"varint,1,req,name=value" json:"value,omitempty"` 81 | XXX_unrecognized []byte `json:"-"` 82 | } 83 | 84 | func (m *BoolProto) Reset() { *m = BoolProto{} } 85 | func (m *BoolProto) String() string { return proto.CompactTextString(m) } 86 | func (*BoolProto) ProtoMessage() {} 87 | 88 | func (m *BoolProto) GetValue() bool { 89 | if m != nil && m.Value != nil { 90 | return *m.Value 91 | } 92 | return false 93 | } 94 | 95 | type DoubleProto struct { 96 | Value *float64 `protobuf:"fixed64,1,req,name=value" json:"value,omitempty"` 97 | XXX_unrecognized []byte `json:"-"` 98 | } 99 | 100 | func (m *DoubleProto) Reset() { *m = DoubleProto{} } 101 | func (m *DoubleProto) String() string { return proto.CompactTextString(m) } 102 | func (*DoubleProto) ProtoMessage() {} 103 | 104 | func (m *DoubleProto) GetValue() float64 { 105 | if m != nil && m.Value != nil { 106 | return *m.Value 107 | } 108 | return 0 109 | } 110 | 111 | type BytesProto struct { 112 | Value []byte `protobuf:"bytes,1,req,name=value" json:"value,omitempty"` 113 | XXX_unrecognized []byte `json:"-"` 114 | } 115 | 116 | func (m *BytesProto) Reset() { *m = BytesProto{} } 117 | func (m *BytesProto) String() string { return proto.CompactTextString(m) } 118 | func (*BytesProto) ProtoMessage() {} 119 | 120 | func (m *BytesProto) GetValue() []byte { 121 | if m != nil { 122 | return m.Value 123 | } 124 | return nil 125 | } 126 | 127 | type VoidProto struct { 128 | XXX_unrecognized []byte `json:"-"` 129 | } 130 | 131 | func (m *VoidProto) Reset() { *m = VoidProto{} } 132 | func (m *VoidProto) String() string { return proto.CompactTextString(m) } 133 | func (*VoidProto) ProtoMessage() {} 134 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/base/api_base.proto: -------------------------------------------------------------------------------- 1 | // Built-in base types for API calls. Primarily useful as return types. 2 | 3 | syntax = "proto2"; 4 | option go_package = "base"; 5 | 6 | package appengine.base; 7 | 8 | message StringProto { 9 | required string value = 1; 10 | } 11 | 12 | message Integer32Proto { 13 | required int32 value = 1; 14 | } 15 | 16 | message Integer64Proto { 17 | required int64 value = 1; 18 | } 19 | 20 | message BoolProto { 21 | required bool value = 1; 22 | } 23 | 24 | message DoubleProto { 25 | required double value = 1; 26 | } 27 | 28 | message BytesProto { 29 | required bytes value = 1 [ctype=CORD]; 30 | } 31 | 32 | message VoidProto { 33 | } 34 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/identity.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | package internal 6 | 7 | import netcontext "golang.org/x/net/context" 8 | 9 | // These functions are implementations of the wrapper functions 10 | // in ../appengine/identity.go. See that file for commentary. 11 | 12 | func AppID(c netcontext.Context) string { 13 | return appID(FullyQualifiedAppID(c)) 14 | } 15 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/identity_classic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build appengine 6 | 7 | package internal 8 | 9 | import ( 10 | "appengine" 11 | 12 | netcontext "golang.org/x/net/context" 13 | ) 14 | 15 | func DefaultVersionHostname(ctx netcontext.Context) string { 16 | return appengine.DefaultVersionHostname(fromContext(ctx)) 17 | } 18 | 19 | func RequestID(ctx netcontext.Context) string { return appengine.RequestID(fromContext(ctx)) } 20 | func Datacenter(_ netcontext.Context) string { return appengine.Datacenter() } 21 | func ServerSoftware() string { return appengine.ServerSoftware() } 22 | func ModuleName(ctx netcontext.Context) string { return appengine.ModuleName(fromContext(ctx)) } 23 | func VersionID(ctx netcontext.Context) string { return appengine.VersionID(fromContext(ctx)) } 24 | func InstanceID() string { return appengine.InstanceID() } 25 | func IsDevAppServer() bool { return appengine.IsDevAppServer() } 26 | 27 | func fullyQualifiedAppID(ctx netcontext.Context) string { return fromContext(ctx).FullyQualifiedAppID() } 28 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/identity_vm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !appengine 6 | 7 | package internal 8 | 9 | import ( 10 | "net/http" 11 | "os" 12 | 13 | netcontext "golang.org/x/net/context" 14 | ) 15 | 16 | // These functions are implementations of the wrapper functions 17 | // in ../appengine/identity.go. See that file for commentary. 18 | 19 | const ( 20 | hDefaultVersionHostname = "X-AppEngine-Default-Version-Hostname" 21 | hRequestLogId = "X-AppEngine-Request-Log-Id" 22 | hDatacenter = "X-AppEngine-Datacenter" 23 | ) 24 | 25 | func ctxHeaders(ctx netcontext.Context) http.Header { 26 | return fromContext(ctx).Request().Header 27 | } 28 | 29 | func DefaultVersionHostname(ctx netcontext.Context) string { 30 | return ctxHeaders(ctx).Get(hDefaultVersionHostname) 31 | } 32 | 33 | func RequestID(ctx netcontext.Context) string { 34 | return ctxHeaders(ctx).Get(hRequestLogId) 35 | } 36 | 37 | func Datacenter(ctx netcontext.Context) string { 38 | return ctxHeaders(ctx).Get(hDatacenter) 39 | } 40 | 41 | func ServerSoftware() string { 42 | // TODO(dsymonds): Remove fallback when we've verified this. 43 | if s := os.Getenv("SERVER_SOFTWARE"); s != "" { 44 | return s 45 | } 46 | return "Google App Engine/1.x.x" 47 | } 48 | 49 | // TODO(dsymonds): Remove the metadata fetches. 50 | 51 | func ModuleName(_ netcontext.Context) string { 52 | if s := os.Getenv("GAE_MODULE_NAME"); s != "" { 53 | return s 54 | } 55 | return string(mustGetMetadata("instance/attributes/gae_backend_name")) 56 | } 57 | 58 | func VersionID(_ netcontext.Context) string { 59 | if s1, s2 := os.Getenv("GAE_MODULE_VERSION"), os.Getenv("GAE_MINOR_VERSION"); s1 != "" && s2 != "" { 60 | return s1 + "." + s2 61 | } 62 | return string(mustGetMetadata("instance/attributes/gae_backend_version")) + "." + string(mustGetMetadata("instance/attributes/gae_backend_minor_version")) 63 | } 64 | 65 | func InstanceID() string { 66 | if s := os.Getenv("GAE_MODULE_INSTANCE"); s != "" { 67 | return s 68 | } 69 | return string(mustGetMetadata("instance/attributes/gae_backend_instance")) 70 | } 71 | 72 | func partitionlessAppID() string { 73 | // gae_project has everything except the partition prefix. 74 | appID := os.Getenv("GAE_LONG_APP_ID") 75 | if appID == "" { 76 | appID = string(mustGetMetadata("instance/attributes/gae_project")) 77 | } 78 | return appID 79 | } 80 | 81 | func fullyQualifiedAppID(_ netcontext.Context) string { 82 | appID := partitionlessAppID() 83 | 84 | part := os.Getenv("GAE_PARTITION") 85 | if part == "" { 86 | part = string(mustGetMetadata("instance/attributes/gae_partition")) 87 | } 88 | 89 | if part != "" { 90 | appID = part + "~" + appID 91 | } 92 | return appID 93 | } 94 | 95 | func IsDevAppServer() bool { 96 | return os.Getenv("RUN_WITH_DEVAPPSERVER") != "" 97 | } 98 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/internal.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package internal provides support for package appengine. 6 | // 7 | // Programs should not use this package directly. Its API is not stable. 8 | // Use packages appengine and appengine/* instead. 9 | package internal 10 | 11 | import ( 12 | "fmt" 13 | 14 | "github.com/golang/protobuf/proto" 15 | 16 | remotepb "google.golang.org/appengine/internal/remote_api" 17 | ) 18 | 19 | // errorCodeMaps is a map of service name to the error code map for the service. 20 | var errorCodeMaps = make(map[string]map[int32]string) 21 | 22 | // RegisterErrorCodeMap is called from API implementations to register their 23 | // error code map. This should only be called from init functions. 24 | func RegisterErrorCodeMap(service string, m map[int32]string) { 25 | errorCodeMaps[service] = m 26 | } 27 | 28 | type timeoutCodeKey struct { 29 | service string 30 | code int32 31 | } 32 | 33 | // timeoutCodes is the set of service+code pairs that represent timeouts. 34 | var timeoutCodes = make(map[timeoutCodeKey]bool) 35 | 36 | func RegisterTimeoutErrorCode(service string, code int32) { 37 | timeoutCodes[timeoutCodeKey{service, code}] = true 38 | } 39 | 40 | // APIError is the type returned by appengine.Context's Call method 41 | // when an API call fails in an API-specific way. This may be, for instance, 42 | // a taskqueue API call failing with TaskQueueServiceError::UNKNOWN_QUEUE. 43 | type APIError struct { 44 | Service string 45 | Detail string 46 | Code int32 // API-specific error code 47 | } 48 | 49 | func (e *APIError) Error() string { 50 | if e.Code == 0 { 51 | if e.Detail == "" { 52 | return "APIError " 53 | } 54 | return e.Detail 55 | } 56 | s := fmt.Sprintf("API error %d", e.Code) 57 | if m, ok := errorCodeMaps[e.Service]; ok { 58 | s += " (" + e.Service + ": " + m[e.Code] + ")" 59 | } else { 60 | // Shouldn't happen, but provide a bit more detail if it does. 61 | s = e.Service + " " + s 62 | } 63 | if e.Detail != "" { 64 | s += ": " + e.Detail 65 | } 66 | return s 67 | } 68 | 69 | func (e *APIError) IsTimeout() bool { 70 | return timeoutCodes[timeoutCodeKey{e.Service, e.Code}] 71 | } 72 | 73 | // CallError is the type returned by appengine.Context's Call method when an 74 | // API call fails in a generic way, such as RpcError::CAPABILITY_DISABLED. 75 | type CallError struct { 76 | Detail string 77 | Code int32 78 | // TODO: Remove this if we get a distinguishable error code. 79 | Timeout bool 80 | } 81 | 82 | func (e *CallError) Error() string { 83 | var msg string 84 | switch remotepb.RpcError_ErrorCode(e.Code) { 85 | case remotepb.RpcError_UNKNOWN: 86 | return e.Detail 87 | case remotepb.RpcError_OVER_QUOTA: 88 | msg = "Over quota" 89 | case remotepb.RpcError_CAPABILITY_DISABLED: 90 | msg = "Capability disabled" 91 | case remotepb.RpcError_CANCELLED: 92 | msg = "Canceled" 93 | default: 94 | msg = fmt.Sprintf("Call error %d", e.Code) 95 | } 96 | s := msg + ": " + e.Detail 97 | if e.Timeout { 98 | s += " (timeout)" 99 | } 100 | return s 101 | } 102 | 103 | func (e *CallError) IsTimeout() bool { 104 | return e.Timeout 105 | } 106 | 107 | // NamespaceMods is a map from API service to a function that will mutate an RPC request to attach a namespace. 108 | // The function should be prepared to be called on the same message more than once; it should only modify the 109 | // RPC request the first time. 110 | var NamespaceMods = make(map[string]func(m proto.Message, namespace string)) 111 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/log/log_service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | option go_package = "log"; 3 | 4 | package appengine; 5 | 6 | message LogServiceError { 7 | enum ErrorCode { 8 | OK = 0; 9 | INVALID_REQUEST = 1; 10 | STORAGE_ERROR = 2; 11 | } 12 | } 13 | 14 | message UserAppLogLine { 15 | required int64 timestamp_usec = 1; 16 | required int64 level = 2; 17 | required string message = 3; 18 | } 19 | 20 | message UserAppLogGroup { 21 | repeated UserAppLogLine log_line = 2; 22 | } 23 | 24 | message FlushRequest { 25 | optional bytes logs = 1; 26 | } 27 | 28 | message SetStatusRequest { 29 | required string status = 1; 30 | } 31 | 32 | 33 | message LogOffset { 34 | optional bytes request_id = 1; 35 | } 36 | 37 | message LogLine { 38 | required int64 time = 1; 39 | required int32 level = 2; 40 | required string log_message = 3; 41 | } 42 | 43 | message RequestLog { 44 | required string app_id = 1; 45 | optional string module_id = 37 [default="default"]; 46 | required string version_id = 2; 47 | required bytes request_id = 3; 48 | optional LogOffset offset = 35; 49 | required string ip = 4; 50 | optional string nickname = 5; 51 | required int64 start_time = 6; 52 | required int64 end_time = 7; 53 | required int64 latency = 8; 54 | required int64 mcycles = 9; 55 | required string method = 10; 56 | required string resource = 11; 57 | required string http_version = 12; 58 | required int32 status = 13; 59 | required int64 response_size = 14; 60 | optional string referrer = 15; 61 | optional string user_agent = 16; 62 | required string url_map_entry = 17; 63 | required string combined = 18; 64 | optional int64 api_mcycles = 19; 65 | optional string host = 20; 66 | optional double cost = 21; 67 | 68 | optional string task_queue_name = 22; 69 | optional string task_name = 23; 70 | 71 | optional bool was_loading_request = 24; 72 | optional int64 pending_time = 25; 73 | optional int32 replica_index = 26 [default = -1]; 74 | optional bool finished = 27 [default = true]; 75 | optional bytes clone_key = 28; 76 | 77 | repeated LogLine line = 29; 78 | 79 | optional bool lines_incomplete = 36; 80 | optional bytes app_engine_release = 38; 81 | 82 | optional int32 exit_reason = 30; 83 | optional bool was_throttled_for_time = 31; 84 | optional bool was_throttled_for_requests = 32; 85 | optional int64 throttled_time = 33; 86 | 87 | optional bytes server_name = 34; 88 | } 89 | 90 | message LogModuleVersion { 91 | optional string module_id = 1 [default="default"]; 92 | optional string version_id = 2; 93 | } 94 | 95 | message LogReadRequest { 96 | required string app_id = 1; 97 | repeated string version_id = 2; 98 | repeated LogModuleVersion module_version = 19; 99 | 100 | optional int64 start_time = 3; 101 | optional int64 end_time = 4; 102 | optional LogOffset offset = 5; 103 | repeated bytes request_id = 6; 104 | 105 | optional int32 minimum_log_level = 7; 106 | optional bool include_incomplete = 8; 107 | optional int64 count = 9; 108 | 109 | optional string combined_log_regex = 14; 110 | optional string host_regex = 15; 111 | optional int32 replica_index = 16; 112 | 113 | optional bool include_app_logs = 10; 114 | optional int32 app_logs_per_request = 17; 115 | optional bool include_host = 11; 116 | optional bool include_all = 12; 117 | optional bool cache_iterator = 13; 118 | optional int32 num_shards = 18; 119 | } 120 | 121 | message LogReadResponse { 122 | repeated RequestLog log = 1; 123 | optional LogOffset offset = 2; 124 | optional int64 last_end_time = 3; 125 | } 126 | 127 | message LogUsageRecord { 128 | optional string version_id = 1; 129 | optional int32 start_time = 2; 130 | optional int32 end_time = 3; 131 | optional int64 count = 4; 132 | optional int64 total_size = 5; 133 | optional int32 records = 6; 134 | } 135 | 136 | message LogUsageRequest { 137 | required string app_id = 1; 138 | repeated string version_id = 2; 139 | optional int32 start_time = 3; 140 | optional int32 end_time = 4; 141 | optional uint32 resolution_hours = 5 [default = 1]; 142 | optional bool combine_versions = 6; 143 | optional int32 usage_version = 7; 144 | optional bool versions_only = 8; 145 | } 146 | 147 | message LogUsageResponse { 148 | repeated LogUsageRecord usage = 1; 149 | optional LogUsageRecord summary = 2; 150 | } 151 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build appengine 6 | 7 | package internal 8 | 9 | import ( 10 | "appengine_internal" 11 | ) 12 | 13 | func Main() { 14 | appengine_internal.Main() 15 | } 16 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/main_vm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !appengine 6 | 7 | package internal 8 | 9 | import ( 10 | "io" 11 | "log" 12 | "net/http" 13 | "net/url" 14 | "os" 15 | ) 16 | 17 | func Main() { 18 | installHealthChecker(http.DefaultServeMux) 19 | 20 | port := "8080" 21 | if s := os.Getenv("PORT"); s != "" { 22 | port = s 23 | } 24 | 25 | if err := http.ListenAndServe(":"+port, http.HandlerFunc(handleHTTP)); err != nil { 26 | log.Fatalf("http.ListenAndServe: %v", err) 27 | } 28 | } 29 | 30 | func installHealthChecker(mux *http.ServeMux) { 31 | // If no health check handler has been installed by this point, add a trivial one. 32 | const healthPath = "/_ah/health" 33 | hreq := &http.Request{ 34 | Method: "GET", 35 | URL: &url.URL{ 36 | Path: healthPath, 37 | }, 38 | } 39 | if _, pat := mux.Handler(hreq); pat != healthPath { 40 | mux.HandleFunc(healthPath, func(w http.ResponseWriter, r *http.Request) { 41 | io.WriteString(w, "ok") 42 | }) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/metadata.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | package internal 6 | 7 | // This file has code for accessing metadata. 8 | // 9 | // References: 10 | // https://cloud.google.com/compute/docs/metadata 11 | 12 | import ( 13 | "fmt" 14 | "io/ioutil" 15 | "log" 16 | "net/http" 17 | "net/url" 18 | ) 19 | 20 | const ( 21 | metadataHost = "metadata" 22 | metadataPath = "/computeMetadata/v1/" 23 | ) 24 | 25 | var ( 26 | metadataRequestHeaders = http.Header{ 27 | "Metadata-Flavor": []string{"Google"}, 28 | } 29 | ) 30 | 31 | // TODO(dsymonds): Do we need to support default values, like Python? 32 | func mustGetMetadata(key string) []byte { 33 | b, err := getMetadata(key) 34 | if err != nil { 35 | log.Fatalf("Metadata fetch failed: %v", err) 36 | } 37 | return b 38 | } 39 | 40 | func getMetadata(key string) ([]byte, error) { 41 | // TODO(dsymonds): May need to use url.Parse to support keys with query args. 42 | req := &http.Request{ 43 | Method: "GET", 44 | URL: &url.URL{ 45 | Scheme: "http", 46 | Host: metadataHost, 47 | Path: metadataPath + key, 48 | }, 49 | Header: metadataRequestHeaders, 50 | Host: metadataHost, 51 | } 52 | resp, err := http.DefaultClient.Do(req) 53 | if err != nil { 54 | return nil, err 55 | } 56 | defer resp.Body.Close() 57 | if resp.StatusCode != 200 { 58 | return nil, fmt.Errorf("metadata server returned HTTP %d", resp.StatusCode) 59 | } 60 | return ioutil.ReadAll(resp.Body) 61 | } 62 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/modules/modules_service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | option go_package = "modules"; 3 | 4 | package appengine; 5 | 6 | message ModulesServiceError { 7 | enum ErrorCode { 8 | OK = 0; 9 | INVALID_MODULE = 1; 10 | INVALID_VERSION = 2; 11 | INVALID_INSTANCES = 3; 12 | TRANSIENT_ERROR = 4; 13 | UNEXPECTED_STATE = 5; 14 | } 15 | } 16 | 17 | message GetModulesRequest { 18 | } 19 | 20 | message GetModulesResponse { 21 | repeated string module = 1; 22 | } 23 | 24 | message GetVersionsRequest { 25 | optional string module = 1; 26 | } 27 | 28 | message GetVersionsResponse { 29 | repeated string version = 1; 30 | } 31 | 32 | message GetDefaultVersionRequest { 33 | optional string module = 1; 34 | } 35 | 36 | message GetDefaultVersionResponse { 37 | required string version = 1; 38 | } 39 | 40 | message GetNumInstancesRequest { 41 | optional string module = 1; 42 | optional string version = 2; 43 | } 44 | 45 | message GetNumInstancesResponse { 46 | required int64 instances = 1; 47 | } 48 | 49 | message SetNumInstancesRequest { 50 | optional string module = 1; 51 | optional string version = 2; 52 | required int64 instances = 3; 53 | } 54 | 55 | message SetNumInstancesResponse {} 56 | 57 | message StartModuleRequest { 58 | required string module = 1; 59 | required string version = 2; 60 | } 61 | 62 | message StartModuleResponse {} 63 | 64 | message StopModuleRequest { 65 | optional string module = 1; 66 | optional string version = 2; 67 | } 68 | 69 | message StopModuleResponse {} 70 | 71 | message GetHostnameRequest { 72 | optional string module = 1; 73 | optional string version = 2; 74 | optional string instance = 3; 75 | } 76 | 77 | message GetHostnameResponse { 78 | required string hostname = 1; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/net.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | package internal 6 | 7 | // This file implements a network dialer that limits the number of concurrent connections. 8 | // It is only used for API calls. 9 | 10 | import ( 11 | "log" 12 | "net" 13 | "runtime" 14 | "sync" 15 | "time" 16 | ) 17 | 18 | var limitSem = make(chan int, 100) // TODO(dsymonds): Use environment variable. 19 | 20 | func limitRelease() { 21 | // non-blocking 22 | select { 23 | case <-limitSem: 24 | default: 25 | // This should not normally happen. 26 | log.Print("appengine: unbalanced limitSem release!") 27 | } 28 | } 29 | 30 | func limitDial(network, addr string) (net.Conn, error) { 31 | limitSem <- 1 32 | 33 | // Dial with a timeout in case the API host is MIA. 34 | // The connection should normally be very fast. 35 | conn, err := net.DialTimeout(network, addr, 500*time.Millisecond) 36 | if err != nil { 37 | limitRelease() 38 | return nil, err 39 | } 40 | lc := &limitConn{Conn: conn} 41 | runtime.SetFinalizer(lc, (*limitConn).Close) // shouldn't usually be required 42 | return lc, nil 43 | } 44 | 45 | type limitConn struct { 46 | close sync.Once 47 | net.Conn 48 | } 49 | 50 | func (lc *limitConn) Close() error { 51 | defer lc.close.Do(func() { 52 | limitRelease() 53 | runtime.SetFinalizer(lc, nil) 54 | }) 55 | return lc.Conn.Close() 56 | } 57 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/regen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # 3 | # This script rebuilds the generated code for the protocol buffers. 4 | # To run this you will need protoc and goprotobuf installed; 5 | # see https://github.com/golang/protobuf for instructions. 6 | 7 | PKG=google.golang.org/appengine 8 | 9 | function die() { 10 | echo 1>&2 $* 11 | exit 1 12 | } 13 | 14 | # Sanity check that the right tools are accessible. 15 | for tool in go protoc protoc-gen-go; do 16 | q=$(which $tool) || die "didn't find $tool" 17 | echo 1>&2 "$tool: $q" 18 | done 19 | 20 | echo -n 1>&2 "finding package dir... " 21 | pkgdir=$(go list -f '{{.Dir}}' $PKG) 22 | echo 1>&2 $pkgdir 23 | base=$(echo $pkgdir | sed "s,/$PKG\$,,") 24 | echo 1>&2 "base: $base" 25 | cd $base 26 | 27 | # Run protoc once per package. 28 | for dir in $(find $PKG/internal -name '*.proto' | xargs dirname | sort | uniq); do 29 | echo 1>&2 "* $dir" 30 | protoc --go_out=. $dir/*.proto 31 | done 32 | 33 | for f in $(find $PKG/internal -name '*.pb.go'); do 34 | # Remove proto.RegisterEnum calls. 35 | # These cause duplicate registration panics when these packages 36 | # are used on classic App Engine. proto.RegisterEnum only affects 37 | # parsing the text format; we don't care about that. 38 | # https://code.google.com/p/googleappengine/issues/detail?id=11670#c17 39 | sed -i '/proto.RegisterEnum/d' $f 40 | done 41 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/remote_api/remote_api.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | option go_package = "remote_api"; 3 | 4 | package remote_api; 5 | 6 | message Request { 7 | required string service_name = 2; 8 | required string method = 3; 9 | required bytes request = 4; 10 | optional string request_id = 5; 11 | } 12 | 13 | message ApplicationError { 14 | required int32 code = 1; 15 | required string detail = 2; 16 | } 17 | 18 | message RpcError { 19 | enum ErrorCode { 20 | UNKNOWN = 0; 21 | CALL_NOT_FOUND = 1; 22 | PARSE_ERROR = 2; 23 | SECURITY_VIOLATION = 3; 24 | OVER_QUOTA = 4; 25 | REQUEST_TOO_LARGE = 5; 26 | CAPABILITY_DISABLED = 6; 27 | FEATURE_DISABLED = 7; 28 | BAD_REQUEST = 8; 29 | RESPONSE_TOO_LARGE = 9; 30 | CANCELLED = 10; 31 | REPLAY_ERROR = 11; 32 | DEADLINE_EXCEEDED = 12; 33 | } 34 | required int32 code = 1; 35 | optional string detail = 2; 36 | } 37 | 38 | message Response { 39 | optional bytes response = 1; 40 | optional bytes exception = 2; 41 | optional ApplicationError application_error = 3; 42 | optional bytes java_exception = 4; 43 | optional RpcError rpc_error = 5; 44 | } 45 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/internal/transaction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | package internal 6 | 7 | // This file implements hooks for applying datastore transactions. 8 | 9 | import ( 10 | "errors" 11 | "reflect" 12 | 13 | "github.com/golang/protobuf/proto" 14 | netcontext "golang.org/x/net/context" 15 | 16 | basepb "google.golang.org/appengine/internal/base" 17 | pb "google.golang.org/appengine/internal/datastore" 18 | ) 19 | 20 | var transactionSetters = make(map[reflect.Type]reflect.Value) 21 | 22 | // RegisterTransactionSetter registers a function that sets transaction information 23 | // in a protocol buffer message. f should be a function with two arguments, 24 | // the first being a protocol buffer type, and the second being *datastore.Transaction. 25 | func RegisterTransactionSetter(f interface{}) { 26 | v := reflect.ValueOf(f) 27 | transactionSetters[v.Type().In(0)] = v 28 | } 29 | 30 | // applyTransaction applies the transaction t to message pb 31 | // by using the relevant setter passed to RegisterTransactionSetter. 32 | func applyTransaction(pb proto.Message, t *pb.Transaction) { 33 | v := reflect.ValueOf(pb) 34 | if f, ok := transactionSetters[v.Type()]; ok { 35 | f.Call([]reflect.Value{v, reflect.ValueOf(t)}) 36 | } 37 | } 38 | 39 | var transactionKey = "used for *Transaction" 40 | 41 | func transactionFromContext(ctx netcontext.Context) *transaction { 42 | t, _ := ctx.Value(&transactionKey).(*transaction) 43 | return t 44 | } 45 | 46 | func withTransaction(ctx netcontext.Context, t *transaction) netcontext.Context { 47 | return netcontext.WithValue(ctx, &transactionKey, t) 48 | } 49 | 50 | type transaction struct { 51 | transaction pb.Transaction 52 | finished bool 53 | } 54 | 55 | var ErrConcurrentTransaction = errors.New("internal: concurrent transaction") 56 | 57 | func RunTransactionOnce(c netcontext.Context, f func(netcontext.Context) error, xg bool) error { 58 | if transactionFromContext(c) != nil { 59 | return errors.New("nested transactions are not supported") 60 | } 61 | 62 | // Begin the transaction. 63 | t := &transaction{} 64 | req := &pb.BeginTransactionRequest{ 65 | App: proto.String(FullyQualifiedAppID(c)), 66 | } 67 | if xg { 68 | req.AllowMultipleEg = proto.Bool(true) 69 | } 70 | if err := Call(c, "datastore_v3", "BeginTransaction", req, &t.transaction); err != nil { 71 | return err 72 | } 73 | 74 | // Call f, rolling back the transaction if f returns a non-nil error, or panics. 75 | // The panic is not recovered. 76 | defer func() { 77 | if t.finished { 78 | return 79 | } 80 | t.finished = true 81 | // Ignore the error return value, since we are already returning a non-nil 82 | // error (or we're panicking). 83 | Call(c, "datastore_v3", "Rollback", &t.transaction, &basepb.VoidProto{}) 84 | }() 85 | if err := f(withTransaction(c, t)); err != nil { 86 | return err 87 | } 88 | t.finished = true 89 | 90 | // Commit the transaction. 91 | res := &pb.CommitResponse{} 92 | err := Call(c, "datastore_v3", "Commit", &t.transaction, res) 93 | if ae, ok := err.(*APIError); ok { 94 | /* TODO: restore this conditional 95 | if appengine.IsDevAppServer() { 96 | */ 97 | // The Python Dev AppServer raises an ApplicationError with error code 2 (which is 98 | // Error.CONCURRENT_TRANSACTION) and message "Concurrency exception.". 99 | if ae.Code == int32(pb.Error_BAD_REQUEST) && ae.Detail == "ApplicationError: 2 Concurrency exception." { 100 | return ErrConcurrentTransaction 101 | } 102 | if ae.Code == int32(pb.Error_CONCURRENT_TRANSACTION) { 103 | return ErrConcurrentTransaction 104 | } 105 | } 106 | return err 107 | } 108 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/namespace.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | package appengine 6 | 7 | import ( 8 | "fmt" 9 | "regexp" 10 | 11 | "golang.org/x/net/context" 12 | 13 | "google.golang.org/appengine/internal" 14 | ) 15 | 16 | // Namespace returns a replacement context that operates within the given namespace. 17 | func Namespace(c context.Context, namespace string) (context.Context, error) { 18 | if !validNamespace.MatchString(namespace) { 19 | return nil, fmt.Errorf("appengine: namespace %q does not match /%s/", namespace, validNamespace) 20 | } 21 | return internal.NamespacedContext(c, namespace), nil 22 | } 23 | 24 | // validNamespace matches valid namespace names. 25 | var validNamespace = regexp.MustCompile(`^[0-9A-Za-z._-]{0,100}$`) 26 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/timeout.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | package appengine 6 | 7 | import "golang.org/x/net/context" 8 | 9 | // IsTimeoutError reports whether err is a timeout error. 10 | func IsTimeoutError(err error) bool { 11 | if err == context.DeadlineExceeded { 12 | return true 13 | } 14 | if t, ok := err.(interface { 15 | IsTimeout() bool 16 | }); ok { 17 | return t.IsTimeout() 18 | } 19 | return false 20 | } 21 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: go 3 | 4 | go: 5 | - 1.7 6 | - 1.8 7 | - tip 8 | 9 | matrix: 10 | allow_failures: 11 | - go: tip 12 | 13 | install: 14 | - go get gopkg.in/check.v1 15 | - mkdir -p $HOME/gopath/src/gopkg.in/vmihailenco 16 | - mv `pwd` $HOME/gopath/src/gopkg.in/vmihailenco/msgpack.v2 17 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 The msgpack for Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | go test ./... 3 | env GOOS=linux GOARCH=386 go test ./... 4 | go test ./... -short -race 5 | go vet 6 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/README.md: -------------------------------------------------------------------------------- 1 | # MessagePack encoding for Golang 2 | 3 | [![Build Status](https://travis-ci.org/vmihailenco/msgpack.svg?branch=v2)](https://travis-ci.org/vmihailenco/msgpack) 4 | [![GoDoc](https://godoc.org/github.com/vmihailenco/msgpack?status.svg)](https://godoc.org/github.com/vmihailenco/msgpack) 5 | 6 | Supports: 7 | - Primitives, arrays, maps, structs, time.Time and interface{}. 8 | - Appengine *datastore.Key and datastore.Cursor. 9 | - [CustomEncoder](https://godoc.org/gopkg.in/vmihailenco/msgpack.v2#example-CustomEncoder)/CustomDecoder interfaces for custom encoding. 10 | - [Extensions](https://godoc.org/gopkg.in/vmihailenco/msgpack.v2#example-RegisterExt) to encode type information. 11 | - Renaming fields via `msgpack:"my_field_name"`. 12 | - Inlining struct fields via `msgpack:",inline"`. 13 | - Omitting empty fields via `msgpack:",omitempty"`. 14 | - [Map keys sorting](https://godoc.org/gopkg.in/vmihailenco/msgpack.v2#Encoder.SortMapKeys). 15 | - Encoding/decoding all [structs as arrays](https://godoc.org/gopkg.in/vmihailenco/msgpack.v2#Encoder.StructAsArray) or [individual structs](https://godoc.org/gopkg.in/vmihailenco/msgpack.v2#example-Marshal--AsArray). 16 | - Simple but very fast and efficient [queries](https://godoc.org/gopkg.in/vmihailenco/msgpack.v2#example-Decoder-Query). 17 | 18 | API docs: https://godoc.org/gopkg.in/vmihailenco/msgpack.v2. 19 | Examples: https://godoc.org/gopkg.in/vmihailenco/msgpack.v2#pkg-examples. 20 | 21 | ## Installation 22 | 23 | Install: 24 | 25 | ```shell 26 | go get gopkg.in/vmihailenco/msgpack.v2 27 | ``` 28 | 29 | ## Quickstart 30 | 31 | ```go 32 | func ExampleMarshal() { 33 | type Item struct { 34 | Foo string 35 | } 36 | 37 | b, err := msgpack.Marshal(&Item{Foo: "bar"}) 38 | if err != nil { 39 | panic(err) 40 | } 41 | 42 | var item Item 43 | err = msgpack.Unmarshal(b, &item) 44 | if err != nil { 45 | panic(err) 46 | } 47 | fmt.Println(item.Foo) 48 | // Output: bar 49 | } 50 | ``` 51 | 52 | ## Benchmark 53 | 54 | ``` 55 | BenchmarkStructVmihailencoMsgpack-4 200000 12814 ns/op 2128 B/op 26 allocs/op 56 | BenchmarkStructUgorjiGoMsgpack-4 100000 17678 ns/op 3616 B/op 70 allocs/op 57 | BenchmarkStructUgorjiGoCodec-4 100000 19053 ns/op 7346 B/op 23 allocs/op 58 | BenchmarkStructJSON-4 20000 69438 ns/op 7864 B/op 26 allocs/op 59 | BenchmarkStructGOB-4 10000 104331 ns/op 14664 B/op 278 allocs/op 60 | ``` 61 | 62 | ## Howto 63 | 64 | Please go through [examples](https://godoc.org/gopkg.in/vmihailenco/msgpack.v2#pkg-examples) to get an idea how to use this package. 65 | 66 | ## See also 67 | 68 | - [Golang PostgreSQL ORM](https://github.com/go-pg/pg) 69 | - [Golang message task queue](https://github.com/go-msgqueue/msgqueue) 70 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/appengine.go: -------------------------------------------------------------------------------- 1 | // +build appengine 2 | 3 | package msgpack 4 | 5 | import ( 6 | "reflect" 7 | 8 | ds "google.golang.org/appengine/datastore" 9 | ) 10 | 11 | var ( 12 | keyPtrType = reflect.TypeOf((*ds.Key)(nil)) 13 | cursorType = reflect.TypeOf((*ds.Cursor)(nil)).Elem() 14 | ) 15 | 16 | func init() { 17 | Register(keyPtrType, encodeDatastoreKeyValue, decodeDatastoreKeyValue) 18 | Register(cursorType, encodeDatastoreCursorValue, decodeDatastoreCursorValue) 19 | } 20 | 21 | func EncodeDatastoreKey(e *Encoder, key *ds.Key) error { 22 | if key == nil { 23 | return e.EncodeNil() 24 | } 25 | return e.EncodeString(key.Encode()) 26 | } 27 | 28 | func encodeDatastoreKeyValue(e *Encoder, v reflect.Value) error { 29 | key := v.Interface().(*ds.Key) 30 | return EncodeDatastoreKey(e, key) 31 | } 32 | 33 | func DecodeDatastoreKey(d *Decoder) (*ds.Key, error) { 34 | v, err := d.DecodeString() 35 | if err != nil { 36 | return nil, err 37 | } 38 | if v == "" { 39 | return nil, nil 40 | } 41 | return ds.DecodeKey(v) 42 | } 43 | 44 | func decodeDatastoreKeyValue(d *Decoder, v reflect.Value) error { 45 | key, err := DecodeDatastoreKey(d) 46 | if err != nil { 47 | return err 48 | } 49 | v.Set(reflect.ValueOf(key)) 50 | return nil 51 | } 52 | 53 | func encodeDatastoreCursorValue(e *Encoder, v reflect.Value) error { 54 | cursor := v.Interface().(ds.Cursor) 55 | return e.Encode(cursor.String()) 56 | } 57 | 58 | func decodeDatastoreCursorValue(d *Decoder, v reflect.Value) error { 59 | s, err := d.DecodeString() 60 | if err != nil { 61 | return err 62 | } 63 | cursor, err := ds.DecodeCursor(s) 64 | if err != nil { 65 | return err 66 | } 67 | v.Set(reflect.ValueOf(cursor)) 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/codes/codes.go: -------------------------------------------------------------------------------- 1 | package codes 2 | 3 | var ( 4 | PosFixedNumHigh byte = 0x7f 5 | NegFixedNumLow byte = 0xe0 6 | 7 | Nil byte = 0xc0 8 | 9 | False byte = 0xc2 10 | True byte = 0xc3 11 | 12 | Float byte = 0xca 13 | Double byte = 0xcb 14 | 15 | Uint8 byte = 0xcc 16 | Uint16 byte = 0xcd 17 | Uint32 byte = 0xce 18 | Uint64 byte = 0xcf 19 | 20 | Int8 byte = 0xd0 21 | Int16 byte = 0xd1 22 | Int32 byte = 0xd2 23 | Int64 byte = 0xd3 24 | 25 | FixedStrLow byte = 0xa0 26 | FixedStrHigh byte = 0xbf 27 | FixedStrMask byte = 0x1f 28 | Str8 byte = 0xd9 29 | Str16 byte = 0xda 30 | Str32 byte = 0xdb 31 | 32 | Bin8 byte = 0xc4 33 | Bin16 byte = 0xc5 34 | Bin32 byte = 0xc6 35 | 36 | FixedArrayLow byte = 0x90 37 | FixedArrayHigh byte = 0x9f 38 | FixedArrayMask byte = 0xf 39 | Array16 byte = 0xdc 40 | Array32 byte = 0xdd 41 | 42 | FixedMapLow byte = 0x80 43 | FixedMapHigh byte = 0x8f 44 | FixedMapMask byte = 0xf 45 | Map16 byte = 0xde 46 | Map32 byte = 0xdf 47 | 48 | FixExt1 byte = 0xd4 49 | FixExt2 byte = 0xd5 50 | FixExt4 byte = 0xd6 51 | FixExt8 byte = 0xd7 52 | FixExt16 byte = 0xd8 53 | Ext8 byte = 0xc7 54 | Ext16 byte = 0xc8 55 | Ext32 byte = 0xc9 56 | ) 57 | 58 | func IsFixedNum(c byte) bool { 59 | return c <= PosFixedNumHigh || c >= NegFixedNumLow 60 | } 61 | 62 | func IsFixedMap(c byte) bool { 63 | return c >= FixedMapLow && c <= FixedMapHigh 64 | } 65 | 66 | func IsFixedArray(c byte) bool { 67 | return c >= FixedArrayLow && c <= FixedArrayHigh 68 | } 69 | 70 | func IsFixedString(c byte) bool { 71 | return c >= FixedStrLow && c <= FixedStrHigh 72 | } 73 | 74 | func IsExt(c byte) bool { 75 | return (c >= FixExt1 && c <= FixExt16) || (c >= Ext8 && c <= Ext32) 76 | } 77 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/decode_query.go: -------------------------------------------------------------------------------- 1 | package msgpack 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | "strings" 7 | 8 | "gopkg.in/vmihailenco/msgpack.v2/codes" 9 | ) 10 | 11 | type queryResult struct { 12 | query string 13 | key string 14 | hasAsterisk bool 15 | 16 | values []interface{} 17 | } 18 | 19 | func (q *queryResult) nextKey() { 20 | ind := strings.IndexByte(q.query, '.') 21 | if ind == -1 { 22 | q.key = q.query 23 | q.query = "" 24 | return 25 | } 26 | q.key = q.query[:ind] 27 | q.query = q.query[ind+1:] 28 | } 29 | 30 | // Query extracts data specified by the query from the msgpack stream skipping 31 | // any other data. Query consists of map keys and array indexes separated with dot, 32 | // e.g. key1.0.key2. 33 | func (d *Decoder) Query(query string) ([]interface{}, error) { 34 | res := queryResult{ 35 | query: query, 36 | } 37 | if err := d.query(&res); err != nil { 38 | return nil, err 39 | } 40 | return res.values, nil 41 | } 42 | 43 | func (d *Decoder) query(q *queryResult) error { 44 | q.nextKey() 45 | if q.key == "" { 46 | v, err := d.DecodeInterface() 47 | if err != nil { 48 | return err 49 | } 50 | q.values = append(q.values, v) 51 | return nil 52 | } 53 | 54 | code, err := d.PeekCode() 55 | if err != nil { 56 | return err 57 | } 58 | 59 | switch { 60 | case code == codes.Map16 || code == codes.Map32 || codes.IsFixedMap(code): 61 | err = d.queryMapKey(q) 62 | case code == codes.Array16 || code == codes.Array32 || codes.IsFixedArray(code): 63 | err = d.queryArrayIndex(q) 64 | default: 65 | err = fmt.Errorf("msgpack: unsupported code=%x decoding key=%q", code, q.key) 66 | } 67 | return err 68 | } 69 | 70 | func (d *Decoder) queryMapKey(q *queryResult) error { 71 | n, err := d.DecodeMapLen() 72 | if err != nil { 73 | return err 74 | } 75 | if n == -1 { 76 | return nil 77 | } 78 | 79 | for i := 0; i < n; i++ { 80 | k, err := d.bytesNoCopy() 81 | if err != nil { 82 | return err 83 | } 84 | 85 | if string(k) == q.key { 86 | if err := d.query(q); err != nil { 87 | return err 88 | } 89 | if q.hasAsterisk { 90 | return d.skipNext((n - i - 1) * 2) 91 | } 92 | return nil 93 | } 94 | 95 | if err := d.Skip(); err != nil { 96 | return err 97 | } 98 | } 99 | 100 | return nil 101 | } 102 | 103 | func (d *Decoder) queryArrayIndex(q *queryResult) error { 104 | n, err := d.DecodeSliceLen() 105 | if err != nil { 106 | return err 107 | } 108 | if n == -1 { 109 | return nil 110 | } 111 | 112 | if q.key == "*" { 113 | q.hasAsterisk = true 114 | 115 | query := q.query 116 | for i := 0; i < n; i++ { 117 | q.query = query 118 | if err := d.query(q); err != nil { 119 | return err 120 | } 121 | } 122 | 123 | q.hasAsterisk = false 124 | return nil 125 | } 126 | 127 | ind, err := strconv.Atoi(q.key) 128 | if err != nil { 129 | return err 130 | } 131 | 132 | for i := 0; i < n; i++ { 133 | if i == ind { 134 | if err := d.query(q); err != nil { 135 | return err 136 | } 137 | if q.hasAsterisk { 138 | return d.skipNext(n - i - 1) 139 | } 140 | return nil 141 | } 142 | 143 | if err := d.Skip(); err != nil { 144 | return err 145 | } 146 | } 147 | 148 | return nil 149 | } 150 | 151 | func (d *Decoder) skipNext(n int) error { 152 | for i := 0; i < n; i++ { 153 | if err := d.Skip(); err != nil { 154 | return err 155 | } 156 | } 157 | return nil 158 | } 159 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/decode_slice.go: -------------------------------------------------------------------------------- 1 | package msgpack 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | 7 | "gopkg.in/vmihailenco/msgpack.v2/codes" 8 | ) 9 | 10 | const sliceElemsAllocLimit = 1e4 11 | 12 | var sliceStringPtrType = reflect.TypeOf((*[]string)(nil)) 13 | 14 | // Deprecated. Use DecodeArrayLen instead. 15 | func (d *Decoder) DecodeSliceLen() (int, error) { 16 | return d.DecodeArrayLen() 17 | } 18 | 19 | func (d *Decoder) DecodeArrayLen() (int, error) { 20 | c, err := d.readByte() 21 | if err != nil { 22 | return 0, err 23 | } 24 | return d.arrayLen(c) 25 | } 26 | 27 | func (d *Decoder) arrayLen(c byte) (int, error) { 28 | if c == codes.Nil { 29 | return -1, nil 30 | } else if c >= codes.FixedArrayLow && c <= codes.FixedArrayHigh { 31 | return int(c & codes.FixedArrayMask), nil 32 | } 33 | switch c { 34 | case codes.Array16: 35 | n, err := d.uint16() 36 | return int(n), err 37 | case codes.Array32: 38 | n, err := d.uint32() 39 | return int(n), err 40 | } 41 | return 0, fmt.Errorf("msgpack: invalid code %x decoding array length", c) 42 | } 43 | 44 | func decodeStringSliceValue(d *Decoder, v reflect.Value) error { 45 | ptr := v.Addr().Convert(sliceStringPtrType).Interface().(*[]string) 46 | return d.decodeStringSlicePtr(ptr) 47 | } 48 | 49 | func (d *Decoder) decodeStringSlicePtr(ptr *[]string) error { 50 | n, err := d.DecodeArrayLen() 51 | if err != nil { 52 | return err 53 | } 54 | if n == -1 { 55 | return nil 56 | } 57 | 58 | ss := setStringsCap(*ptr, n) 59 | for i := 0; i < n; i++ { 60 | s, err := d.DecodeString() 61 | if err != nil { 62 | return err 63 | } 64 | ss = append(ss, s) 65 | } 66 | *ptr = ss 67 | 68 | return nil 69 | } 70 | 71 | func setStringsCap(s []string, n int) []string { 72 | if n > sliceElemsAllocLimit { 73 | n = sliceElemsAllocLimit 74 | } 75 | 76 | if s == nil { 77 | return make([]string, 0, n) 78 | } 79 | 80 | if cap(s) >= n { 81 | return s[:0] 82 | } 83 | 84 | s = s[:cap(s)] 85 | s = append(s, make([]string, n-len(s))...) 86 | return s[:0] 87 | } 88 | 89 | func decodeSliceValue(d *Decoder, v reflect.Value) error { 90 | n, err := d.DecodeArrayLen() 91 | if err != nil { 92 | return err 93 | } 94 | 95 | if n == -1 { 96 | v.Set(reflect.Zero(v.Type())) 97 | return nil 98 | } 99 | if n == 0 && v.IsNil() { 100 | v.Set(reflect.MakeSlice(v.Type(), 0, 0)) 101 | return nil 102 | } 103 | 104 | if v.Cap() >= n { 105 | v.Set(v.Slice(0, n)) 106 | } else if v.Len() < v.Cap() { 107 | v.Set(v.Slice(0, v.Cap())) 108 | } 109 | 110 | for i := 0; i < n; i++ { 111 | if i >= v.Len() { 112 | v.Set(growSliceValue(v, n)) 113 | } 114 | sv := v.Index(i) 115 | if err := d.DecodeValue(sv); err != nil { 116 | return err 117 | } 118 | } 119 | 120 | return nil 121 | } 122 | 123 | func growSliceValue(v reflect.Value, n int) reflect.Value { 124 | diff := n - v.Len() 125 | if diff > sliceElemsAllocLimit { 126 | diff = sliceElemsAllocLimit 127 | } 128 | v = reflect.AppendSlice(v, reflect.MakeSlice(v.Type(), diff, diff)) 129 | return v 130 | } 131 | 132 | func decodeArrayValue(d *Decoder, v reflect.Value) error { 133 | n, err := d.DecodeArrayLen() 134 | if err != nil { 135 | return err 136 | } 137 | 138 | if n == -1 { 139 | return nil 140 | } 141 | 142 | if n > v.Len() { 143 | return fmt.Errorf("%s len is %d, but msgpack has %d elements", v.Type(), v.Len(), n) 144 | } 145 | for i := 0; i < n; i++ { 146 | sv := v.Index(i) 147 | if err := d.DecodeValue(sv); err != nil { 148 | return err 149 | } 150 | } 151 | 152 | return nil 153 | } 154 | 155 | func (d *Decoder) DecodeSlice() ([]interface{}, error) { 156 | c, err := d.readByte() 157 | if err != nil { 158 | return nil, err 159 | } 160 | return d.decodeSlice(c) 161 | } 162 | 163 | func (d *Decoder) decodeSlice(c byte) ([]interface{}, error) { 164 | n, err := d.arrayLen(c) 165 | if err != nil { 166 | return nil, err 167 | } 168 | if n == -1 { 169 | return nil, nil 170 | } 171 | 172 | s := make([]interface{}, 0, min(n, sliceElemsAllocLimit)) 173 | for i := 0; i < n; i++ { 174 | v, err := d.DecodeInterface() 175 | if err != nil { 176 | return nil, err 177 | } 178 | s = append(s, v) 179 | } 180 | 181 | return s, nil 182 | } 183 | 184 | func (d *Decoder) skipSlice(c byte) error { 185 | n, err := d.arrayLen(c) 186 | if err != nil { 187 | return err 188 | } 189 | 190 | for i := 0; i < n; i++ { 191 | if err := d.Skip(); err != nil { 192 | return err 193 | } 194 | } 195 | 196 | return nil 197 | } 198 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/decode_string.go: -------------------------------------------------------------------------------- 1 | package msgpack 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | 7 | "gopkg.in/vmihailenco/msgpack.v2/codes" 8 | ) 9 | 10 | func (d *Decoder) bytesLen(c byte) (int, error) { 11 | if c == codes.Nil { 12 | return -1, nil 13 | } else if codes.IsFixedString(c) { 14 | return int(c & codes.FixedStrMask), nil 15 | } 16 | switch c { 17 | case codes.Str8, codes.Bin8: 18 | n, err := d.uint8() 19 | return int(n), err 20 | case codes.Str16, codes.Bin16: 21 | n, err := d.uint16() 22 | return int(n), err 23 | case codes.Str32, codes.Bin32: 24 | n, err := d.uint32() 25 | return int(n), err 26 | } 27 | return 0, fmt.Errorf("msgpack: invalid code %x decoding bytes length", c) 28 | } 29 | 30 | func (d *Decoder) DecodeString() (string, error) { 31 | c, err := d.readByte() 32 | if err != nil { 33 | return "", err 34 | } 35 | return d.string(c) 36 | } 37 | 38 | func (d *Decoder) string(c byte) (string, error) { 39 | n, err := d.bytesLen(c) 40 | if err != nil { 41 | return "", err 42 | } 43 | if n == -1 { 44 | return "", nil 45 | } 46 | b, err := d.readN(n) 47 | return string(b), err 48 | } 49 | 50 | func decodeStringValue(d *Decoder, v reflect.Value) error { 51 | s, err := d.DecodeString() 52 | if err != nil { 53 | return err 54 | } 55 | v.SetString(s) 56 | return nil 57 | } 58 | 59 | func (d *Decoder) DecodeBytesLen() (int, error) { 60 | c, err := d.readByte() 61 | if err != nil { 62 | return 0, err 63 | } 64 | return d.bytesLen(c) 65 | } 66 | 67 | func (d *Decoder) DecodeBytes() ([]byte, error) { 68 | c, err := d.readByte() 69 | if err != nil { 70 | return nil, err 71 | } 72 | return d.bytes(c, nil) 73 | } 74 | 75 | func (d *Decoder) bytes(c byte, b []byte) ([]byte, error) { 76 | n, err := d.bytesLen(c) 77 | if err != nil { 78 | return nil, err 79 | } 80 | if n == -1 { 81 | return nil, nil 82 | } 83 | return readN(d.r, b, n) 84 | } 85 | 86 | func (d *Decoder) bytesNoCopy() ([]byte, error) { 87 | c, err := d.readByte() 88 | if err != nil { 89 | return nil, err 90 | } 91 | n, err := d.bytesLen(c) 92 | if err != nil { 93 | return nil, err 94 | } 95 | if n == -1 { 96 | return nil, nil 97 | } 98 | return d.readN(n) 99 | } 100 | 101 | func (d *Decoder) decodeBytesPtr(ptr *[]byte) error { 102 | c, err := d.readByte() 103 | if err != nil { 104 | return err 105 | } 106 | return d.bytesPtr(c, ptr) 107 | } 108 | 109 | func (d *Decoder) bytesPtr(c byte, ptr *[]byte) error { 110 | n, err := d.bytesLen(c) 111 | if err != nil { 112 | return err 113 | } 114 | if n == -1 { 115 | *ptr = nil 116 | return nil 117 | } 118 | 119 | *ptr, err = readN(d.r, *ptr, n) 120 | return err 121 | } 122 | 123 | func (d *Decoder) skipBytes(c byte) error { 124 | n, err := d.bytesLen(c) 125 | if err != nil { 126 | return err 127 | } 128 | if n == -1 { 129 | return nil 130 | } 131 | return d.skipN(n) 132 | } 133 | 134 | func decodeBytesValue(d *Decoder, v reflect.Value) error { 135 | c, err := d.readByte() 136 | if err != nil { 137 | return err 138 | } 139 | 140 | b, err := d.bytes(c, v.Bytes()) 141 | if err != nil { 142 | return err 143 | } 144 | v.SetBytes(b) 145 | 146 | return nil 147 | } 148 | 149 | func decodeByteArrayValue(d *Decoder, v reflect.Value) error { 150 | c, err := d.readByte() 151 | if err != nil { 152 | return err 153 | } 154 | 155 | n, err := d.bytesLen(c) 156 | if err != nil { 157 | return err 158 | } 159 | if n == -1 { 160 | return nil 161 | } 162 | if n > v.Len() { 163 | return fmt.Errorf("%s len is %d, but msgpack has %d elements", v.Type(), v.Len(), n) 164 | } 165 | 166 | b := v.Slice(0, n).Bytes() 167 | return d.readFull(b) 168 | } 169 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/encode.go: -------------------------------------------------------------------------------- 1 | package msgpack 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "reflect" 7 | "time" 8 | 9 | "gopkg.in/vmihailenco/msgpack.v2/codes" 10 | ) 11 | 12 | type writer interface { 13 | io.Writer 14 | WriteByte(byte) error 15 | WriteString(string) (int, error) 16 | } 17 | 18 | type byteWriter struct { 19 | io.Writer 20 | } 21 | 22 | func (w byteWriter) WriteByte(b byte) error { 23 | _, err := w.Write([]byte{b}) 24 | return err 25 | } 26 | 27 | func (w byteWriter) WriteString(s string) (int, error) { 28 | return w.Write([]byte(s)) 29 | } 30 | 31 | // Marshal returns the MessagePack encoding of v. 32 | func Marshal(v ...interface{}) ([]byte, error) { 33 | var buf bytes.Buffer 34 | err := NewEncoder(&buf).Encode(v...) 35 | return buf.Bytes(), err 36 | } 37 | 38 | type Encoder struct { 39 | w writer 40 | buf []byte 41 | 42 | sortMapKeys bool 43 | structAsArray bool 44 | } 45 | 46 | func NewEncoder(w io.Writer) *Encoder { 47 | bw, ok := w.(writer) 48 | if !ok { 49 | bw = byteWriter{Writer: w} 50 | } 51 | return &Encoder{ 52 | w: bw, 53 | buf: make([]byte, 9), 54 | } 55 | } 56 | 57 | // SortMapKeys causes the Encoder to encode map keys in increasing order. 58 | // Supported map types are: 59 | // - map[string]string 60 | // - map[string]interface{} 61 | func (e *Encoder) SortMapKeys(v bool) *Encoder { 62 | e.sortMapKeys = v 63 | return e 64 | } 65 | 66 | // StructAsArray causes the Encoder to encode Go structs as MessagePack arrays. 67 | func (e *Encoder) StructAsArray(v bool) *Encoder { 68 | e.structAsArray = v 69 | return e 70 | } 71 | 72 | func (e *Encoder) Encode(v ...interface{}) error { 73 | for _, vv := range v { 74 | if err := e.encode(vv); err != nil { 75 | return err 76 | } 77 | } 78 | return nil 79 | } 80 | 81 | func (e *Encoder) encode(v interface{}) error { 82 | switch v := v.(type) { 83 | case nil: 84 | return e.EncodeNil() 85 | case string: 86 | return e.EncodeString(v) 87 | case []byte: 88 | return e.EncodeBytes(v) 89 | case int: 90 | return e.EncodeInt64(int64(v)) 91 | case int64: 92 | return e.EncodeInt64(v) 93 | case uint: 94 | return e.EncodeUint64(uint64(v)) 95 | case uint64: 96 | return e.EncodeUint64(v) 97 | case bool: 98 | return e.EncodeBool(v) 99 | case float32: 100 | return e.EncodeFloat32(v) 101 | case float64: 102 | return e.EncodeFloat64(v) 103 | case time.Duration: 104 | return e.EncodeInt64(int64(v)) 105 | case time.Time: 106 | return e.EncodeTime(v) 107 | } 108 | return e.EncodeValue(reflect.ValueOf(v)) 109 | } 110 | 111 | func (e *Encoder) EncodeValue(v reflect.Value) error { 112 | encode := getEncoder(v.Type()) 113 | return encode(e, v) 114 | } 115 | 116 | func (e *Encoder) EncodeNil() error { 117 | return e.w.WriteByte(codes.Nil) 118 | } 119 | 120 | func (e *Encoder) EncodeBool(value bool) error { 121 | if value { 122 | return e.w.WriteByte(codes.True) 123 | } 124 | return e.w.WriteByte(codes.False) 125 | } 126 | 127 | func (e *Encoder) write(b []byte) error { 128 | _, err := e.w.Write(b) 129 | if err != nil { 130 | return err 131 | } 132 | return nil 133 | } 134 | 135 | func (e *Encoder) writeString(s string) error { 136 | n, err := e.w.WriteString(s) 137 | if err != nil { 138 | return err 139 | } 140 | if n < len(s) { 141 | return io.ErrShortWrite 142 | } 143 | return nil 144 | } 145 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/encode_map.go: -------------------------------------------------------------------------------- 1 | package msgpack 2 | 3 | import ( 4 | "reflect" 5 | "sort" 6 | 7 | "gopkg.in/vmihailenco/msgpack.v2/codes" 8 | ) 9 | 10 | func encodeMapValue(e *Encoder, v reflect.Value) error { 11 | if v.IsNil() { 12 | return e.EncodeNil() 13 | } 14 | 15 | if err := e.EncodeMapLen(v.Len()); err != nil { 16 | return err 17 | } 18 | 19 | for _, key := range v.MapKeys() { 20 | if err := e.EncodeValue(key); err != nil { 21 | return err 22 | } 23 | if err := e.EncodeValue(v.MapIndex(key)); err != nil { 24 | return err 25 | } 26 | } 27 | 28 | return nil 29 | } 30 | 31 | func encodeMapStringStringValue(e *Encoder, v reflect.Value) error { 32 | if v.IsNil() { 33 | return e.EncodeNil() 34 | } 35 | 36 | if err := e.EncodeMapLen(v.Len()); err != nil { 37 | return err 38 | } 39 | 40 | m := v.Convert(mapStringStringType).Interface().(map[string]string) 41 | if e.sortMapKeys { 42 | return e.encodeSortedMapStringString(m) 43 | } 44 | 45 | for mk, mv := range m { 46 | if err := e.EncodeString(mk); err != nil { 47 | return err 48 | } 49 | if err := e.EncodeString(mv); err != nil { 50 | return err 51 | } 52 | } 53 | 54 | return nil 55 | } 56 | 57 | func encodeMapStringInterfaceValue(e *Encoder, v reflect.Value) error { 58 | if v.IsNil() { 59 | return e.EncodeNil() 60 | } 61 | 62 | if err := e.EncodeMapLen(v.Len()); err != nil { 63 | return err 64 | } 65 | 66 | m := v.Convert(mapStringInterfaceType).Interface().(map[string]interface{}) 67 | if e.sortMapKeys { 68 | return e.encodeSortedMapStringInterface(m) 69 | } 70 | 71 | for mk, mv := range m { 72 | if err := e.EncodeString(mk); err != nil { 73 | return err 74 | } 75 | if err := e.Encode(mv); err != nil { 76 | return err 77 | } 78 | } 79 | 80 | return nil 81 | } 82 | 83 | func (e *Encoder) encodeSortedMapStringString(m map[string]string) error { 84 | keys := make([]string, 0, len(m)) 85 | for k, _ := range m { 86 | keys = append(keys, k) 87 | } 88 | sort.Strings(keys) 89 | 90 | for _, k := range keys { 91 | err := e.EncodeString(k) 92 | if err != nil { 93 | return err 94 | } 95 | if err = e.EncodeString(m[k]); err != nil { 96 | return err 97 | } 98 | } 99 | 100 | return nil 101 | } 102 | 103 | func (e *Encoder) encodeSortedMapStringInterface(m map[string]interface{}) error { 104 | keys := make([]string, 0, len(m)) 105 | for k, _ := range m { 106 | keys = append(keys, k) 107 | } 108 | sort.Strings(keys) 109 | 110 | for _, k := range keys { 111 | err := e.EncodeString(k) 112 | if err != nil { 113 | return err 114 | } 115 | if err = e.Encode(m[k]); err != nil { 116 | return err 117 | } 118 | } 119 | 120 | return nil 121 | } 122 | 123 | func (e *Encoder) EncodeMapLen(l int) error { 124 | if l < 16 { 125 | return e.w.WriteByte(codes.FixedMapLow | byte(l)) 126 | } 127 | if l < 65536 { 128 | return e.write2(codes.Map16, uint64(l)) 129 | } 130 | return e.write4(codes.Map32, uint32(l)) 131 | } 132 | 133 | func encodeStructValue(e *Encoder, strct reflect.Value) error { 134 | structFields := structs.Fields(strct.Type()) 135 | if e.structAsArray || structFields.asArray { 136 | return encodeStructValueAsArray(e, strct, structFields.List) 137 | } 138 | fields := structFields.OmitEmpty(strct) 139 | 140 | if err := e.EncodeMapLen(len(fields)); err != nil { 141 | return err 142 | } 143 | 144 | for _, f := range fields { 145 | if err := e.EncodeString(f.name); err != nil { 146 | return err 147 | } 148 | if err := f.EncodeValue(e, strct); err != nil { 149 | return err 150 | } 151 | } 152 | 153 | return nil 154 | } 155 | 156 | func encodeStructValueAsArray(e *Encoder, strct reflect.Value, fields []*field) error { 157 | if err := e.EncodeArrayLen(len(fields)); err != nil { 158 | return err 159 | } 160 | for _, f := range fields { 161 | if err := f.EncodeValue(e, strct); err != nil { 162 | return err 163 | } 164 | } 165 | return nil 166 | } 167 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/encode_number.go: -------------------------------------------------------------------------------- 1 | package msgpack 2 | 3 | import ( 4 | "math" 5 | "reflect" 6 | 7 | "gopkg.in/vmihailenco/msgpack.v2/codes" 8 | ) 9 | 10 | func (e *Encoder) EncodeUint(v uint) error { 11 | return e.EncodeUint64(uint64(v)) 12 | } 13 | 14 | func (e *Encoder) EncodeUint8(v uint8) error { 15 | return e.EncodeUint64(uint64(v)) 16 | } 17 | 18 | func (e *Encoder) EncodeUint16(v uint16) error { 19 | return e.EncodeUint64(uint64(v)) 20 | } 21 | 22 | func (e *Encoder) EncodeUint32(v uint32) error { 23 | return e.EncodeUint64(uint64(v)) 24 | } 25 | 26 | func (e *Encoder) EncodeUint64(v uint64) error { 27 | if v <= math.MaxInt8 { 28 | return e.w.WriteByte(byte(v)) 29 | } 30 | if v <= math.MaxUint8 { 31 | return e.write1(codes.Uint8, v) 32 | } 33 | if v <= math.MaxUint16 { 34 | return e.write2(codes.Uint16, v) 35 | } 36 | if v <= math.MaxUint32 { 37 | return e.write4(codes.Uint32, uint32(v)) 38 | } 39 | return e.write8(codes.Uint64, v) 40 | } 41 | 42 | func (e *Encoder) EncodeInt(v int) error { 43 | return e.EncodeInt64(int64(v)) 44 | } 45 | 46 | func (e *Encoder) EncodeInt8(v int8) error { 47 | return e.EncodeInt64(int64(v)) 48 | } 49 | 50 | func (e *Encoder) EncodeInt16(v int16) error { 51 | return e.EncodeInt64(int64(v)) 52 | } 53 | 54 | func (e *Encoder) EncodeInt32(v int32) error { 55 | return e.EncodeInt64(int64(v)) 56 | } 57 | 58 | func (e *Encoder) EncodeInt64(v int64) error { 59 | if v >= 0 { 60 | return e.EncodeUint64(uint64(v)) 61 | } 62 | if v >= int64(int8(codes.NegFixedNumLow)) { 63 | return e.w.WriteByte(byte(v)) 64 | } 65 | if v >= math.MinInt8 { 66 | return e.write1(codes.Int8, uint64(v)) 67 | } 68 | if v >= math.MinInt16 { 69 | return e.write2(codes.Int16, uint64(v)) 70 | } 71 | if v >= math.MinInt32 { 72 | return e.write4(codes.Int32, uint32(v)) 73 | } 74 | return e.write8(codes.Int64, uint64(v)) 75 | } 76 | 77 | func (e *Encoder) EncodeFloat32(n float32) error { 78 | return e.write4(codes.Float, math.Float32bits(n)) 79 | } 80 | 81 | func (e *Encoder) EncodeFloat64(n float64) error { 82 | return e.write8(codes.Double, math.Float64bits(n)) 83 | } 84 | 85 | func (e *Encoder) write1(code byte, n uint64) error { 86 | e.buf = e.buf[:2] 87 | e.buf[0] = code 88 | e.buf[1] = byte(n) 89 | return e.write(e.buf) 90 | } 91 | 92 | func (e *Encoder) write2(code byte, n uint64) error { 93 | e.buf = e.buf[:3] 94 | e.buf[0] = code 95 | e.buf[1] = byte(n >> 8) 96 | e.buf[2] = byte(n) 97 | return e.write(e.buf) 98 | } 99 | 100 | func (e *Encoder) write4(code byte, n uint32) error { 101 | e.buf = e.buf[:5] 102 | e.buf[0] = code 103 | e.buf[1] = byte(n >> 24) 104 | e.buf[2] = byte(n >> 16) 105 | e.buf[3] = byte(n >> 8) 106 | e.buf[4] = byte(n) 107 | return e.write(e.buf) 108 | } 109 | 110 | func (e *Encoder) write8(code byte, n uint64) error { 111 | e.buf = e.buf[:9] 112 | e.buf[0] = code 113 | e.buf[1] = byte(n >> 56) 114 | e.buf[2] = byte(n >> 48) 115 | e.buf[3] = byte(n >> 40) 116 | e.buf[4] = byte(n >> 32) 117 | e.buf[5] = byte(n >> 24) 118 | e.buf[6] = byte(n >> 16) 119 | e.buf[7] = byte(n >> 8) 120 | e.buf[8] = byte(n) 121 | return e.write(e.buf) 122 | } 123 | 124 | func encodeInt64Value(e *Encoder, v reflect.Value) error { 125 | return e.EncodeInt64(v.Int()) 126 | } 127 | 128 | func encodeUint64Value(e *Encoder, v reflect.Value) error { 129 | return e.EncodeUint64(v.Uint()) 130 | } 131 | 132 | func encodeFloat32Value(e *Encoder, v reflect.Value) error { 133 | return e.EncodeFloat32(float32(v.Float())) 134 | } 135 | 136 | func encodeFloat64Value(e *Encoder, v reflect.Value) error { 137 | return e.EncodeFloat64(v.Float()) 138 | } 139 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/encode_slice.go: -------------------------------------------------------------------------------- 1 | package msgpack 2 | 3 | import ( 4 | "reflect" 5 | 6 | "gopkg.in/vmihailenco/msgpack.v2/codes" 7 | ) 8 | 9 | func encodeStringValue(e *Encoder, v reflect.Value) error { 10 | return e.EncodeString(v.String()) 11 | } 12 | 13 | func encodeByteSliceValue(e *Encoder, v reflect.Value) error { 14 | return e.EncodeBytes(v.Bytes()) 15 | } 16 | 17 | func encodeByteArrayValue(e *Encoder, v reflect.Value) error { 18 | if err := e.EncodeBytesLen(v.Len()); err != nil { 19 | return err 20 | } 21 | 22 | if v.CanAddr() { 23 | b := v.Slice(0, v.Len()).Bytes() 24 | return e.write(b) 25 | } 26 | 27 | b := make([]byte, v.Len()) 28 | reflect.Copy(reflect.ValueOf(b), v) 29 | return e.write(b) 30 | } 31 | 32 | func (e *Encoder) EncodeBytesLen(l int) error { 33 | if l < 256 { 34 | return e.write1(codes.Bin8, uint64(l)) 35 | } 36 | if l < 65536 { 37 | return e.write2(codes.Bin16, uint64(l)) 38 | } 39 | return e.write4(codes.Bin32, uint32(l)) 40 | } 41 | 42 | func (e *Encoder) encodeStrLen(l int) error { 43 | if l < 32 { 44 | return e.w.WriteByte(codes.FixedStrLow | uint8(l)) 45 | } 46 | if l < 256 { 47 | return e.write1(codes.Str8, uint64(l)) 48 | } 49 | if l < 65536 { 50 | return e.write2(codes.Str16, uint64(l)) 51 | } 52 | return e.write4(codes.Str32, uint32(l)) 53 | } 54 | 55 | func (e *Encoder) EncodeString(v string) error { 56 | if err := e.encodeStrLen(len(v)); err != nil { 57 | return err 58 | } 59 | return e.writeString(v) 60 | } 61 | 62 | func (e *Encoder) EncodeBytes(v []byte) error { 63 | if v == nil { 64 | return e.EncodeNil() 65 | } 66 | if err := e.EncodeBytesLen(len(v)); err != nil { 67 | return err 68 | } 69 | return e.write(v) 70 | } 71 | 72 | func (e *Encoder) EncodeArrayLen(l int) error { 73 | if l < 16 { 74 | return e.w.WriteByte(codes.FixedArrayLow | byte(l)) 75 | } 76 | if l < 65536 { 77 | return e.write2(codes.Array16, uint64(l)) 78 | } 79 | return e.write4(codes.Array32, uint32(l)) 80 | } 81 | 82 | // Deprecated. Use EncodeArrayLen instead. 83 | func (e *Encoder) EncodeSliceLen(l int) error { 84 | return e.EncodeArrayLen(l) 85 | } 86 | 87 | func (e *Encoder) encodeStringSlice(s []string) error { 88 | if s == nil { 89 | return e.EncodeNil() 90 | } 91 | if err := e.EncodeArrayLen(len(s)); err != nil { 92 | return err 93 | } 94 | for _, v := range s { 95 | if err := e.EncodeString(v); err != nil { 96 | return err 97 | } 98 | } 99 | return nil 100 | } 101 | 102 | func encodeSliceValue(e *Encoder, v reflect.Value) error { 103 | if v.IsNil() { 104 | return e.EncodeNil() 105 | } 106 | return encodeArrayValue(e, v) 107 | } 108 | 109 | func encodeArrayValue(e *Encoder, v reflect.Value) error { 110 | l := v.Len() 111 | if err := e.EncodeSliceLen(l); err != nil { 112 | return err 113 | } 114 | for i := 0; i < l; i++ { 115 | if err := e.EncodeValue(v.Index(i)); err != nil { 116 | return err 117 | } 118 | } 119 | return nil 120 | } 121 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/encode_value.go: -------------------------------------------------------------------------------- 1 | package msgpack 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | ) 7 | 8 | var valueEncoders []encoderFunc 9 | 10 | func init() { 11 | valueEncoders = []encoderFunc{ 12 | reflect.Bool: encodeBoolValue, 13 | reflect.Int: encodeInt64Value, 14 | reflect.Int8: encodeInt64Value, 15 | reflect.Int16: encodeInt64Value, 16 | reflect.Int32: encodeInt64Value, 17 | reflect.Int64: encodeInt64Value, 18 | reflect.Uint: encodeUint64Value, 19 | reflect.Uint8: encodeUint64Value, 20 | reflect.Uint16: encodeUint64Value, 21 | reflect.Uint32: encodeUint64Value, 22 | reflect.Uint64: encodeUint64Value, 23 | reflect.Float32: encodeFloat32Value, 24 | reflect.Float64: encodeFloat64Value, 25 | reflect.Complex64: encodeUnsupportedValue, 26 | reflect.Complex128: encodeUnsupportedValue, 27 | reflect.Array: encodeArrayValue, 28 | reflect.Chan: encodeUnsupportedValue, 29 | reflect.Func: encodeUnsupportedValue, 30 | reflect.Interface: encodeInterfaceValue, 31 | reflect.Map: encodeMapValue, 32 | reflect.Ptr: encodeUnsupportedValue, 33 | reflect.Slice: encodeSliceValue, 34 | reflect.String: encodeStringValue, 35 | reflect.Struct: encodeStructValue, 36 | reflect.UnsafePointer: encodeUnsupportedValue, 37 | } 38 | } 39 | 40 | func getEncoder(typ reflect.Type) encoderFunc { 41 | if encoder, ok := typEncMap[typ]; ok { 42 | return encoder 43 | } 44 | 45 | if typ.Implements(customEncoderType) { 46 | return encodeCustomValue 47 | } 48 | if typ.Implements(marshalerType) { 49 | return marshalValue 50 | } 51 | 52 | kind := typ.Kind() 53 | 54 | // Addressable struct field value. 55 | if kind != reflect.Ptr { 56 | ptr := reflect.PtrTo(typ) 57 | if ptr.Implements(customEncoderType) { 58 | return encodeCustomValuePtr 59 | } 60 | if ptr.Implements(marshalerType) { 61 | return marshalValuePtr 62 | } 63 | } 64 | 65 | if typ == errorType { 66 | return encodeErrorValue 67 | } 68 | 69 | switch kind { 70 | case reflect.Ptr: 71 | return ptrEncoderFunc(typ) 72 | case reflect.Slice: 73 | if typ.Elem().Kind() == reflect.Uint8 { 74 | return encodeByteSliceValue 75 | } 76 | case reflect.Array: 77 | if typ.Elem().Kind() == reflect.Uint8 { 78 | return encodeByteArrayValue 79 | } 80 | case reflect.Map: 81 | if typ.Key() == stringType { 82 | switch typ.Elem() { 83 | case stringType: 84 | return encodeMapStringStringValue 85 | case interfaceType: 86 | return encodeMapStringInterfaceValue 87 | } 88 | } 89 | } 90 | return valueEncoders[kind] 91 | } 92 | 93 | func ptrEncoderFunc(typ reflect.Type) encoderFunc { 94 | encoder := getEncoder(typ.Elem()) 95 | return func(e *Encoder, v reflect.Value) error { 96 | if v.IsNil() { 97 | return e.EncodeNil() 98 | } 99 | return encoder(e, v.Elem()) 100 | } 101 | } 102 | 103 | func encodeCustomValuePtr(e *Encoder, v reflect.Value) error { 104 | if !v.CanAddr() { 105 | return fmt.Errorf("msgpack: Encode(non-addressable %T)", v.Interface()) 106 | } 107 | encoder := v.Addr().Interface().(CustomEncoder) 108 | return encoder.EncodeMsgpack(e) 109 | } 110 | 111 | func encodeCustomValue(e *Encoder, v reflect.Value) error { 112 | switch v.Kind() { 113 | case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: 114 | if v.IsNil() { 115 | return e.EncodeNil() 116 | } 117 | } 118 | 119 | encoder := v.Interface().(CustomEncoder) 120 | return encoder.EncodeMsgpack(e) 121 | } 122 | 123 | func marshalValuePtr(e *Encoder, v reflect.Value) error { 124 | if !v.CanAddr() { 125 | return fmt.Errorf("msgpack: Encode(non-addressable %T)", v.Interface()) 126 | } 127 | return marshalValue(e, v.Addr()) 128 | } 129 | 130 | func marshalValue(e *Encoder, v reflect.Value) error { 131 | switch v.Kind() { 132 | case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: 133 | if v.IsNil() { 134 | return e.EncodeNil() 135 | } 136 | } 137 | 138 | marshaler := v.Interface().(Marshaler) 139 | b, err := marshaler.MarshalMsgpack() 140 | if err != nil { 141 | return err 142 | } 143 | _, err = e.w.Write(b) 144 | return err 145 | } 146 | 147 | func encodeBoolValue(e *Encoder, v reflect.Value) error { 148 | return e.EncodeBool(v.Bool()) 149 | } 150 | 151 | func encodeInterfaceValue(e *Encoder, v reflect.Value) error { 152 | if v.IsNil() { 153 | return e.EncodeNil() 154 | } 155 | return e.EncodeValue(v.Elem()) 156 | } 157 | 158 | func encodeErrorValue(e *Encoder, v reflect.Value) error { 159 | if v.IsNil() { 160 | return e.EncodeNil() 161 | } 162 | return e.EncodeString(v.Interface().(error).Error()) 163 | } 164 | 165 | func encodeUnsupportedValue(e *Encoder, v reflect.Value) error { 166 | return fmt.Errorf("msgpack: Encode(unsupported %s)", v.Type()) 167 | } 168 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/ext.go: -------------------------------------------------------------------------------- 1 | package msgpack 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "reflect" 7 | "sync" 8 | 9 | "gopkg.in/vmihailenco/msgpack.v2/codes" 10 | ) 11 | 12 | var extTypes []reflect.Type 13 | 14 | var bufferPool = &sync.Pool{ 15 | New: func() interface{} { 16 | return new(bytes.Buffer) 17 | }, 18 | } 19 | 20 | // RegisterExt records a type, identified by a value for that type, 21 | // under the provided id. That id will identify the concrete type of a value 22 | // sent or received as an interface variable. Only types that will be 23 | // transferred as implementations of interface values need to be registered. 24 | // Expecting to be used only during initialization, it panics if the mapping 25 | // between types and ids is not a bijection. 26 | func RegisterExt(id int8, value interface{}) { 27 | if diff := int(id) - len(extTypes) + 1; diff > 0 { 28 | extTypes = append(extTypes, make([]reflect.Type, diff)...) 29 | } 30 | 31 | if extTypes[id] != nil { 32 | panic(fmt.Errorf("msgpack: ext with id=%d is already registered", id)) 33 | } 34 | 35 | typ := reflect.TypeOf(value) 36 | if typ.Kind() == reflect.Ptr { 37 | typ = typ.Elem() 38 | } 39 | ptr := reflect.PtrTo(typ) 40 | 41 | extTypes[id] = typ 42 | decoder := getDecoder(typ) 43 | Register(ptr, makeExtEncoder(id, getEncoder(ptr)), decoder) 44 | Register(typ, makeExtEncoder(id, getEncoder(typ)), decoder) 45 | } 46 | 47 | func makeExtEncoder(id int8, enc encoderFunc) encoderFunc { 48 | return func(e *Encoder, v reflect.Value) error { 49 | buf := bufferPool.Get().(*bytes.Buffer) 50 | defer bufferPool.Put(buf) 51 | buf.Reset() 52 | 53 | oldw := e.w 54 | e.w = buf 55 | err := enc(e, v) 56 | e.w = oldw 57 | 58 | if err != nil { 59 | return err 60 | } 61 | 62 | if err := e.encodeExtLen(buf.Len()); err != nil { 63 | return err 64 | } 65 | if err := e.w.WriteByte(byte(id)); err != nil { 66 | return err 67 | } 68 | return e.write(buf.Bytes()) 69 | } 70 | } 71 | 72 | func (e *Encoder) encodeExtLen(l int) error { 73 | switch l { 74 | case 1: 75 | return e.w.WriteByte(codes.FixExt1) 76 | case 2: 77 | return e.w.WriteByte(codes.FixExt2) 78 | case 4: 79 | return e.w.WriteByte(codes.FixExt4) 80 | case 8: 81 | return e.w.WriteByte(codes.FixExt8) 82 | case 16: 83 | return e.w.WriteByte(codes.FixExt16) 84 | } 85 | if l < 256 { 86 | return e.write1(codes.Ext8, uint64(l)) 87 | } 88 | if l < 65536 { 89 | return e.write2(codes.Ext16, uint64(l)) 90 | } 91 | return e.write4(codes.Ext32, uint32(l)) 92 | } 93 | 94 | func (d *Decoder) decodeExtLen() (int, error) { 95 | c, err := d.readByte() 96 | if err != nil { 97 | return 0, err 98 | } 99 | return d.parseExtLen(c) 100 | } 101 | 102 | func (d *Decoder) parseExtLen(c byte) (int, error) { 103 | switch c { 104 | case codes.FixExt1: 105 | return 1, nil 106 | case codes.FixExt2: 107 | return 2, nil 108 | case codes.FixExt4: 109 | return 4, nil 110 | case codes.FixExt8: 111 | return 8, nil 112 | case codes.FixExt16: 113 | return 16, nil 114 | case codes.Ext8: 115 | n, err := d.uint8() 116 | return int(n), err 117 | case codes.Ext16: 118 | n, err := d.uint16() 119 | return int(n), err 120 | case codes.Ext32: 121 | n, err := d.uint32() 122 | return int(n), err 123 | default: 124 | return 0, fmt.Errorf("msgpack: invalid code %x decoding ext length", c) 125 | } 126 | } 127 | 128 | func (d *Decoder) decodeExt() (interface{}, error) { 129 | c, err := d.readByte() 130 | if err != nil { 131 | return 0, err 132 | } 133 | return d.ext(c) 134 | } 135 | 136 | func (d *Decoder) ext(c byte) (interface{}, error) { 137 | extLen, err := d.parseExtLen(c) 138 | if err != nil { 139 | return nil, err 140 | } 141 | // Save for later use. 142 | d.extLen = extLen 143 | 144 | extId, err := d.readByte() 145 | if err != nil { 146 | return nil, err 147 | } 148 | 149 | if int(extId) >= len(extTypes) { 150 | return nil, fmt.Errorf("msgpack: unregistered ext id=%d", extId) 151 | } 152 | 153 | typ := extTypes[extId] 154 | if typ == nil { 155 | return nil, fmt.Errorf("msgpack: unregistered ext id=%d", extId) 156 | } 157 | 158 | v := reflect.New(typ).Elem() 159 | if err := d.DecodeValue(v); err != nil { 160 | return nil, err 161 | } 162 | 163 | return v.Interface(), nil 164 | } 165 | 166 | func (d *Decoder) skipExt(c byte) error { 167 | n, err := d.parseExtLen(c) 168 | if err != nil { 169 | return err 170 | } 171 | return d.skipN(n) 172 | } 173 | 174 | func (d *Decoder) skipExtHeader(c byte) error { 175 | // Read ext type. 176 | _, err := d.readByte() 177 | if err != nil { 178 | return err 179 | } 180 | // Read ext body len. 181 | for i := 0; i < extHeaderLen(c); i++ { 182 | _, err := d.readByte() 183 | if err != nil { 184 | return err 185 | } 186 | } 187 | return nil 188 | } 189 | 190 | func extHeaderLen(c byte) int { 191 | switch c { 192 | case codes.Ext8: 193 | return 1 194 | case codes.Ext16: 195 | return 2 196 | case codes.Ext32: 197 | return 4 198 | } 199 | return 0 200 | } 201 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/msgpack.go: -------------------------------------------------------------------------------- 1 | package msgpack // import "gopkg.in/vmihailenco/msgpack.v2" 2 | 3 | // Deprecated. Use CustomEncoder. 4 | type Marshaler interface { 5 | MarshalMsgpack() ([]byte, error) 6 | } 7 | 8 | // Deprecated. Use CustomDecoder. 9 | type Unmarshaler interface { 10 | UnmarshalMsgpack([]byte) error 11 | } 12 | 13 | type CustomEncoder interface { 14 | EncodeMsgpack(*Encoder) error 15 | } 16 | 17 | type CustomDecoder interface { 18 | DecodeMsgpack(*Decoder) error 19 | } 20 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/tags.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package msgpack 6 | 7 | import ( 8 | "strings" 9 | ) 10 | 11 | // tagOptions is the string following a comma in a struct field's "json" 12 | // tag, or the empty string. It does not include the leading comma. 13 | type tagOptions string 14 | 15 | // parseTag splits a struct field's json tag into its name and 16 | // comma-separated options. 17 | func parseTag(tag string) (string, tagOptions) { 18 | if idx := strings.Index(tag, ","); idx != -1 { 19 | return tag[:idx], tagOptions(tag[idx+1:]) 20 | } 21 | return tag, tagOptions("") 22 | } 23 | 24 | // Contains reports whether a comma-separated list of options 25 | // contains a particular substr flag. substr must be surrounded by a 26 | // string boundary or commas. 27 | func (o tagOptions) Contains(optionName string) bool { 28 | if len(o) == 0 { 29 | return false 30 | } 31 | s := string(o) 32 | for s != "" { 33 | var next string 34 | i := strings.IndexRune(s, ',') 35 | if i >= 0 { 36 | s, next = s[:i], s[i+1:] 37 | } 38 | if s == optionName { 39 | return true 40 | } 41 | s = next 42 | } 43 | return false 44 | } 45 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/time.go: -------------------------------------------------------------------------------- 1 | package msgpack 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | "time" 7 | 8 | "gopkg.in/vmihailenco/msgpack.v2/codes" 9 | ) 10 | 11 | var timeType = reflect.TypeOf((*time.Time)(nil)).Elem() 12 | 13 | func init() { 14 | Register(timeType, encodeTimeValue, decodeTimeValue) 15 | } 16 | 17 | func (e *Encoder) EncodeTime(tm time.Time) error { 18 | if err := e.w.WriteByte(codes.FixedArrayLow | 2); err != nil { 19 | return err 20 | } 21 | if err := e.EncodeInt64(tm.Unix()); err != nil { 22 | return err 23 | } 24 | return e.EncodeInt(tm.Nanosecond()) 25 | } 26 | 27 | func (d *Decoder) DecodeTime() (time.Time, error) { 28 | b, err := d.readByte() 29 | if err != nil { 30 | return time.Time{}, err 31 | } 32 | if b != 0x92 { 33 | return time.Time{}, fmt.Errorf("msgpack: invalid code %x decoding time", b) 34 | } 35 | 36 | sec, err := d.DecodeInt64() 37 | if err != nil { 38 | return time.Time{}, err 39 | } 40 | nsec, err := d.DecodeInt64() 41 | if err != nil { 42 | return time.Time{}, err 43 | } 44 | return time.Unix(sec, nsec), nil 45 | } 46 | 47 | func encodeTimeValue(e *Encoder, v reflect.Value) error { 48 | tm := v.Interface().(time.Time) 49 | return e.EncodeTime(tm) 50 | } 51 | 52 | func decodeTimeValue(d *Decoder, v reflect.Value) error { 53 | tm, err := d.DecodeTime() 54 | if err != nil { 55 | return err 56 | } 57 | v.Set(reflect.ValueOf(tm)) 58 | return nil 59 | } 60 | -------------------------------------------------------------------------------- /vendor/gopkg.in/vmihailenco/msgpack.v2/types.go: -------------------------------------------------------------------------------- 1 | package msgpack 2 | 3 | import ( 4 | "reflect" 5 | "sync" 6 | ) 7 | 8 | var errorType = reflect.TypeOf((*error)(nil)).Elem() 9 | 10 | var customEncoderType = reflect.TypeOf((*CustomEncoder)(nil)).Elem() 11 | var customDecoderType = reflect.TypeOf((*CustomDecoder)(nil)).Elem() 12 | 13 | var marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem() 14 | var unmarshalerType = reflect.TypeOf((*Unmarshaler)(nil)).Elem() 15 | 16 | type encoderFunc func(*Encoder, reflect.Value) error 17 | type decoderFunc func(*Decoder, reflect.Value) error 18 | 19 | var typEncMap = make(map[reflect.Type]encoderFunc) 20 | var typDecMap = make(map[reflect.Type]decoderFunc) 21 | 22 | // Register registers encoder and decoder functions for a type. 23 | // In most cases you should prefer implementing CustomEncoder and 24 | // CustomDecoder interfaces. 25 | func Register(typ reflect.Type, enc encoderFunc, dec decoderFunc) { 26 | if enc != nil { 27 | typEncMap[typ] = enc 28 | } 29 | if dec != nil { 30 | typDecMap[typ] = dec 31 | } 32 | } 33 | 34 | //------------------------------------------------------------------------------ 35 | 36 | var structs = newStructCache() 37 | 38 | type structCache struct { 39 | l sync.RWMutex 40 | m map[reflect.Type]*fields 41 | } 42 | 43 | func newStructCache() *structCache { 44 | return &structCache{ 45 | m: make(map[reflect.Type]*fields), 46 | } 47 | } 48 | 49 | func (m *structCache) Fields(typ reflect.Type) *fields { 50 | m.l.RLock() 51 | fs, ok := m.m[typ] 52 | m.l.RUnlock() 53 | if !ok { 54 | m.l.Lock() 55 | fs, ok = m.m[typ] 56 | if !ok { 57 | fs = getFields(typ) 58 | m.m[typ] = fs 59 | } 60 | m.l.Unlock() 61 | } 62 | 63 | return fs 64 | } 65 | 66 | //------------------------------------------------------------------------------ 67 | 68 | type field struct { 69 | name string 70 | index []int 71 | omitEmpty bool 72 | 73 | encoder encoderFunc 74 | decoder decoderFunc 75 | } 76 | 77 | func (f *field) value(strct reflect.Value) reflect.Value { 78 | return strct.FieldByIndex(f.index) 79 | } 80 | 81 | func (f *field) Omit(strct reflect.Value) bool { 82 | return f.omitEmpty && isEmptyValue(f.value(strct)) 83 | } 84 | 85 | func (f *field) EncodeValue(e *Encoder, strct reflect.Value) error { 86 | return f.encoder(e, f.value(strct)) 87 | } 88 | 89 | func (f *field) DecodeValue(d *Decoder, strct reflect.Value) error { 90 | return f.decoder(d, f.value(strct)) 91 | } 92 | 93 | //------------------------------------------------------------------------------ 94 | 95 | type fields struct { 96 | List []*field 97 | Table map[string]*field 98 | 99 | asArray bool 100 | omitEmpty bool 101 | } 102 | 103 | func newFields(numField int) *fields { 104 | return &fields{ 105 | List: make([]*field, 0, numField), 106 | Table: make(map[string]*field, numField), 107 | } 108 | } 109 | 110 | func (fs *fields) Len() int { 111 | return len(fs.List) 112 | } 113 | 114 | func (fs *fields) Add(field *field) { 115 | fs.List = append(fs.List, field) 116 | fs.Table[field.name] = field 117 | if field.omitEmpty { 118 | fs.omitEmpty = field.omitEmpty 119 | } 120 | } 121 | 122 | func (fs *fields) OmitEmpty(strct reflect.Value) []*field { 123 | if !fs.omitEmpty { 124 | return fs.List 125 | } 126 | 127 | fields := make([]*field, 0, fs.Len()) 128 | for _, f := range fs.List { 129 | if !f.Omit(strct) { 130 | fields = append(fields, f) 131 | } 132 | } 133 | return fields 134 | } 135 | 136 | func getFields(typ reflect.Type) *fields { 137 | numField := typ.NumField() 138 | fs := newFields(numField) 139 | 140 | var omitEmpty bool 141 | for i := 0; i < numField; i++ { 142 | f := typ.Field(i) 143 | 144 | name, opt := parseTag(f.Tag.Get("msgpack")) 145 | if name == "-" { 146 | continue 147 | } 148 | 149 | if f.Name == "_msgpack" { 150 | if opt.Contains("asArray") { 151 | fs.asArray = true 152 | } 153 | if opt.Contains("omitempty") { 154 | omitEmpty = true 155 | } 156 | } 157 | 158 | if f.PkgPath != "" && !f.Anonymous { 159 | continue 160 | } 161 | 162 | if opt.Contains("inline") { 163 | inlineFields(fs, f) 164 | continue 165 | } 166 | 167 | if name == "" { 168 | name = f.Name 169 | } 170 | field := field{ 171 | name: name, 172 | index: f.Index, 173 | omitEmpty: omitEmpty || opt.Contains("omitempty"), 174 | encoder: getEncoder(f.Type), 175 | decoder: getDecoder(f.Type), 176 | } 177 | fs.Add(&field) 178 | } 179 | return fs 180 | } 181 | 182 | func inlineFields(fs *fields, f reflect.StructField) { 183 | typ := f.Type 184 | if typ.Kind() == reflect.Ptr { 185 | typ = typ.Elem() 186 | } 187 | inlinedFields := getFields(typ).List 188 | for _, field := range inlinedFields { 189 | if _, ok := fs.Table[field.name]; ok { 190 | // Don't overwrite shadowed fields. 191 | continue 192 | } 193 | field.index = append(f.Index, field.index...) 194 | fs.Add(field) 195 | } 196 | } 197 | 198 | func isEmptyValue(v reflect.Value) bool { 199 | switch v.Kind() { 200 | case reflect.Array, reflect.Map, reflect.Slice, reflect.String: 201 | return v.Len() == 0 202 | case reflect.Bool: 203 | return !v.Bool() 204 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 205 | return v.Int() == 0 206 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: 207 | return v.Uint() == 0 208 | case reflect.Float32, reflect.Float64: 209 | return v.Float() == 0 210 | case reflect.Interface, reflect.Ptr: 211 | return v.IsNil() 212 | } 213 | return false 214 | } 215 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.4 5 | - 1.5 6 | - 1.6 7 | - 1.7 8 | - 1.8 9 | - 1.9 10 | - tip 11 | 12 | go_import_path: gopkg.in/yaml.v2 13 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/LICENSE.libyaml: -------------------------------------------------------------------------------- 1 | The following files were ported to Go from C files of libyaml, and thus 2 | are still covered by their original copyright and license: 3 | 4 | apic.go 5 | emitterc.go 6 | parserc.go 7 | readerc.go 8 | scannerc.go 9 | writerc.go 10 | yamlh.go 11 | yamlprivateh.go 12 | 13 | Copyright (c) 2006 Kirill Simonov 14 | 15 | Permission is hereby granted, free of charge, to any person obtaining a copy of 16 | this software and associated documentation files (the "Software"), to deal in 17 | the Software without restriction, including without limitation the rights to 18 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 19 | of the Software, and to permit persons to whom the Software is furnished to do 20 | so, subject to the following conditions: 21 | 22 | The above copyright notice and this permission notice shall be included in all 23 | copies or substantial portions of the Software. 24 | 25 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 | SOFTWARE. 32 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2011-2016 Canonical Ltd. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/README.md: -------------------------------------------------------------------------------- 1 | # YAML support for the Go language 2 | 3 | Introduction 4 | ------------ 5 | 6 | The yaml package enables Go programs to comfortably encode and decode YAML 7 | values. It was developed within [Canonical](https://www.canonical.com) as 8 | part of the [juju](https://juju.ubuntu.com) project, and is based on a 9 | pure Go port of the well-known [libyaml](http://pyyaml.org/wiki/LibYAML) 10 | C library to parse and generate YAML data quickly and reliably. 11 | 12 | Compatibility 13 | ------------- 14 | 15 | The yaml package supports most of YAML 1.1 and 1.2, including support for 16 | anchors, tags, map merging, etc. Multi-document unmarshalling is not yet 17 | implemented, and base-60 floats from YAML 1.1 are purposefully not 18 | supported since they're a poor design and are gone in YAML 1.2. 19 | 20 | Installation and usage 21 | ---------------------- 22 | 23 | The import path for the package is *gopkg.in/yaml.v2*. 24 | 25 | To install it, run: 26 | 27 | go get gopkg.in/yaml.v2 28 | 29 | API documentation 30 | ----------------- 31 | 32 | If opened in a browser, the import path itself leads to the API documentation: 33 | 34 | * [https://gopkg.in/yaml.v2](https://gopkg.in/yaml.v2) 35 | 36 | API stability 37 | ------------- 38 | 39 | The package API for yaml v2 will remain stable as described in [gopkg.in](https://gopkg.in). 40 | 41 | 42 | License 43 | ------- 44 | 45 | The yaml package is licensed under the Apache License 2.0. Please see the LICENSE file for details. 46 | 47 | 48 | Example 49 | ------- 50 | 51 | ```Go 52 | package main 53 | 54 | import ( 55 | "fmt" 56 | "log" 57 | 58 | "gopkg.in/yaml.v2" 59 | ) 60 | 61 | var data = ` 62 | a: Easy! 63 | b: 64 | c: 2 65 | d: [3, 4] 66 | ` 67 | 68 | // Note: struct fields must be public in order for unmarshal to 69 | // correctly populate the data. 70 | type T struct { 71 | A string 72 | B struct { 73 | RenamedC int `yaml:"c"` 74 | D []int `yaml:",flow"` 75 | } 76 | } 77 | 78 | func main() { 79 | t := T{} 80 | 81 | err := yaml.Unmarshal([]byte(data), &t) 82 | if err != nil { 83 | log.Fatalf("error: %v", err) 84 | } 85 | fmt.Printf("--- t:\n%v\n\n", t) 86 | 87 | d, err := yaml.Marshal(&t) 88 | if err != nil { 89 | log.Fatalf("error: %v", err) 90 | } 91 | fmt.Printf("--- t dump:\n%s\n\n", string(d)) 92 | 93 | m := make(map[interface{}]interface{}) 94 | 95 | err = yaml.Unmarshal([]byte(data), &m) 96 | if err != nil { 97 | log.Fatalf("error: %v", err) 98 | } 99 | fmt.Printf("--- m:\n%v\n\n", m) 100 | 101 | d, err = yaml.Marshal(&m) 102 | if err != nil { 103 | log.Fatalf("error: %v", err) 104 | } 105 | fmt.Printf("--- m dump:\n%s\n\n", string(d)) 106 | } 107 | ``` 108 | 109 | This example will generate the following output: 110 | 111 | ``` 112 | --- t: 113 | {Easy! {2 [3 4]}} 114 | 115 | --- t dump: 116 | a: Easy! 117 | b: 118 | c: 2 119 | d: [3, 4] 120 | 121 | 122 | --- m: 123 | map[a:Easy! b:map[c:2 d:[3 4]]] 124 | 125 | --- m dump: 126 | a: Easy! 127 | b: 128 | c: 2 129 | d: 130 | - 3 131 | - 4 132 | ``` 133 | 134 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/go.mod: -------------------------------------------------------------------------------- 1 | module "gopkg.in/yaml.v2" 2 | 3 | require ( 4 | "gopkg.in/check.v1" v0.0.0-20161208181325-20d25e280405 5 | ) 6 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/sorter.go: -------------------------------------------------------------------------------- 1 | package yaml 2 | 3 | import ( 4 | "reflect" 5 | "unicode" 6 | ) 7 | 8 | type keyList []reflect.Value 9 | 10 | func (l keyList) Len() int { return len(l) } 11 | func (l keyList) Swap(i, j int) { l[i], l[j] = l[j], l[i] } 12 | func (l keyList) Less(i, j int) bool { 13 | a := l[i] 14 | b := l[j] 15 | ak := a.Kind() 16 | bk := b.Kind() 17 | for (ak == reflect.Interface || ak == reflect.Ptr) && !a.IsNil() { 18 | a = a.Elem() 19 | ak = a.Kind() 20 | } 21 | for (bk == reflect.Interface || bk == reflect.Ptr) && !b.IsNil() { 22 | b = b.Elem() 23 | bk = b.Kind() 24 | } 25 | af, aok := keyFloat(a) 26 | bf, bok := keyFloat(b) 27 | if aok && bok { 28 | if af != bf { 29 | return af < bf 30 | } 31 | if ak != bk { 32 | return ak < bk 33 | } 34 | return numLess(a, b) 35 | } 36 | if ak != reflect.String || bk != reflect.String { 37 | return ak < bk 38 | } 39 | ar, br := []rune(a.String()), []rune(b.String()) 40 | for i := 0; i < len(ar) && i < len(br); i++ { 41 | if ar[i] == br[i] { 42 | continue 43 | } 44 | al := unicode.IsLetter(ar[i]) 45 | bl := unicode.IsLetter(br[i]) 46 | if al && bl { 47 | return ar[i] < br[i] 48 | } 49 | if al || bl { 50 | return bl 51 | } 52 | var ai, bi int 53 | var an, bn int64 54 | if ar[i] == '0' || br[i] == '0' { 55 | for j := i-1; j >= 0 && unicode.IsDigit(ar[j]); j-- { 56 | if ar[j] != '0' { 57 | an = 1 58 | bn = 1 59 | break 60 | } 61 | } 62 | } 63 | for ai = i; ai < len(ar) && unicode.IsDigit(ar[ai]); ai++ { 64 | an = an*10 + int64(ar[ai]-'0') 65 | } 66 | for bi = i; bi < len(br) && unicode.IsDigit(br[bi]); bi++ { 67 | bn = bn*10 + int64(br[bi]-'0') 68 | } 69 | if an != bn { 70 | return an < bn 71 | } 72 | if ai != bi { 73 | return ai < bi 74 | } 75 | return ar[i] < br[i] 76 | } 77 | return len(ar) < len(br) 78 | } 79 | 80 | // keyFloat returns a float value for v if it is a number/bool 81 | // and whether it is a number/bool or not. 82 | func keyFloat(v reflect.Value) (f float64, ok bool) { 83 | switch v.Kind() { 84 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 85 | return float64(v.Int()), true 86 | case reflect.Float32, reflect.Float64: 87 | return v.Float(), true 88 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: 89 | return float64(v.Uint()), true 90 | case reflect.Bool: 91 | if v.Bool() { 92 | return 1, true 93 | } 94 | return 0, true 95 | } 96 | return 0, false 97 | } 98 | 99 | // numLess returns whether a < b. 100 | // a and b must necessarily have the same kind. 101 | func numLess(a, b reflect.Value) bool { 102 | switch a.Kind() { 103 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 104 | return a.Int() < b.Int() 105 | case reflect.Float32, reflect.Float64: 106 | return a.Float() < b.Float() 107 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: 108 | return a.Uint() < b.Uint() 109 | case reflect.Bool: 110 | return !a.Bool() && b.Bool() 111 | } 112 | panic("not a number") 113 | } 114 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/writerc.go: -------------------------------------------------------------------------------- 1 | package yaml 2 | 3 | // Set the writer error and return false. 4 | func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool { 5 | emitter.error = yaml_WRITER_ERROR 6 | emitter.problem = problem 7 | return false 8 | } 9 | 10 | // Flush the output buffer. 11 | func yaml_emitter_flush(emitter *yaml_emitter_t) bool { 12 | if emitter.write_handler == nil { 13 | panic("write handler not set") 14 | } 15 | 16 | // Check if the buffer is empty. 17 | if emitter.buffer_pos == 0 { 18 | return true 19 | } 20 | 21 | if err := emitter.write_handler(emitter, emitter.buffer[:emitter.buffer_pos]); err != nil { 22 | return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error()) 23 | } 24 | emitter.buffer_pos = 0 25 | return true 26 | } 27 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/yamlprivateh.go: -------------------------------------------------------------------------------- 1 | package yaml 2 | 3 | const ( 4 | // The size of the input raw buffer. 5 | input_raw_buffer_size = 512 6 | 7 | // The size of the input buffer. 8 | // It should be possible to decode the whole raw buffer. 9 | input_buffer_size = input_raw_buffer_size * 3 10 | 11 | // The size of the output buffer. 12 | output_buffer_size = 128 13 | 14 | // The size of the output raw buffer. 15 | // It should be possible to encode the whole output buffer. 16 | output_raw_buffer_size = (output_buffer_size*2 + 2) 17 | 18 | // The size of other stacks and queues. 19 | initial_stack_size = 16 20 | initial_queue_size = 16 21 | initial_string_size = 16 22 | ) 23 | 24 | // Check if the character at the specified position is an alphabetical 25 | // character, a digit, '_', or '-'. 26 | func is_alpha(b []byte, i int) bool { 27 | return b[i] >= '0' && b[i] <= '9' || b[i] >= 'A' && b[i] <= 'Z' || b[i] >= 'a' && b[i] <= 'z' || b[i] == '_' || b[i] == '-' 28 | } 29 | 30 | // Check if the character at the specified position is a digit. 31 | func is_digit(b []byte, i int) bool { 32 | return b[i] >= '0' && b[i] <= '9' 33 | } 34 | 35 | // Get the value of a digit. 36 | func as_digit(b []byte, i int) int { 37 | return int(b[i]) - '0' 38 | } 39 | 40 | // Check if the character at the specified position is a hex-digit. 41 | func is_hex(b []byte, i int) bool { 42 | return b[i] >= '0' && b[i] <= '9' || b[i] >= 'A' && b[i] <= 'F' || b[i] >= 'a' && b[i] <= 'f' 43 | } 44 | 45 | // Get the value of a hex-digit. 46 | func as_hex(b []byte, i int) int { 47 | bi := b[i] 48 | if bi >= 'A' && bi <= 'F' { 49 | return int(bi) - 'A' + 10 50 | } 51 | if bi >= 'a' && bi <= 'f' { 52 | return int(bi) - 'a' + 10 53 | } 54 | return int(bi) - '0' 55 | } 56 | 57 | // Check if the character is ASCII. 58 | func is_ascii(b []byte, i int) bool { 59 | return b[i] <= 0x7F 60 | } 61 | 62 | // Check if the character at the start of the buffer can be printed unescaped. 63 | func is_printable(b []byte, i int) bool { 64 | return ((b[i] == 0x0A) || // . == #x0A 65 | (b[i] >= 0x20 && b[i] <= 0x7E) || // #x20 <= . <= #x7E 66 | (b[i] == 0xC2 && b[i+1] >= 0xA0) || // #0xA0 <= . <= #xD7FF 67 | (b[i] > 0xC2 && b[i] < 0xED) || 68 | (b[i] == 0xED && b[i+1] < 0xA0) || 69 | (b[i] == 0xEE) || 70 | (b[i] == 0xEF && // #xE000 <= . <= #xFFFD 71 | !(b[i+1] == 0xBB && b[i+2] == 0xBF) && // && . != #xFEFF 72 | !(b[i+1] == 0xBF && (b[i+2] == 0xBE || b[i+2] == 0xBF)))) 73 | } 74 | 75 | // Check if the character at the specified position is NUL. 76 | func is_z(b []byte, i int) bool { 77 | return b[i] == 0x00 78 | } 79 | 80 | // Check if the beginning of the buffer is a BOM. 81 | func is_bom(b []byte, i int) bool { 82 | return b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF 83 | } 84 | 85 | // Check if the character at the specified position is space. 86 | func is_space(b []byte, i int) bool { 87 | return b[i] == ' ' 88 | } 89 | 90 | // Check if the character at the specified position is tab. 91 | func is_tab(b []byte, i int) bool { 92 | return b[i] == '\t' 93 | } 94 | 95 | // Check if the character at the specified position is blank (space or tab). 96 | func is_blank(b []byte, i int) bool { 97 | //return is_space(b, i) || is_tab(b, i) 98 | return b[i] == ' ' || b[i] == '\t' 99 | } 100 | 101 | // Check if the character at the specified position is a line break. 102 | func is_break(b []byte, i int) bool { 103 | return (b[i] == '\r' || // CR (#xD) 104 | b[i] == '\n' || // LF (#xA) 105 | b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) 106 | b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) 107 | b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9) // PS (#x2029) 108 | } 109 | 110 | func is_crlf(b []byte, i int) bool { 111 | return b[i] == '\r' && b[i+1] == '\n' 112 | } 113 | 114 | // Check if the character is a line break or NUL. 115 | func is_breakz(b []byte, i int) bool { 116 | //return is_break(b, i) || is_z(b, i) 117 | return ( // is_break: 118 | b[i] == '\r' || // CR (#xD) 119 | b[i] == '\n' || // LF (#xA) 120 | b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) 121 | b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) 122 | b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029) 123 | // is_z: 124 | b[i] == 0) 125 | } 126 | 127 | // Check if the character is a line break, space, or NUL. 128 | func is_spacez(b []byte, i int) bool { 129 | //return is_space(b, i) || is_breakz(b, i) 130 | return ( // is_space: 131 | b[i] == ' ' || 132 | // is_breakz: 133 | b[i] == '\r' || // CR (#xD) 134 | b[i] == '\n' || // LF (#xA) 135 | b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) 136 | b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) 137 | b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029) 138 | b[i] == 0) 139 | } 140 | 141 | // Check if the character is a line break, space, tab, or NUL. 142 | func is_blankz(b []byte, i int) bool { 143 | //return is_blank(b, i) || is_breakz(b, i) 144 | return ( // is_blank: 145 | b[i] == ' ' || b[i] == '\t' || 146 | // is_breakz: 147 | b[i] == '\r' || // CR (#xD) 148 | b[i] == '\n' || // LF (#xA) 149 | b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) 150 | b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) 151 | b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029) 152 | b[i] == 0) 153 | } 154 | 155 | // Determine the width of the character. 156 | func width(b byte) int { 157 | // Don't replace these by a switch without first 158 | // confirming that it is being inlined. 159 | if b&0x80 == 0x00 { 160 | return 1 161 | } 162 | if b&0xE0 == 0xC0 { 163 | return 2 164 | } 165 | if b&0xF0 == 0xE0 { 166 | return 3 167 | } 168 | if b&0xF8 == 0xF0 { 169 | return 4 170 | } 171 | return 0 172 | 173 | } 174 | --------------------------------------------------------------------------------