diff --git a/README.md b/README.md index 3de93d7f..c17414ef 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,14 @@ ## Getting Started Install [Docker](https://docs.docker.com/get-started/overview/), -[Docker Compose](https://docs.docker.com/compose/) (V1 or V2), and +[Docker Compose](https://docs.docker.com/compose/), and [Go](https://go.dev/dl/). ``` -docker-compose -f build/docker-compose.yml up -d +docker compose -f build/docker-compose.yml up -d make test RACE=y make test -docker-compose -f build/docker-compose.yml down +docker compose -f build/docker-compose.yml down ``` ## Running an API Locally @@ -31,11 +31,11 @@ OpenAPI live docs are available at ## Deploying -[Docker Compose](https://docs.docker.com/compose/) (V1 or V2) files for the -Hermes platform and its dependencies are available in `build/deploy/`. These can -be used for a single-system deploy, or as templates for orchestration tooling -such as [Nomad](https://www.nomadproject.io/) or -[Kubernetes](https://kubernetes.io/). Keys should be provided where applicable. +[Docker Compose](https://docs.docker.com/compose/) files for the Hermes platform +and its dependencies are available in `build/deploy/`. These can be used for a +single-system deploy, or as templates for orchestration tooling such as +[Nomad](https://www.nomadproject.io/) or [Kubernetes](https://kubernetes.io/). +Keys should be provided where applicable. ## Use of Build Tags In Tests diff --git a/go.mod b/go.mod index d935fc8b..892ee420 100644 --- a/go.mod +++ b/go.mod @@ -8,17 +8,17 @@ require ( github.com/gregdel/pushover v1.3.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 github.com/jackc/pgx/v5 v5.5.3 - github.com/jellydator/ttlcache/v3 v3.1.1 + github.com/jellydator/ttlcache/v3 v3.2.0 github.com/mennanov/fmutils v0.2.1 github.com/nsqio/go-nsq v1.1.0 github.com/ownmfa/proto/go v1.1.2 - github.com/redis/go-redis/v9 v9.4.0 + github.com/redis/go-redis/v9 v9.5.1 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/smira/go-statsd v1.3.3 github.com/stretchr/testify v1.8.4 go.uber.org/mock v0.4.0 - golang.org/x/crypto v0.19.0 - google.golang.org/grpc v1.61.0 + golang.org/x/crypto v0.20.0 + google.golang.org/grpc v1.62.0 google.golang.org/protobuf v1.32.0 ) @@ -38,8 +38,8 @@ require ( golang.org/x/sync v0.6.0 // indirect golang.org/x/sys v0.17.0 // indirect golang.org/x/text v0.14.0 // indirect - google.golang.org/genproto v0.0.0-20240205150955-31a09d347014 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240205150955-31a09d347014 // indirect + google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index d3241dcf..8539d297 100644 --- a/go.sum +++ b/go.sum @@ -536,8 +536,8 @@ github.com/jackc/pgx/v5 v5.5.3 h1:Ces6/M3wbDXYpM8JyyPD57ivTtJACFZJd885pdIaV2s= github.com/jackc/pgx/v5 v5.5.3/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A= github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= -github.com/jellydator/ttlcache/v3 v3.1.1 h1:RCgYJqo3jgvhl+fEWvjNW8thxGWsgxi+TPhRir1Y9y8= -github.com/jellydator/ttlcache/v3 v3.1.1/go.mod h1:hi7MGFdMAwZna5n2tuvh63DvFLzVKySzCVW6+0gA2n4= +github.com/jellydator/ttlcache/v3 v3.2.0 h1:6lqVJ8X3ZaUwvzENqPAobDsXNExfUJd61u++uW8a3LE= +github.com/jellydator/ttlcache/v3 v3.2.0/go.mod h1:hi7MGFdMAwZna5n2tuvh63DvFLzVKySzCVW6+0gA2n4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -557,8 +557,8 @@ github.com/ownmfa/proto/go v1.1.2/go.mod h1:9+2QP5peqzs3yE5NWUviHtfZV3WGTREI4tzi github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/redis/go-redis/v9 v9.4.0 h1:Yzoz33UZw9I/mFhx4MNrB6Fk+XHO1VukNcCa1+lwyKk= -github.com/redis/go-redis/v9 v9.4.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= +github.com/redis/go-redis/v9 v9.5.1 h1:H1X4D3yHPaYrkL5X06Wh6xNVM/pX0Ft4RV0vMGvLBh8= +github.com/redis/go-redis/v9 v9.5.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= @@ -606,8 +606,8 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= -golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= +golang.org/x/crypto v0.20.0 h1:jmAMJJZXr5KiCw05dfYK9QnqaqKLYXijU23lsEdcQqg= +golang.org/x/crypto v0.20.0/go.mod h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -1045,12 +1045,12 @@ google.golang.org/genproto v0.0.0-20221117204609-8f9c96812029/go.mod h1:rZS5c/ZV google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6/go.mod h1:rZS5c/ZVYMaOGBfO68GWtjOw/eLaZM1X6iVtgjZ+EWg= google.golang.org/genproto v0.0.0-20221201164419-0e50fba7f41c/go.mod h1:rZS5c/ZVYMaOGBfO68GWtjOw/eLaZM1X6iVtgjZ+EWg= google.golang.org/genproto v0.0.0-20230202175211-008b39050e57/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= -google.golang.org/genproto v0.0.0-20240205150955-31a09d347014 h1:g/4bk7P6TPMkAUbUhquq98xey1slwvuVJPosdBqYJlU= -google.golang.org/genproto v0.0.0-20240205150955-31a09d347014/go.mod h1:xEgQu1e4stdSSsxPDK8Azkrk/ECl5HvdPf6nbZrTS5M= -google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014 h1:x9PwdEgd11LgK+orcck69WVRo7DezSO4VUMPI4xpc8A= -google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014/go.mod h1:rbHMSEDyoYX62nRVLOCc4Qt1HbsdytAYoVwgjiOhF3I= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240205150955-31a09d347014 h1:FSL3lRCkhaPFxqi0s9o+V4UI2WTzAVOvkgbd4kVV4Wg= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240205150955-31a09d347014/go.mod h1:SaPjaZGWb0lPqs6Ittu0spdfrOArqji4ZdeP5IC/9N4= +google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c h1:Zmyn5CV/jxzKnF+3d+xzbomACPwLQqVpLTpyXN5uTaQ= +google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo= +google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c h1:9g7erC9qu44ks7UK4gDNlnk4kOxZG707xKm4jVniy6o= +google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:5iCWqnniDlqZHrd3neWVTOwvh/v6s3232omMecelax8= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c h1:NUsgEN92SQQqzfA+YtqYNqYmB3DMMYLlIwUZAQFVFbo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -1087,8 +1087,8 @@ google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCD google.golang.org/grpc v1.50.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc v1.51.0/go.mod h1:wgNDFcnuBGmxLKI/qn4T+m5BtEBYXJPvibbUPsAIPww= -google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0= -google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= +google.golang.org/grpc v1.62.0 h1:HQKZ/fa1bXkX1oFOvSjmZEUL8wLSaZTjCcLAlmZRtdk= +google.golang.org/grpc v1.62.0/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= diff --git a/pkg/cache/redis_test.go b/pkg/cache/redis_test.go index ce77af4d..25f5b159 100644 --- a/pkg/cache/redis_test.go +++ b/pkg/cache/redis_test.go @@ -31,18 +31,16 @@ func TestNewRedis(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can connect %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can connect %+v", test), func(t *testing.T) { t.Parallel() - res, err := NewRedis(lTest.inp) + res, err := NewRedis(test.inp) t.Logf("res, err: %+v, %v", res, err) - if lTest.err == "" { + if test.err == "" { require.NotNil(t, res) require.NoError(t, err) } else { - require.Contains(t, err.Error(), lTest.err) + require.Contains(t, err.Error(), test.err) } }) } diff --git a/pkg/config/parse_test.go b/pkg/config/parse_test.go index 9e93837a..05a20fff 100644 --- a/pkg/config/parse_test.go +++ b/pkg/config/parse_test.go @@ -34,14 +34,12 @@ func TestString(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can parse %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can parse %+v", test), func(t *testing.T) { t.Parallel() - res := String(lTest.inpKey, lTest.inpDef) + res := String(test.inpKey, test.inpDef) t.Logf("res: %v", res) - require.Equal(t, lTest.res, res) + require.Equal(t, test.res, res) }) } } @@ -70,14 +68,12 @@ func TestStringSlice(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can parse %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can parse %+v", test), func(t *testing.T) { t.Parallel() - res := StringSlice(lTest.inpKey, lTest.inpDef) + res := StringSlice(test.inpKey, test.inpDef) t.Logf("res: %#v", res) - require.Equal(t, lTest.res, res) + require.Equal(t, test.res, res) }) } } @@ -101,14 +97,12 @@ func TestInt(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can parse %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can parse %+v", test), func(t *testing.T) { t.Parallel() - res := Int(lTest.inpKey, lTest.inpDef) + res := Int(test.inpKey, test.inpDef) t.Logf("res: %v", res) - require.Equal(t, lTest.res, res) + require.Equal(t, test.res, res) }) } } @@ -131,14 +125,12 @@ func TestBool(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can parse %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can parse %+v", test), func(t *testing.T) { t.Parallel() - res := Bool(lTest.inpKey, lTest.inpDef) + res := Bool(test.inpKey, test.inpDef) t.Logf("res: %v", res) - require.Equal(t, lTest.res, res) + require.Equal(t, test.res, res) }) } } @@ -162,14 +154,12 @@ func TestDuration(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can parse %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can parse %+v", test), func(t *testing.T) { t.Parallel() - res := Duration(lTest.inpKey, lTest.inpDef) + res := Duration(test.inpKey, test.inpDef) t.Logf("res: %#v", res) - require.Equal(t, lTest.res, res) + require.Equal(t, test.res, res) }) } } @@ -197,14 +187,12 @@ func TestByteSlice(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can parse %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can parse %+v", test), func(t *testing.T) { t.Parallel() - res := ByteSlice(lTest.inp) + res := ByteSlice(test.inp) t.Logf("res: %x", res) - require.Equal(t, lTest.res, res) + require.Equal(t, test.res, res) }) } } diff --git a/pkg/consterr/consterr_test.go b/pkg/consterr/consterr_test.go index 2a45b31f..a1a2bdc4 100644 --- a/pkg/consterr/consterr_test.go +++ b/pkg/consterr/consterr_test.go @@ -13,10 +13,8 @@ import ( func TestOrg(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can error %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can error %v", i), func(t *testing.T) { t.Parallel() errStr := random.String(10) diff --git a/pkg/crypto/encrypt_test.go b/pkg/crypto/encrypt_test.go index e3fa7be8..be07cfdd 100644 --- a/pkg/crypto/encrypt_test.go +++ b/pkg/crypto/encrypt_test.go @@ -33,15 +33,13 @@ func TestEncrypt(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can encrypt %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can encrypt %+v", test), func(t *testing.T) { t.Parallel() - res, err := Encrypt(lTest.inpKey, lTest.inpPlaintext) + res, err := Encrypt(test.inpKey, test.inpPlaintext) t.Logf("res, err: %x, %v", res, err) - require.Len(t, res, lTest.resLen) - require.Equal(t, lTest.err, err) + require.Len(t, res, test.resLen) + require.Equal(t, test.err, err) }) } } @@ -70,24 +68,22 @@ func TestDecrypt(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can encrypt %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can encrypt %+v", test), func(t *testing.T) { t.Parallel() - resEnc, err := Encrypt(lTest.inpEncKey, lTest.inpPlaintext) + resEnc, err := Encrypt(test.inpEncKey, test.inpPlaintext) t.Logf("resEnc, err: %x, %v", resEnc, err) require.NoError(t, err) var resDec []byte - if lTest.inpCiphertext == nil { - resDec, err = Decrypt(lTest.inpDecKey, resEnc) + if test.inpCiphertext == nil { + resDec, err = Decrypt(test.inpDecKey, resEnc) } else { - resDec, err = Decrypt(lTest.inpDecKey, lTest.inpCiphertext) + resDec, err = Decrypt(test.inpDecKey, test.inpCiphertext) } t.Logf("resDec, err: %x, %#v", resDec, err) - require.Equal(t, lTest.inpPlaintext, resDec) - require.Equal(t, lTest.err, err) + require.Equal(t, test.inpPlaintext, resDec) + require.Equal(t, test.err, err) }) } } diff --git a/pkg/crypto/password_test.go b/pkg/crypto/password_test.go index 5438da20..aa4350cc 100644 --- a/pkg/crypto/password_test.go +++ b/pkg/crypto/password_test.go @@ -26,14 +26,12 @@ func TestCheckPass(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can check %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can check %+v", test), func(t *testing.T) { t.Parallel() - err := CheckPass(lTest.inp) + err := CheckPass(test.inp) t.Logf("err: %v", err) - require.Equal(t, lTest.err, err) + require.Equal(t, test.err, err) }) } } diff --git a/pkg/dao/app/crudl_test.go b/pkg/dao/app/crudl_test.go index a8c51d90..efc85bbe 100644 --- a/pkg/dao/app/crudl_test.go +++ b/pkg/dao/app/crudl_test.go @@ -316,7 +316,7 @@ func TestList(t *testing.T) { appEmails := []string{} appPushoverKeys := []string{} appTSes := []time.Time{} - for i := 0; i < 3; i++ { + for range 3 { createApp, err := globalAppDAO.Create(ctx, random.App("dao-app", createOrg.GetId())) t.Logf("createApp, err: %+v, %v", createApp, err) diff --git a/pkg/dao/error_test.go b/pkg/dao/error_test.go index 52ccafd8..7e6b1f98 100644 --- a/pkg/dao/error_test.go +++ b/pkg/dao/error_test.go @@ -49,14 +49,12 @@ func TestDBToSentinel(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can map %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can map %+v", test), func(t *testing.T) { t.Parallel() - res := DBToSentinel(lTest.inp) + res := DBToSentinel(test.inp) t.Logf("res: %#v", res) - require.Equal(t, lTest.res, res) + require.Equal(t, test.res, res) }) } } diff --git a/pkg/dao/event/crudl_test.go b/pkg/dao/event/crudl_test.go index bec2440d..0dec6ddc 100644 --- a/pkg/dao/event/crudl_test.go +++ b/pkg/dao/event/crudl_test.go @@ -71,7 +71,7 @@ func TestList(t *testing.T) { events := []*api.Event{} - for i := 0; i < 5; i++ { + for range 5 { event := random.Event("dao-event", createOrg.GetId()) event.IdentityId = identityID events = append(events, event) @@ -163,7 +163,7 @@ func TestLatest(t *testing.T) { events := []*api.Event{} - for i := 0; i < 5; i++ { + for range 5 { event := random.Event("dao-event", createOrg.GetId()) events = append(events, event) diff --git a/pkg/dao/identity/crudl_test.go b/pkg/dao/identity/crudl_test.go index d00a7cae..3929e03b 100644 --- a/pkg/dao/identity/crudl_test.go +++ b/pkg/dao/identity/crudl_test.go @@ -661,7 +661,7 @@ func TestList(t *testing.T) { identityIDs := []string{} identityComments := []string{} identityTSes := []time.Time{} - for i := 0; i < 3; i++ { + for range 3 { createIdentity, _, _, err := globalIdentDAO.Create(ctx, random.HOTPIdentity("dao-identity", createOrg.GetId(), createApp.GetId())) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) diff --git a/pkg/dao/identity/method_test.go b/pkg/dao/identity/method_test.go index 1d9e4935..68500adf 100644 --- a/pkg/dao/identity/method_test.go +++ b/pkg/dao/identity/method_test.go @@ -147,27 +147,25 @@ func TestMethodToOTP(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can convert %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can convert %+v", test), func(t *testing.T) { t.Parallel() identity := random.HOTPIdentity("dao-identity", uuid.NewString(), uuid.NewString()) - identity.MethodOneof = lTest.inp.GetMethodOneof() + identity.MethodOneof = test.inp.GetMethodOneof() otp, meta, err := methodToOTP(identity) t.Logf("otp, meta, err: %#v, %#v, %v", otp, meta, err) // Normalize secret. - if lTest.resOTP != nil { + if test.resOTP != nil { require.Len(t, otp.Key, 32) - lTest.resOTP.Key = otp.Key + test.resOTP.Key = otp.Key } - require.Equal(t, lTest.resOTP, otp) - require.Equal(t, lTest.resMeta, meta) - require.Equal(t, lTest.err, err) + require.Equal(t, test.resOTP, otp) + require.Equal(t, test.resMeta, meta) + require.Equal(t, test.err, err) }) } } @@ -291,19 +289,17 @@ func TestOTPToMethod(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can modify %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can modify %+v", test), func(t *testing.T) { t.Parallel() identity := &api.Identity{} - otpToMethod(identity, lTest.inpOTP, lTest.inpMeta) + otpToMethod(identity, test.inpOTP, test.inpMeta) t.Logf("identity: %+v", identity) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 - if !proto.Equal(lTest.res, identity) { - t.Fatalf("\nExpect: %+v\nActual: %+v", lTest.res, identity) + if !proto.Equal(test.res, identity) { + t.Fatalf("\nExpect: %+v\nActual: %+v", test.res, identity) } }) } diff --git a/pkg/dao/key/crudl_test.go b/pkg/dao/key/crudl_test.go index 9642be07..c9d80834 100644 --- a/pkg/dao/key/crudl_test.go +++ b/pkg/dao/key/crudl_test.go @@ -209,7 +209,7 @@ func TestList(t *testing.T) { keyNames := []string{} keyRoles := []api.Role{} keyTSes := []time.Time{} - for i := 0; i < 3; i++ { + for range 3 { createKey, err := globalKeyDAO.Create(ctx, random.Key("dao-key", createOrg.GetId())) t.Logf("createKey, err: %+v, %v", createKey, err) diff --git a/pkg/dao/org/crudl_test.go b/pkg/dao/org/crudl_test.go index 0fe48d14..6ce95903 100644 --- a/pkg/dao/org/crudl_test.go +++ b/pkg/dao/org/crudl_test.go @@ -374,7 +374,7 @@ func TestList(t *testing.T) { orgNames := []string{} orgPlans := []api.Plan{} orgTSes := []time.Time{} - for i := 0; i < 3; i++ { + for range 3 { createOrg, err := globalOrgDAO.Create(ctx, random.Org("dao-org")) t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) diff --git a/pkg/dao/org/key_test.go b/pkg/dao/org/key_test.go index aad8262a..68b2a5d6 100644 --- a/pkg/dao/org/key_test.go +++ b/pkg/dao/org/key_test.go @@ -13,10 +13,8 @@ import ( func TestOrgKey(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can key %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can key %v", i), func(t *testing.T) { t.Parallel() orgID := uuid.NewString() diff --git a/pkg/dao/pg_db_test.go b/pkg/dao/pg_db_test.go index 0a34b44c..9aab02ad 100644 --- a/pkg/dao/pg_db_test.go +++ b/pkg/dao/pg_db_test.go @@ -30,18 +30,16 @@ func TestNewPgDB(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can connect %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can connect %+v", test), func(t *testing.T) { t.Parallel() - res, err := NewPgDB(lTest.inp) + res, err := NewPgDB(test.inp) t.Logf("res, err: %+v, %#v", res, err) - if lTest.err == "" { + if test.err == "" { require.NotNil(t, res) require.NoError(t, err) } else { - require.Contains(t, err.Error(), lTest.err) + require.Contains(t, err.Error(), test.err) } }) } diff --git a/pkg/dao/user/crudl_test.go b/pkg/dao/user/crudl_test.go index 615a3cf4..48dec1b5 100644 --- a/pkg/dao/user/crudl_test.go +++ b/pkg/dao/user/crudl_test.go @@ -506,7 +506,7 @@ func TestList(t *testing.T) { userNames := []string{} userRoles := []api.Role{} userTSes := []time.Time{} - for i := 0; i < 3; i++ { + for range 3 { createUser, err := globalUserDAO.Create(ctx, random.User("dao-user", createOrg.GetId())) t.Logf("createUser, err: %+v, %v", createUser, err) diff --git a/pkg/hlog/default_test.go b/pkg/hlog/default_test.go index 2a7c7947..cdd70d5d 100644 --- a/pkg/hlog/default_test.go +++ b/pkg/hlog/default_test.go @@ -14,18 +14,16 @@ func TestDefault(t *testing.T) { logDef := Default() t.Logf("logDef: %#v", logDef) - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can log %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can log %v", i), func(t *testing.T) { t.Parallel() logDef.Debug("Debug") - logDef.Debugf("Debugf: %v", lTest) + logDef.Debugf("Debugf: %v", i) logDef.Info("Info") - logDef.Infof("Infof: %v", lTest) + logDef.Infof("Infof: %v", i) logDef.Error("Error") - logDef.Errorf("Errorf: %v", lTest) + logDef.Errorf("Errorf: %v", i) // Do not test Fatal* due to os.Exit. }) } @@ -34,18 +32,16 @@ func TestDefault(t *testing.T) { func TestDefaultConsole(t *testing.T) { SetDefault(NewConsole("DEBUG")) - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can log %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can log %v", i), func(t *testing.T) { t.Parallel() Debug("Debug") - Debugf("Debugf: %v", lTest) + Debugf("Debugf: %v", i) Info("Info") - Infof("Infof: %v", lTest) + Infof("Infof: %v", i) Error("Error") - Errorf("Errorf: %v", lTest) + Errorf("Errorf: %v", i) // Do not test Fatal* due to os.Exit. }) } @@ -54,18 +50,16 @@ func TestDefaultConsole(t *testing.T) { func TestDefaultJSON(t *testing.T) { SetDefault(NewJSON("DEBUG")) - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can log %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can log %v", i), func(t *testing.T) { t.Parallel() Debug("Debug") - Debugf("Debugf: %v", lTest) + Debugf("Debugf: %v", i) Info("Info") - Infof("Infof: %v", lTest) + Infof("Infof: %v", i) Error("Error") - Errorf("Errorf: %v", lTest) + Errorf("Errorf: %v", i) // Do not test Fatal* due to os.Exit. }) } @@ -74,21 +68,19 @@ func TestDefaultJSON(t *testing.T) { func TestDefaultWithField(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can log %v with string", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can log %v with string", i), func(t *testing.T) { t.Parallel() - logField := WithField(strconv.Itoa(lTest), random.String(10)) + logField := WithField(strconv.Itoa(i), random.String(10)) t.Logf("logField: %#v", logField) logField.Debug("Debug") - logField.Debugf("Debugf: %v", lTest) + logField.Debugf("Debugf: %v", i) logField.Info("Info") - logField.Infof("Infof: %v", lTest) + logField.Infof("Infof: %v", i) logField.Error("Error") - logField.Errorf("Errorf: %v", lTest) + logField.Errorf("Errorf: %v", i) // Do not test Fatal* due to os.Exit. }) } diff --git a/pkg/hlog/slog_test.go b/pkg/hlog/slog_test.go index f81d37ea..145c8c62 100644 --- a/pkg/hlog/slog_test.go +++ b/pkg/hlog/slog_test.go @@ -22,20 +22,18 @@ func TestStlogLevel(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can log %v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can log %v", test), func(t *testing.T) { t.Parallel() - logLevel := newStlogConsole(lTest) + logLevel := newStlogConsole(test) t.Logf("logLevel: %#v", logLevel) logLevel.Debug("Debug") - logLevel.Debugf("Debugf: %v and above", lTest) + logLevel.Debugf("Debugf: %v and above", test) logLevel.Info("Info") - logLevel.Infof("Infof: %v and above", lTest) + logLevel.Infof("Infof: %v and above", test) logLevel.Error("Error") - logLevel.Errorf("Errorf: %v and above", lTest) + logLevel.Errorf("Errorf: %v and above", test) // Do not test Fatal* due to os.Exit. }) } @@ -47,21 +45,19 @@ func TestStlogWithField(t *testing.T) { logger := newStlogJSON("DEBUG") t.Logf("logger: %#v", logger) - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can log %v with string", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can log %v with string", i), func(t *testing.T) { t.Parallel() - logField := logger.WithField(strconv.Itoa(lTest), random.String(10)) + logField := logger.WithField(strconv.Itoa(i), random.String(10)) t.Logf("logField: %#v", logField) logField.Debug("Debug") - logField.Debugf("Debugf: %v", lTest) + logField.Debugf("Debugf: %v", i) logField.Info("Info") - logField.Infof("Infof: %v", lTest) + logField.Infof("Infof: %v", i) logField.Error("Error") - logField.Errorf("Errorf: %v", lTest) + logField.Errorf("Errorf: %v", i) // Do not test Fatal* due to os.Exit. }) } diff --git a/pkg/key/key_test.go b/pkg/key/key_test.go index 344134fd..0336a202 100644 --- a/pkg/key/key_test.go +++ b/pkg/key/key_test.go @@ -14,10 +14,8 @@ import ( func TestHOTPCounter(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can key %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can key %v", i), func(t *testing.T) { t.Parallel() orgID := uuid.NewString() @@ -37,10 +35,8 @@ func TestHOTPCounter(t *testing.T) { func TestExpire(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can key %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can key %v", i), func(t *testing.T) { t.Parallel() orgID := uuid.NewString() diff --git a/pkg/metric/default_test.go b/pkg/metric/default_test.go index b016200f..e0cfb0a0 100644 --- a/pkg/metric/default_test.go +++ b/pkg/metric/default_test.go @@ -14,10 +14,8 @@ func TestDefault(t *testing.T) { metricer := getDefault() t.Logf("metricer: %#v", metricer) - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can send %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can send %v", i), func(t *testing.T) { t.Parallel() metricer.Incr(random.String(10), nil) @@ -32,10 +30,8 @@ func TestDefault(t *testing.T) { } func TestDefaultNoOp(t *testing.T) { - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can send %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can send %v", i), func(t *testing.T) { t.Parallel() Incr(random.String(10), nil) diff --git a/pkg/metric/noop_test.go b/pkg/metric/noop_test.go index 557eed3e..702a9fc7 100644 --- a/pkg/metric/noop_test.go +++ b/pkg/metric/noop_test.go @@ -16,10 +16,8 @@ func TestNoOp(t *testing.T) { metricer := &noOpMetric{} t.Logf("metricer: %#v", metricer) - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can send %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can send %v", i), func(t *testing.T) { t.Parallel() metricer.Incr(random.String(10), nil) diff --git a/pkg/metric/statsd_test.go b/pkg/metric/statsd_test.go index c2759081..88f98b2e 100644 --- a/pkg/metric/statsd_test.go +++ b/pkg/metric/statsd_test.go @@ -21,10 +21,8 @@ func TestStatsD(t *testing.T) { } t.Logf("metStats: %#v", metStats) - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can send %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can send %v", i), func(t *testing.T) { t.Parallel() metStats.Incr(random.String(10), nil) @@ -41,10 +39,8 @@ func TestStatsD(t *testing.T) { func TestSetStatsD(t *testing.T) { SetStatsD("127.0.0.1:8125", "testnewstatsd") - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can send %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can send %v", i), func(t *testing.T) { t.Parallel() Incr(random.String(10), nil) @@ -63,10 +59,8 @@ func TestNewStatsDNoAddr(t *testing.T) { SetStatsD("", "testnewstatsdnoaddr") - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can send %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can send %v", i), func(t *testing.T) { t.Parallel() Incr(random.String(10), nil) diff --git a/pkg/notify/fake_test.go b/pkg/notify/fake_test.go index 43c58963..1d9306f0 100644 --- a/pkg/notify/fake_test.go +++ b/pkg/notify/fake_test.go @@ -18,10 +18,8 @@ func TestNewFake(t *testing.T) { notifier := NewFake() t.Logf("notifier: %#v", notifier) - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can notify %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can notify %v", i), func(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.Background(), diff --git a/pkg/oath/hotp.go b/pkg/oath/hotp.go index 00b6f09f..93f5dd5d 100644 --- a/pkg/oath/hotp.go +++ b/pkg/oath/hotp.go @@ -37,7 +37,7 @@ func (o *OTP) HOTP(counter int64) (string, error) { func (o *OTP) VerifyHOTP(lookAhead int, counter int64, passcode string) ( int64, error, ) { - for i := 0; i < lookAhead; i++ { + for i := range lookAhead { pass, err := o.HOTP(counter + int64(i)) if err != nil { return 0, err diff --git a/pkg/oath/hotp_test.go b/pkg/oath/hotp_test.go index 21f11b63..9ef96a16 100644 --- a/pkg/oath/hotp_test.go +++ b/pkg/oath/hotp_test.go @@ -42,23 +42,21 @@ func TestHOTP(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can generate %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can generate %+v", test), func(t *testing.T) { t.Parallel() otp := &OTP{ - Algorithm: HOTP, Hash: lTest.inpHash, Key: lTest.inpKey, - Digits: lTest.inpDigits, + Algorithm: HOTP, Hash: test.inpHash, Key: test.inpKey, + Digits: test.inpDigits, } - res, err := otp.HOTP(lTest.inpCounter) + res, err := otp.HOTP(test.inpCounter) t.Logf("res, err: %v, %v", res, err) - require.Len(t, res, lTest.resDigits) - if lTest.resCode != "" { - require.Equal(t, lTest.resCode, res) + require.Len(t, res, test.resDigits) + if test.resCode != "" { + require.Equal(t, test.resCode, res) } - require.Equal(t, lTest.err, err) + require.Equal(t, test.err, err) }) } } @@ -86,20 +84,18 @@ func TestVerifyHOTP(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can generate %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can generate %+v", test), func(t *testing.T) { t.Parallel() otp := &OTP{ - Algorithm: HOTP, Hash: lTest.inpHash, Key: lTest.inpKey, - Digits: lTest.inpDigits, + Algorithm: HOTP, Hash: test.inpHash, Key: test.inpKey, + Digits: test.inpDigits, } - res, err := otp.VerifyHOTP(DefaultHOTPLookAhead, 0, lTest.inpCode) + res, err := otp.VerifyHOTP(DefaultHOTPLookAhead, 0, test.inpCode) t.Logf("res, err: %v, %v", res, err) - require.Equal(t, lTest.res, res) - require.Equal(t, lTest.err, err) + require.Equal(t, test.res, res) + require.Equal(t, test.err, err) }) } } diff --git a/pkg/oath/oath_test.go b/pkg/oath/oath_test.go index ef8dc7e6..4d53768d 100644 --- a/pkg/oath/oath_test.go +++ b/pkg/oath/oath_test.go @@ -53,19 +53,17 @@ func TestValidate(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can validate %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can validate %+v", test), func(t *testing.T) { t.Parallel() otp := &OTP{ - Algorithm: lTest.inpAlg, Hash: lTest.inpHash, Key: lTest.inpKey, - Digits: lTest.inpDigits, + Algorithm: test.inpAlg, Hash: test.inpHash, Key: test.inpKey, + Digits: test.inpDigits, } err := otp.validate() t.Logf("err:%v", err) - require.Equal(t, lTest.err, err) + require.Equal(t, test.err, err) }) } } @@ -113,20 +111,18 @@ func TestUri(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can generate %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can generate %+v", test), func(t *testing.T) { t.Parallel() otp := &OTP{ - Algorithm: lTest.inpAlg, Hash: lTest.inpHash, Key: lTest.inpKey, - Digits: lTest.inpDigits, AccountName: lTest.inpAccount, + Algorithm: test.inpAlg, Hash: test.inpHash, Key: test.inpKey, + Digits: test.inpDigits, AccountName: test.inpAccount, } - res, err := otp.uri(lTest.inpIssuer) + res, err := otp.uri(test.inpIssuer) t.Logf("res, err: %v, %v", res, err) - require.Equal(t, lTest.res, res) - require.Equal(t, lTest.err, err) + require.Equal(t, test.res, res) + require.Equal(t, test.err, err) uri, err := url.Parse(res) t.Logf("uri, err: %#v, %v", uri, err) @@ -162,22 +158,20 @@ func TestQR(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can generate %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can generate %+v", test), func(t *testing.T) { t.Parallel() otp := &OTP{ - Algorithm: lTest.inpAlg, Hash: lTest.inpHash, Key: lTest.inpKey, - Digits: lTest.inpDigits, AccountName: lTest.inpAccount, + Algorithm: test.inpAlg, Hash: test.inpHash, Key: test.inpKey, + Digits: test.inpDigits, AccountName: test.inpAccount, } - res, err := otp.QR(lTest.inpIssuer) + res, err := otp.QR(test.inpIssuer) t.Logf("res, err: %x, %v", res, err) - if lTest.err == nil { + if test.err == nil { require.Greater(t, len(res), 800) } - require.Equal(t, lTest.err, err) + require.Equal(t, test.err, err) }) } } diff --git a/pkg/oath/totp_test.go b/pkg/oath/totp_test.go index 2d9a3aa5..1d76435f 100644 --- a/pkg/oath/totp_test.go +++ b/pkg/oath/totp_test.go @@ -44,28 +44,26 @@ func TestTOTP(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can generate %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can generate %+v", test), func(t *testing.T) { t.Parallel() otp := &OTP{ - Algorithm: TOTP, Hash: lTest.inpHash, Key: lTest.inpKey, - Digits: lTest.inpDigits, + Algorithm: TOTP, Hash: test.inpHash, Key: test.inpKey, + Digits: test.inpDigits, } - res, err := otp.TOTP(lTest.inpTime) + res, err := otp.TOTP(test.inpTime) t.Logf("res, err: %v, %v", res, err) - require.Len(t, res, lTest.resDigits) - if lTest.resCode != "" { - require.Equal(t, lTest.resCode, res) + require.Len(t, res, test.resDigits) + if test.resCode != "" { + require.Equal(t, test.resCode, res) } - require.Equal(t, lTest.err, err) + require.Equal(t, test.err, err) res, err = otp.TOTP(time.Now()) t.Logf("res, err: %v, %v", res, err) - require.Len(t, res, lTest.resDigits) - require.Equal(t, lTest.err, err) + require.Len(t, res, test.resDigits) + require.Equal(t, test.err, err) }) } } @@ -98,32 +96,30 @@ func TestVerifyTOTP(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can generate %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can generate %+v", test), func(t *testing.T) { t.Parallel() otp := &OTP{ - Algorithm: TOTP, Hash: lTest.inpHash, Key: lTest.inpKey, - Digits: lTest.inpDigits, + Algorithm: TOTP, Hash: test.inpHash, Key: test.inpKey, + Digits: test.inpDigits, } - res, err := otp.verifyTOTP(DefaultTOTPLookAhead, lTest.inpOffset, - lTest.inpTime, lTest.inpCode) + res, err := otp.verifyTOTP(DefaultTOTPLookAhead, test.inpOffset, + test.inpTime, test.inpCode) t.Logf("res, err: %v, %v", res, err) - require.Equal(t, lTest.res, res) - require.Equal(t, lTest.err, err) + require.Equal(t, test.res, res) + require.Equal(t, test.err, err) - if lTest.err == nil { + if test.err == nil { code, err := otp.TOTP(time.Now().Add(time.Duration( - lTest.res*period) * time.Second)) + test.res*period) * time.Second)) t.Logf("code, err: %v, %v", code, err) require.NoError(t, err) - res, err = otp.VerifyTOTP(DefaultTOTPLookAhead, lTest.inpOffset, + res, err = otp.VerifyTOTP(DefaultTOTPLookAhead, test.inpOffset, code) t.Logf("res, err: %v, %v", res, err) - require.Equal(t, lTest.res, res) + require.Equal(t, test.res, res) require.NoError(t, err) } }) diff --git a/pkg/queue/nsq_test.go b/pkg/queue/nsq_test.go index 38c6c666..d70f88eb 100644 --- a/pkg/queue/nsq_test.go +++ b/pkg/queue/nsq_test.go @@ -32,19 +32,17 @@ func TestNewNSQ(t *testing.T) { } for _, test := range tests { - lTest := test - - t.Run(fmt.Sprintf("Can connect %+v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can connect %+v", test), func(t *testing.T) { t.Parallel() - res, err := NewNSQ(lTest.inpPubAddr, lTest.inpLookupAddrs, + res, err := NewNSQ(test.inpPubAddr, test.inpLookupAddrs, "testNewNSQ-"+random.String(10)) t.Logf("res, err: %+v, %v", res, err) - if lTest.err == "" { + if test.err == "" { require.NotNil(t, res) require.NoError(t, err) } else { - require.Contains(t, err.Error(), lTest.err) + require.Contains(t, err.Error(), test.err) } }) } diff --git a/pkg/test/random/api_test.go b/pkg/test/random/api_test.go index 5bf10421..7c526fab 100644 --- a/pkg/test/random/api_test.go +++ b/pkg/test/random/api_test.go @@ -14,10 +14,8 @@ import ( func TestOrg(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can generate %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can generate %v", i), func(t *testing.T) { t.Parallel() prefix := String(10) @@ -36,10 +34,8 @@ func TestOrg(t *testing.T) { func TestUser(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can generate %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can generate %v", i), func(t *testing.T) { t.Parallel() prefix := String(10) @@ -61,10 +57,8 @@ func TestUser(t *testing.T) { func TestKey(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can generate %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can generate %v", i), func(t *testing.T) { t.Parallel() prefix := String(10) @@ -84,10 +78,8 @@ func TestKey(t *testing.T) { func TestApp(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can generate %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can generate %v", i), func(t *testing.T) { t.Parallel() prefix := String(10) @@ -111,10 +103,8 @@ func TestApp(t *testing.T) { func TestHOTPIdentity(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can generate %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can generate %v", i), func(t *testing.T) { t.Parallel() prefix := String(10) @@ -135,10 +125,8 @@ func TestHOTPIdentity(t *testing.T) { func TestSMSIdentity(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can generate %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can generate %v", i), func(t *testing.T) { t.Parallel() prefix := String(10) @@ -159,10 +147,8 @@ func TestSMSIdentity(t *testing.T) { func TestPushoverIdentity(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can generate %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can generate %v", i), func(t *testing.T) { t.Parallel() prefix := String(10) @@ -183,10 +169,8 @@ func TestPushoverIdentity(t *testing.T) { func TestEmailIdentity(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can generate %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can generate %v", i), func(t *testing.T) { t.Parallel() prefix := String(10) @@ -207,10 +191,8 @@ func TestEmailIdentity(t *testing.T) { func TestBackupCodesIdentity(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can generate %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can generate %v", i), func(t *testing.T) { t.Parallel() prefix := String(10) @@ -231,10 +213,8 @@ func TestBackupCodesIdentity(t *testing.T) { func TestSecurityQuestionsIdentity(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can generate %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can generate %v", i), func(t *testing.T) { t.Parallel() prefix := String(10) @@ -255,10 +235,8 @@ func TestSecurityQuestionsIdentity(t *testing.T) { func TestEvent(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can generate %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can generate %v", i), func(t *testing.T) { t.Parallel() prefix := String(10) diff --git a/pkg/test/random/int_test.go b/pkg/test/random/int_test.go index eb65b4f9..12180e4b 100644 --- a/pkg/test/random/int_test.go +++ b/pkg/test/random/int_test.go @@ -12,10 +12,8 @@ import ( func TestIntn(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can generate %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can generate %v", i), func(t *testing.T) { t.Parallel() n := Intn(99) diff --git a/pkg/test/random/string_test.go b/pkg/test/random/string_test.go index 30456987..6855b59a 100644 --- a/pkg/test/random/string_test.go +++ b/pkg/test/random/string_test.go @@ -14,17 +14,15 @@ func TestBytes(t *testing.T) { t.Parallel() for i := 5; i < 15; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can generate %v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can generate %v", i), func(t *testing.T) { t.Parallel() - b1 := Bytes(uint(lTest)) - b2 := Bytes(uint(lTest)) + b1 := Bytes(uint(i)) + b2 := Bytes(uint(i)) t.Logf("b1, b2: %x, %x", b1, b2) - require.Len(t, b1, lTest) - require.Len(t, b2, lTest) + require.Len(t, b1, i) + require.Len(t, b2, i) require.NotEqual(t, b1, b2) }) } @@ -34,17 +32,15 @@ func TestString(t *testing.T) { t.Parallel() for i := 5; i < 15; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can generate %v", lTest), func(t *testing.T) { + t.Run(fmt.Sprintf("Can generate %v", i), func(t *testing.T) { t.Parallel() - s1 := String(uint(lTest)) - s2 := String(uint(lTest)) + s1 := String(uint(i)) + s2 := String(uint(i)) t.Logf("s1, s2: %v, %v", s1, s2) - require.Len(t, s1, lTest) - require.Len(t, s2, lTest) + require.Len(t, s1, i) + require.Len(t, s2, i) require.NotEqual(t, s1, s2) }) } @@ -53,10 +49,8 @@ func TestString(t *testing.T) { func TestEmail(t *testing.T) { t.Parallel() - for i := 0; i < 5; i++ { - lTest := i - - t.Run(fmt.Sprintf("Can generate %v", lTest), func(t *testing.T) { + for i := range 5 { + t.Run(fmt.Sprintf("Can generate %v", i), func(t *testing.T) { t.Parallel() e1 := Email() diff --git a/proto/Makefile b/proto/Makefile index ff7afcda..e1808fed 100644 --- a/proto/Makefile +++ b/proto/Makefile @@ -4,9 +4,9 @@ # filesystem depth generate: cp -Rf ../../proto/protobuf/api protobuf/ - docker-compose build --progress=plain --no-cache --pull - docker-compose up - docker-compose down + docker compose build --progress=plain --no-cache --pull + docker compose up + docker compose down rm -rf protobuf/api cp -f ../../proto/openapi/hermes.swagger.json ../web/ diff --git a/proto/README.md b/proto/README.md index ec7ca64b..8d390418 100644 --- a/proto/README.md +++ b/proto/README.md @@ -17,7 +17,7 @@ import "github.com/ownmfa/hermes/proto/go/token" These instructions require [Docker](https://docs.docker.com/get-started/overview/) and -[Docker Compose](https://docs.docker.com/compose/) (V1 or V2) to be installed. +[Docker Compose](https://docs.docker.com/compose/) to be installed. ``` make diff --git a/vendor/github.com/golang/protobuf/jsonpb/decode.go b/vendor/github.com/golang/protobuf/jsonpb/decode.go deleted file mode 100644 index 6c16c255..00000000 --- a/vendor/github.com/golang/protobuf/jsonpb/decode.go +++ /dev/null @@ -1,530 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package jsonpb - -import ( - "encoding/json" - "errors" - "fmt" - "io" - "math" - "reflect" - "strconv" - "strings" - "time" - - "github.com/golang/protobuf/proto" - "google.golang.org/protobuf/encoding/protojson" - protoV2 "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" -) - -const wrapJSONUnmarshalV2 = false - -// UnmarshalNext unmarshals the next JSON object from d into m. -func UnmarshalNext(d *json.Decoder, m proto.Message) error { - return new(Unmarshaler).UnmarshalNext(d, m) -} - -// Unmarshal unmarshals a JSON object from r into m. -func Unmarshal(r io.Reader, m proto.Message) error { - return new(Unmarshaler).Unmarshal(r, m) -} - -// UnmarshalString unmarshals a JSON object from s into m. -func UnmarshalString(s string, m proto.Message) error { - return new(Unmarshaler).Unmarshal(strings.NewReader(s), m) -} - -// Unmarshaler is a configurable object for converting from a JSON -// representation to a protocol buffer object. -type Unmarshaler struct { - // AllowUnknownFields specifies whether to allow messages to contain - // unknown JSON fields, as opposed to failing to unmarshal. - AllowUnknownFields bool - - // AnyResolver is used to resolve the google.protobuf.Any well-known type. - // If unset, the global registry is used by default. - AnyResolver AnyResolver -} - -// JSONPBUnmarshaler is implemented by protobuf messages that customize the way -// they are unmarshaled from JSON. Messages that implement this should also -// implement JSONPBMarshaler so that the custom format can be produced. -// -// The JSON unmarshaling must follow the JSON to proto specification: -// https://developers.google.com/protocol-buffers/docs/proto3#json -// -// Deprecated: Custom types should implement protobuf reflection instead. -type JSONPBUnmarshaler interface { - UnmarshalJSONPB(*Unmarshaler, []byte) error -} - -// Unmarshal unmarshals a JSON object from r into m. -func (u *Unmarshaler) Unmarshal(r io.Reader, m proto.Message) error { - return u.UnmarshalNext(json.NewDecoder(r), m) -} - -// UnmarshalNext unmarshals the next JSON object from d into m. -func (u *Unmarshaler) UnmarshalNext(d *json.Decoder, m proto.Message) error { - if m == nil { - return errors.New("invalid nil message") - } - - // Parse the next JSON object from the stream. - raw := json.RawMessage{} - if err := d.Decode(&raw); err != nil { - return err - } - - // Check for custom unmarshalers first since they may not properly - // implement protobuf reflection that the logic below relies on. - if jsu, ok := m.(JSONPBUnmarshaler); ok { - return jsu.UnmarshalJSONPB(u, raw) - } - - mr := proto.MessageReflect(m) - - // NOTE: For historical reasons, a top-level null is treated as a noop. - // This is incorrect, but kept for compatibility. - if string(raw) == "null" && mr.Descriptor().FullName() != "google.protobuf.Value" { - return nil - } - - if wrapJSONUnmarshalV2 { - // NOTE: If input message is non-empty, we need to preserve merge semantics - // of the old jsonpb implementation. These semantics are not supported by - // the protobuf JSON specification. - isEmpty := true - mr.Range(func(protoreflect.FieldDescriptor, protoreflect.Value) bool { - isEmpty = false // at least one iteration implies non-empty - return false - }) - if !isEmpty { - // Perform unmarshaling into a newly allocated, empty message. - mr = mr.New() - - // Use a defer to copy all unmarshaled fields into the original message. - dst := proto.MessageReflect(m) - defer mr.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool { - dst.Set(fd, v) - return true - }) - } - - // Unmarshal using the v2 JSON unmarshaler. - opts := protojson.UnmarshalOptions{ - DiscardUnknown: u.AllowUnknownFields, - } - if u.AnyResolver != nil { - opts.Resolver = anyResolver{u.AnyResolver} - } - return opts.Unmarshal(raw, mr.Interface()) - } else { - if err := u.unmarshalMessage(mr, raw); err != nil { - return err - } - return protoV2.CheckInitialized(mr.Interface()) - } -} - -func (u *Unmarshaler) unmarshalMessage(m protoreflect.Message, in []byte) error { - md := m.Descriptor() - fds := md.Fields() - - if jsu, ok := proto.MessageV1(m.Interface()).(JSONPBUnmarshaler); ok { - return jsu.UnmarshalJSONPB(u, in) - } - - if string(in) == "null" && md.FullName() != "google.protobuf.Value" { - return nil - } - - switch wellKnownType(md.FullName()) { - case "Any": - var jsonObject map[string]json.RawMessage - if err := json.Unmarshal(in, &jsonObject); err != nil { - return err - } - - rawTypeURL, ok := jsonObject["@type"] - if !ok { - return errors.New("Any JSON doesn't have '@type'") - } - typeURL, err := unquoteString(string(rawTypeURL)) - if err != nil { - return fmt.Errorf("can't unmarshal Any's '@type': %q", rawTypeURL) - } - m.Set(fds.ByNumber(1), protoreflect.ValueOfString(typeURL)) - - var m2 protoreflect.Message - if u.AnyResolver != nil { - mi, err := u.AnyResolver.Resolve(typeURL) - if err != nil { - return err - } - m2 = proto.MessageReflect(mi) - } else { - mt, err := protoregistry.GlobalTypes.FindMessageByURL(typeURL) - if err != nil { - if err == protoregistry.NotFound { - return fmt.Errorf("could not resolve Any message type: %v", typeURL) - } - return err - } - m2 = mt.New() - } - - if wellKnownType(m2.Descriptor().FullName()) != "" { - rawValue, ok := jsonObject["value"] - if !ok { - return errors.New("Any JSON doesn't have 'value'") - } - if err := u.unmarshalMessage(m2, rawValue); err != nil { - return fmt.Errorf("can't unmarshal Any nested proto %v: %v", typeURL, err) - } - } else { - delete(jsonObject, "@type") - rawJSON, err := json.Marshal(jsonObject) - if err != nil { - return fmt.Errorf("can't generate JSON for Any's nested proto to be unmarshaled: %v", err) - } - if err = u.unmarshalMessage(m2, rawJSON); err != nil { - return fmt.Errorf("can't unmarshal Any nested proto %v: %v", typeURL, err) - } - } - - rawWire, err := protoV2.Marshal(m2.Interface()) - if err != nil { - return fmt.Errorf("can't marshal proto %v into Any.Value: %v", typeURL, err) - } - m.Set(fds.ByNumber(2), protoreflect.ValueOfBytes(rawWire)) - return nil - case "BoolValue", "BytesValue", "StringValue", - "Int32Value", "UInt32Value", "FloatValue", - "Int64Value", "UInt64Value", "DoubleValue": - fd := fds.ByNumber(1) - v, err := u.unmarshalValue(m.NewField(fd), in, fd) - if err != nil { - return err - } - m.Set(fd, v) - return nil - case "Duration": - v, err := unquoteString(string(in)) - if err != nil { - return err - } - d, err := time.ParseDuration(v) - if err != nil { - return fmt.Errorf("bad Duration: %v", err) - } - - sec := d.Nanoseconds() / 1e9 - nsec := d.Nanoseconds() % 1e9 - m.Set(fds.ByNumber(1), protoreflect.ValueOfInt64(int64(sec))) - m.Set(fds.ByNumber(2), protoreflect.ValueOfInt32(int32(nsec))) - return nil - case "Timestamp": - v, err := unquoteString(string(in)) - if err != nil { - return err - } - t, err := time.Parse(time.RFC3339Nano, v) - if err != nil { - return fmt.Errorf("bad Timestamp: %v", err) - } - - sec := t.Unix() - nsec := t.Nanosecond() - m.Set(fds.ByNumber(1), protoreflect.ValueOfInt64(int64(sec))) - m.Set(fds.ByNumber(2), protoreflect.ValueOfInt32(int32(nsec))) - return nil - case "Value": - switch { - case string(in) == "null": - m.Set(fds.ByNumber(1), protoreflect.ValueOfEnum(0)) - case string(in) == "true": - m.Set(fds.ByNumber(4), protoreflect.ValueOfBool(true)) - case string(in) == "false": - m.Set(fds.ByNumber(4), protoreflect.ValueOfBool(false)) - case hasPrefixAndSuffix('"', in, '"'): - s, err := unquoteString(string(in)) - if err != nil { - return fmt.Errorf("unrecognized type for Value %q", in) - } - m.Set(fds.ByNumber(3), protoreflect.ValueOfString(s)) - case hasPrefixAndSuffix('[', in, ']'): - v := m.Mutable(fds.ByNumber(6)) - return u.unmarshalMessage(v.Message(), in) - case hasPrefixAndSuffix('{', in, '}'): - v := m.Mutable(fds.ByNumber(5)) - return u.unmarshalMessage(v.Message(), in) - default: - f, err := strconv.ParseFloat(string(in), 0) - if err != nil { - return fmt.Errorf("unrecognized type for Value %q", in) - } - m.Set(fds.ByNumber(2), protoreflect.ValueOfFloat64(f)) - } - return nil - case "ListValue": - var jsonArray []json.RawMessage - if err := json.Unmarshal(in, &jsonArray); err != nil { - return fmt.Errorf("bad ListValue: %v", err) - } - - lv := m.Mutable(fds.ByNumber(1)).List() - for _, raw := range jsonArray { - ve := lv.NewElement() - if err := u.unmarshalMessage(ve.Message(), raw); err != nil { - return err - } - lv.Append(ve) - } - return nil - case "Struct": - var jsonObject map[string]json.RawMessage - if err := json.Unmarshal(in, &jsonObject); err != nil { - return fmt.Errorf("bad StructValue: %v", err) - } - - mv := m.Mutable(fds.ByNumber(1)).Map() - for key, raw := range jsonObject { - kv := protoreflect.ValueOf(key).MapKey() - vv := mv.NewValue() - if err := u.unmarshalMessage(vv.Message(), raw); err != nil { - return fmt.Errorf("bad value in StructValue for key %q: %v", key, err) - } - mv.Set(kv, vv) - } - return nil - } - - var jsonObject map[string]json.RawMessage - if err := json.Unmarshal(in, &jsonObject); err != nil { - return err - } - - // Handle known fields. - for i := 0; i < fds.Len(); i++ { - fd := fds.Get(i) - if fd.IsWeak() && fd.Message().IsPlaceholder() { - continue // weak reference is not linked in - } - - // Search for any raw JSON value associated with this field. - var raw json.RawMessage - name := string(fd.Name()) - if fd.Kind() == protoreflect.GroupKind { - name = string(fd.Message().Name()) - } - if v, ok := jsonObject[name]; ok { - delete(jsonObject, name) - raw = v - } - name = string(fd.JSONName()) - if v, ok := jsonObject[name]; ok { - delete(jsonObject, name) - raw = v - } - - field := m.NewField(fd) - // Unmarshal the field value. - if raw == nil || (string(raw) == "null" && !isSingularWellKnownValue(fd) && !isSingularJSONPBUnmarshaler(field, fd)) { - continue - } - v, err := u.unmarshalValue(field, raw, fd) - if err != nil { - return err - } - m.Set(fd, v) - } - - // Handle extension fields. - for name, raw := range jsonObject { - if !strings.HasPrefix(name, "[") || !strings.HasSuffix(name, "]") { - continue - } - - // Resolve the extension field by name. - xname := protoreflect.FullName(name[len("[") : len(name)-len("]")]) - xt, _ := protoregistry.GlobalTypes.FindExtensionByName(xname) - if xt == nil && isMessageSet(md) { - xt, _ = protoregistry.GlobalTypes.FindExtensionByName(xname.Append("message_set_extension")) - } - if xt == nil { - continue - } - delete(jsonObject, name) - fd := xt.TypeDescriptor() - if fd.ContainingMessage().FullName() != m.Descriptor().FullName() { - return fmt.Errorf("extension field %q does not extend message %q", xname, m.Descriptor().FullName()) - } - - field := m.NewField(fd) - // Unmarshal the field value. - if raw == nil || (string(raw) == "null" && !isSingularWellKnownValue(fd) && !isSingularJSONPBUnmarshaler(field, fd)) { - continue - } - v, err := u.unmarshalValue(field, raw, fd) - if err != nil { - return err - } - m.Set(fd, v) - } - - if !u.AllowUnknownFields && len(jsonObject) > 0 { - for name := range jsonObject { - return fmt.Errorf("unknown field %q in %v", name, md.FullName()) - } - } - return nil -} - -func isSingularWellKnownValue(fd protoreflect.FieldDescriptor) bool { - if fd.Cardinality() == protoreflect.Repeated { - return false - } - if md := fd.Message(); md != nil { - return md.FullName() == "google.protobuf.Value" - } - if ed := fd.Enum(); ed != nil { - return ed.FullName() == "google.protobuf.NullValue" - } - return false -} - -func isSingularJSONPBUnmarshaler(v protoreflect.Value, fd protoreflect.FieldDescriptor) bool { - if fd.Message() != nil && fd.Cardinality() != protoreflect.Repeated { - _, ok := proto.MessageV1(v.Interface()).(JSONPBUnmarshaler) - return ok - } - return false -} - -func (u *Unmarshaler) unmarshalValue(v protoreflect.Value, in []byte, fd protoreflect.FieldDescriptor) (protoreflect.Value, error) { - switch { - case fd.IsList(): - var jsonArray []json.RawMessage - if err := json.Unmarshal(in, &jsonArray); err != nil { - return v, err - } - lv := v.List() - for _, raw := range jsonArray { - ve, err := u.unmarshalSingularValue(lv.NewElement(), raw, fd) - if err != nil { - return v, err - } - lv.Append(ve) - } - return v, nil - case fd.IsMap(): - var jsonObject map[string]json.RawMessage - if err := json.Unmarshal(in, &jsonObject); err != nil { - return v, err - } - kfd := fd.MapKey() - vfd := fd.MapValue() - mv := v.Map() - for key, raw := range jsonObject { - var kv protoreflect.MapKey - if kfd.Kind() == protoreflect.StringKind { - kv = protoreflect.ValueOf(key).MapKey() - } else { - v, err := u.unmarshalSingularValue(kfd.Default(), []byte(key), kfd) - if err != nil { - return v, err - } - kv = v.MapKey() - } - - vv, err := u.unmarshalSingularValue(mv.NewValue(), raw, vfd) - if err != nil { - return v, err - } - mv.Set(kv, vv) - } - return v, nil - default: - return u.unmarshalSingularValue(v, in, fd) - } -} - -var nonFinite = map[string]float64{ - `"NaN"`: math.NaN(), - `"Infinity"`: math.Inf(+1), - `"-Infinity"`: math.Inf(-1), -} - -func (u *Unmarshaler) unmarshalSingularValue(v protoreflect.Value, in []byte, fd protoreflect.FieldDescriptor) (protoreflect.Value, error) { - switch fd.Kind() { - case protoreflect.BoolKind: - return unmarshalValue(in, new(bool)) - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: - return unmarshalValue(trimQuote(in), new(int32)) - case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - return unmarshalValue(trimQuote(in), new(int64)) - case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: - return unmarshalValue(trimQuote(in), new(uint32)) - case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: - return unmarshalValue(trimQuote(in), new(uint64)) - case protoreflect.FloatKind: - if f, ok := nonFinite[string(in)]; ok { - return protoreflect.ValueOfFloat32(float32(f)), nil - } - return unmarshalValue(trimQuote(in), new(float32)) - case protoreflect.DoubleKind: - if f, ok := nonFinite[string(in)]; ok { - return protoreflect.ValueOfFloat64(float64(f)), nil - } - return unmarshalValue(trimQuote(in), new(float64)) - case protoreflect.StringKind: - return unmarshalValue(in, new(string)) - case protoreflect.BytesKind: - return unmarshalValue(in, new([]byte)) - case protoreflect.EnumKind: - if hasPrefixAndSuffix('"', in, '"') { - vd := fd.Enum().Values().ByName(protoreflect.Name(trimQuote(in))) - if vd == nil { - return v, fmt.Errorf("unknown value %q for enum %s", in, fd.Enum().FullName()) - } - return protoreflect.ValueOfEnum(vd.Number()), nil - } - return unmarshalValue(in, new(protoreflect.EnumNumber)) - case protoreflect.MessageKind, protoreflect.GroupKind: - err := u.unmarshalMessage(v.Message(), in) - return v, err - default: - panic(fmt.Sprintf("invalid kind %v", fd.Kind())) - } -} - -func unmarshalValue(in []byte, v interface{}) (protoreflect.Value, error) { - err := json.Unmarshal(in, v) - return protoreflect.ValueOf(reflect.ValueOf(v).Elem().Interface()), err -} - -func unquoteString(in string) (out string, err error) { - err = json.Unmarshal([]byte(in), &out) - return out, err -} - -func hasPrefixAndSuffix(prefix byte, in []byte, suffix byte) bool { - if len(in) >= 2 && in[0] == prefix && in[len(in)-1] == suffix { - return true - } - return false -} - -// trimQuote is like unquoteString but simply strips surrounding quotes. -// This is incorrect, but is behavior done by the legacy implementation. -func trimQuote(in []byte) []byte { - if len(in) >= 2 && in[0] == '"' && in[len(in)-1] == '"' { - in = in[1 : len(in)-1] - } - return in -} diff --git a/vendor/github.com/golang/protobuf/jsonpb/encode.go b/vendor/github.com/golang/protobuf/jsonpb/encode.go deleted file mode 100644 index 685c80a6..00000000 --- a/vendor/github.com/golang/protobuf/jsonpb/encode.go +++ /dev/null @@ -1,559 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package jsonpb - -import ( - "encoding/json" - "errors" - "fmt" - "io" - "math" - "reflect" - "sort" - "strconv" - "strings" - "time" - - "github.com/golang/protobuf/proto" - "google.golang.org/protobuf/encoding/protojson" - protoV2 "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" -) - -const wrapJSONMarshalV2 = false - -// Marshaler is a configurable object for marshaling protocol buffer messages -// to the specified JSON representation. -type Marshaler struct { - // OrigName specifies whether to use the original protobuf name for fields. - OrigName bool - - // EnumsAsInts specifies whether to render enum values as integers, - // as opposed to string values. - EnumsAsInts bool - - // EmitDefaults specifies whether to render fields with zero values. - EmitDefaults bool - - // Indent controls whether the output is compact or not. - // If empty, the output is compact JSON. Otherwise, every JSON object - // entry and JSON array value will be on its own line. - // Each line will be preceded by repeated copies of Indent, where the - // number of copies is the current indentation depth. - Indent string - - // AnyResolver is used to resolve the google.protobuf.Any well-known type. - // If unset, the global registry is used by default. - AnyResolver AnyResolver -} - -// JSONPBMarshaler is implemented by protobuf messages that customize the -// way they are marshaled to JSON. Messages that implement this should also -// implement JSONPBUnmarshaler so that the custom format can be parsed. -// -// The JSON marshaling must follow the proto to JSON specification: -// https://developers.google.com/protocol-buffers/docs/proto3#json -// -// Deprecated: Custom types should implement protobuf reflection instead. -type JSONPBMarshaler interface { - MarshalJSONPB(*Marshaler) ([]byte, error) -} - -// Marshal serializes a protobuf message as JSON into w. -func (jm *Marshaler) Marshal(w io.Writer, m proto.Message) error { - b, err := jm.marshal(m) - if len(b) > 0 { - if _, err := w.Write(b); err != nil { - return err - } - } - return err -} - -// MarshalToString serializes a protobuf message as JSON in string form. -func (jm *Marshaler) MarshalToString(m proto.Message) (string, error) { - b, err := jm.marshal(m) - if err != nil { - return "", err - } - return string(b), nil -} - -func (jm *Marshaler) marshal(m proto.Message) ([]byte, error) { - v := reflect.ValueOf(m) - if m == nil || (v.Kind() == reflect.Ptr && v.IsNil()) { - return nil, errors.New("Marshal called with nil") - } - - // Check for custom marshalers first since they may not properly - // implement protobuf reflection that the logic below relies on. - if jsm, ok := m.(JSONPBMarshaler); ok { - return jsm.MarshalJSONPB(jm) - } - - if wrapJSONMarshalV2 { - opts := protojson.MarshalOptions{ - UseProtoNames: jm.OrigName, - UseEnumNumbers: jm.EnumsAsInts, - EmitUnpopulated: jm.EmitDefaults, - Indent: jm.Indent, - } - if jm.AnyResolver != nil { - opts.Resolver = anyResolver{jm.AnyResolver} - } - return opts.Marshal(proto.MessageReflect(m).Interface()) - } else { - // Check for unpopulated required fields first. - m2 := proto.MessageReflect(m) - if err := protoV2.CheckInitialized(m2.Interface()); err != nil { - return nil, err - } - - w := jsonWriter{Marshaler: jm} - err := w.marshalMessage(m2, "", "") - return w.buf, err - } -} - -type jsonWriter struct { - *Marshaler - buf []byte -} - -func (w *jsonWriter) write(s string) { - w.buf = append(w.buf, s...) -} - -func (w *jsonWriter) marshalMessage(m protoreflect.Message, indent, typeURL string) error { - if jsm, ok := proto.MessageV1(m.Interface()).(JSONPBMarshaler); ok { - b, err := jsm.MarshalJSONPB(w.Marshaler) - if err != nil { - return err - } - if typeURL != "" { - // we are marshaling this object to an Any type - var js map[string]*json.RawMessage - if err = json.Unmarshal(b, &js); err != nil { - return fmt.Errorf("type %T produced invalid JSON: %v", m.Interface(), err) - } - turl, err := json.Marshal(typeURL) - if err != nil { - return fmt.Errorf("failed to marshal type URL %q to JSON: %v", typeURL, err) - } - js["@type"] = (*json.RawMessage)(&turl) - if b, err = json.Marshal(js); err != nil { - return err - } - } - w.write(string(b)) - return nil - } - - md := m.Descriptor() - fds := md.Fields() - - // Handle well-known types. - const secondInNanos = int64(time.Second / time.Nanosecond) - switch wellKnownType(md.FullName()) { - case "Any": - return w.marshalAny(m, indent) - case "BoolValue", "BytesValue", "StringValue", - "Int32Value", "UInt32Value", "FloatValue", - "Int64Value", "UInt64Value", "DoubleValue": - fd := fds.ByNumber(1) - return w.marshalValue(fd, m.Get(fd), indent) - case "Duration": - const maxSecondsInDuration = 315576000000 - // "Generated output always contains 0, 3, 6, or 9 fractional digits, - // depending on required precision." - s := m.Get(fds.ByNumber(1)).Int() - ns := m.Get(fds.ByNumber(2)).Int() - if s < -maxSecondsInDuration || s > maxSecondsInDuration { - return fmt.Errorf("seconds out of range %v", s) - } - if ns <= -secondInNanos || ns >= secondInNanos { - return fmt.Errorf("ns out of range (%v, %v)", -secondInNanos, secondInNanos) - } - if (s > 0 && ns < 0) || (s < 0 && ns > 0) { - return errors.New("signs of seconds and nanos do not match") - } - var sign string - if s < 0 || ns < 0 { - sign, s, ns = "-", -1*s, -1*ns - } - x := fmt.Sprintf("%s%d.%09d", sign, s, ns) - x = strings.TrimSuffix(x, "000") - x = strings.TrimSuffix(x, "000") - x = strings.TrimSuffix(x, ".000") - w.write(fmt.Sprintf(`"%vs"`, x)) - return nil - case "Timestamp": - // "RFC 3339, where generated output will always be Z-normalized - // and uses 0, 3, 6 or 9 fractional digits." - s := m.Get(fds.ByNumber(1)).Int() - ns := m.Get(fds.ByNumber(2)).Int() - if ns < 0 || ns >= secondInNanos { - return fmt.Errorf("ns out of range [0, %v)", secondInNanos) - } - t := time.Unix(s, ns).UTC() - // time.RFC3339Nano isn't exactly right (we need to get 3/6/9 fractional digits). - x := t.Format("2006-01-02T15:04:05.000000000") - x = strings.TrimSuffix(x, "000") - x = strings.TrimSuffix(x, "000") - x = strings.TrimSuffix(x, ".000") - w.write(fmt.Sprintf(`"%vZ"`, x)) - return nil - case "Value": - // JSON value; which is a null, number, string, bool, object, or array. - od := md.Oneofs().Get(0) - fd := m.WhichOneof(od) - if fd == nil { - return errors.New("nil Value") - } - return w.marshalValue(fd, m.Get(fd), indent) - case "Struct", "ListValue": - // JSON object or array. - fd := fds.ByNumber(1) - return w.marshalValue(fd, m.Get(fd), indent) - } - - w.write("{") - if w.Indent != "" { - w.write("\n") - } - - firstField := true - if typeURL != "" { - if err := w.marshalTypeURL(indent, typeURL); err != nil { - return err - } - firstField = false - } - - for i := 0; i < fds.Len(); { - fd := fds.Get(i) - if od := fd.ContainingOneof(); od != nil { - fd = m.WhichOneof(od) - i += od.Fields().Len() - if fd == nil { - continue - } - } else { - i++ - } - - v := m.Get(fd) - - if !m.Has(fd) { - if !w.EmitDefaults || fd.ContainingOneof() != nil { - continue - } - if fd.Cardinality() != protoreflect.Repeated && (fd.Message() != nil || fd.Syntax() == protoreflect.Proto2) { - v = protoreflect.Value{} // use "null" for singular messages or proto2 scalars - } - } - - if !firstField { - w.writeComma() - } - if err := w.marshalField(fd, v, indent); err != nil { - return err - } - firstField = false - } - - // Handle proto2 extensions. - if md.ExtensionRanges().Len() > 0 { - // Collect a sorted list of all extension descriptor and values. - type ext struct { - desc protoreflect.FieldDescriptor - val protoreflect.Value - } - var exts []ext - m.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool { - if fd.IsExtension() { - exts = append(exts, ext{fd, v}) - } - return true - }) - sort.Slice(exts, func(i, j int) bool { - return exts[i].desc.Number() < exts[j].desc.Number() - }) - - for _, ext := range exts { - if !firstField { - w.writeComma() - } - if err := w.marshalField(ext.desc, ext.val, indent); err != nil { - return err - } - firstField = false - } - } - - if w.Indent != "" { - w.write("\n") - w.write(indent) - } - w.write("}") - return nil -} - -func (w *jsonWriter) writeComma() { - if w.Indent != "" { - w.write(",\n") - } else { - w.write(",") - } -} - -func (w *jsonWriter) marshalAny(m protoreflect.Message, indent string) error { - // "If the Any contains a value that has a special JSON mapping, - // it will be converted as follows: {"@type": xxx, "value": yyy}. - // Otherwise, the value will be converted into a JSON object, - // and the "@type" field will be inserted to indicate the actual data type." - md := m.Descriptor() - typeURL := m.Get(md.Fields().ByNumber(1)).String() - rawVal := m.Get(md.Fields().ByNumber(2)).Bytes() - - var m2 protoreflect.Message - if w.AnyResolver != nil { - mi, err := w.AnyResolver.Resolve(typeURL) - if err != nil { - return err - } - m2 = proto.MessageReflect(mi) - } else { - mt, err := protoregistry.GlobalTypes.FindMessageByURL(typeURL) - if err != nil { - return err - } - m2 = mt.New() - } - - if err := protoV2.Unmarshal(rawVal, m2.Interface()); err != nil { - return err - } - - if wellKnownType(m2.Descriptor().FullName()) == "" { - return w.marshalMessage(m2, indent, typeURL) - } - - w.write("{") - if w.Indent != "" { - w.write("\n") - } - if err := w.marshalTypeURL(indent, typeURL); err != nil { - return err - } - w.writeComma() - if w.Indent != "" { - w.write(indent) - w.write(w.Indent) - w.write(`"value": `) - } else { - w.write(`"value":`) - } - if err := w.marshalMessage(m2, indent+w.Indent, ""); err != nil { - return err - } - if w.Indent != "" { - w.write("\n") - w.write(indent) - } - w.write("}") - return nil -} - -func (w *jsonWriter) marshalTypeURL(indent, typeURL string) error { - if w.Indent != "" { - w.write(indent) - w.write(w.Indent) - } - w.write(`"@type":`) - if w.Indent != "" { - w.write(" ") - } - b, err := json.Marshal(typeURL) - if err != nil { - return err - } - w.write(string(b)) - return nil -} - -// marshalField writes field description and value to the Writer. -func (w *jsonWriter) marshalField(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string) error { - if w.Indent != "" { - w.write(indent) - w.write(w.Indent) - } - w.write(`"`) - switch { - case fd.IsExtension(): - // For message set, use the fname of the message as the extension name. - name := string(fd.FullName()) - if isMessageSet(fd.ContainingMessage()) { - name = strings.TrimSuffix(name, ".message_set_extension") - } - - w.write("[" + name + "]") - case w.OrigName: - name := string(fd.Name()) - if fd.Kind() == protoreflect.GroupKind { - name = string(fd.Message().Name()) - } - w.write(name) - default: - w.write(string(fd.JSONName())) - } - w.write(`":`) - if w.Indent != "" { - w.write(" ") - } - return w.marshalValue(fd, v, indent) -} - -func (w *jsonWriter) marshalValue(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string) error { - switch { - case fd.IsList(): - w.write("[") - comma := "" - lv := v.List() - for i := 0; i < lv.Len(); i++ { - w.write(comma) - if w.Indent != "" { - w.write("\n") - w.write(indent) - w.write(w.Indent) - w.write(w.Indent) - } - if err := w.marshalSingularValue(fd, lv.Get(i), indent+w.Indent); err != nil { - return err - } - comma = "," - } - if w.Indent != "" { - w.write("\n") - w.write(indent) - w.write(w.Indent) - } - w.write("]") - return nil - case fd.IsMap(): - kfd := fd.MapKey() - vfd := fd.MapValue() - mv := v.Map() - - // Collect a sorted list of all map keys and values. - type entry struct{ key, val protoreflect.Value } - var entries []entry - mv.Range(func(k protoreflect.MapKey, v protoreflect.Value) bool { - entries = append(entries, entry{k.Value(), v}) - return true - }) - sort.Slice(entries, func(i, j int) bool { - switch kfd.Kind() { - case protoreflect.BoolKind: - return !entries[i].key.Bool() && entries[j].key.Bool() - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind, protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - return entries[i].key.Int() < entries[j].key.Int() - case protoreflect.Uint32Kind, protoreflect.Fixed32Kind, protoreflect.Uint64Kind, protoreflect.Fixed64Kind: - return entries[i].key.Uint() < entries[j].key.Uint() - case protoreflect.StringKind: - return entries[i].key.String() < entries[j].key.String() - default: - panic("invalid kind") - } - }) - - w.write(`{`) - comma := "" - for _, entry := range entries { - w.write(comma) - if w.Indent != "" { - w.write("\n") - w.write(indent) - w.write(w.Indent) - w.write(w.Indent) - } - - s := fmt.Sprint(entry.key.Interface()) - b, err := json.Marshal(s) - if err != nil { - return err - } - w.write(string(b)) - - w.write(`:`) - if w.Indent != "" { - w.write(` `) - } - - if err := w.marshalSingularValue(vfd, entry.val, indent+w.Indent); err != nil { - return err - } - comma = "," - } - if w.Indent != "" { - w.write("\n") - w.write(indent) - w.write(w.Indent) - } - w.write(`}`) - return nil - default: - return w.marshalSingularValue(fd, v, indent) - } -} - -func (w *jsonWriter) marshalSingularValue(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string) error { - switch { - case !v.IsValid(): - w.write("null") - return nil - case fd.Message() != nil: - return w.marshalMessage(v.Message(), indent+w.Indent, "") - case fd.Enum() != nil: - if fd.Enum().FullName() == "google.protobuf.NullValue" { - w.write("null") - return nil - } - - vd := fd.Enum().Values().ByNumber(v.Enum()) - if vd == nil || w.EnumsAsInts { - w.write(strconv.Itoa(int(v.Enum()))) - } else { - w.write(`"` + string(vd.Name()) + `"`) - } - return nil - default: - switch v.Interface().(type) { - case float32, float64: - switch { - case math.IsInf(v.Float(), +1): - w.write(`"Infinity"`) - return nil - case math.IsInf(v.Float(), -1): - w.write(`"-Infinity"`) - return nil - case math.IsNaN(v.Float()): - w.write(`"NaN"`) - return nil - } - case int64, uint64: - w.write(fmt.Sprintf(`"%d"`, v.Interface())) - return nil - } - - b, err := json.Marshal(v.Interface()) - if err != nil { - return err - } - w.write(string(b)) - return nil - } -} diff --git a/vendor/github.com/golang/protobuf/jsonpb/json.go b/vendor/github.com/golang/protobuf/jsonpb/json.go deleted file mode 100644 index 480e2448..00000000 --- a/vendor/github.com/golang/protobuf/jsonpb/json.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package jsonpb provides functionality to marshal and unmarshal between a -// protocol buffer message and JSON. It follows the specification at -// https://developers.google.com/protocol-buffers/docs/proto3#json. -// -// Do not rely on the default behavior of the standard encoding/json package -// when called on generated message types as it does not operate correctly. -// -// Deprecated: Use the "google.golang.org/protobuf/encoding/protojson" -// package instead. -package jsonpb - -import ( - "github.com/golang/protobuf/proto" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" - "google.golang.org/protobuf/runtime/protoimpl" -) - -// AnyResolver takes a type URL, present in an Any message, -// and resolves it into an instance of the associated message. -type AnyResolver interface { - Resolve(typeURL string) (proto.Message, error) -} - -type anyResolver struct{ AnyResolver } - -func (r anyResolver) FindMessageByName(message protoreflect.FullName) (protoreflect.MessageType, error) { - return r.FindMessageByURL(string(message)) -} - -func (r anyResolver) FindMessageByURL(url string) (protoreflect.MessageType, error) { - m, err := r.Resolve(url) - if err != nil { - return nil, err - } - return protoimpl.X.MessageTypeOf(m), nil -} - -func (r anyResolver) FindExtensionByName(field protoreflect.FullName) (protoreflect.ExtensionType, error) { - return protoregistry.GlobalTypes.FindExtensionByName(field) -} - -func (r anyResolver) FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error) { - return protoregistry.GlobalTypes.FindExtensionByNumber(message, field) -} - -func wellKnownType(s protoreflect.FullName) string { - if s.Parent() == "google.protobuf" { - switch s.Name() { - case "Empty", "Any", - "BoolValue", "BytesValue", "StringValue", - "Int32Value", "UInt32Value", "FloatValue", - "Int64Value", "UInt64Value", "DoubleValue", - "Duration", "Timestamp", - "NullValue", "Struct", "Value", "ListValue": - return string(s.Name()) - } - } - return "" -} - -func isMessageSet(md protoreflect.MessageDescriptor) bool { - ms, ok := md.(interface{ IsMessageSet() bool }) - return ok && ms.IsMessageSet() -} diff --git a/vendor/github.com/golang/protobuf/ptypes/any.go b/vendor/github.com/golang/protobuf/ptypes/any.go deleted file mode 100644 index 85f9f573..00000000 --- a/vendor/github.com/golang/protobuf/ptypes/any.go +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ptypes - -import ( - "fmt" - "strings" - - "github.com/golang/protobuf/proto" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" - - anypb "github.com/golang/protobuf/ptypes/any" -) - -const urlPrefix = "type.googleapis.com/" - -// AnyMessageName returns the message name contained in an anypb.Any message. -// Most type assertions should use the Is function instead. -// -// Deprecated: Call the any.MessageName method instead. -func AnyMessageName(any *anypb.Any) (string, error) { - name, err := anyMessageName(any) - return string(name), err -} -func anyMessageName(any *anypb.Any) (protoreflect.FullName, error) { - if any == nil { - return "", fmt.Errorf("message is nil") - } - name := protoreflect.FullName(any.TypeUrl) - if i := strings.LastIndex(any.TypeUrl, "/"); i >= 0 { - name = name[i+len("/"):] - } - if !name.IsValid() { - return "", fmt.Errorf("message type url %q is invalid", any.TypeUrl) - } - return name, nil -} - -// MarshalAny marshals the given message m into an anypb.Any message. -// -// Deprecated: Call the anypb.New function instead. -func MarshalAny(m proto.Message) (*anypb.Any, error) { - switch dm := m.(type) { - case DynamicAny: - m = dm.Message - case *DynamicAny: - if dm == nil { - return nil, proto.ErrNil - } - m = dm.Message - } - b, err := proto.Marshal(m) - if err != nil { - return nil, err - } - return &anypb.Any{TypeUrl: urlPrefix + proto.MessageName(m), Value: b}, nil -} - -// Empty returns a new message of the type specified in an anypb.Any message. -// It returns protoregistry.NotFound if the corresponding message type could not -// be resolved in the global registry. -// -// Deprecated: Use protoregistry.GlobalTypes.FindMessageByName instead -// to resolve the message name and create a new instance of it. -func Empty(any *anypb.Any) (proto.Message, error) { - name, err := anyMessageName(any) - if err != nil { - return nil, err - } - mt, err := protoregistry.GlobalTypes.FindMessageByName(name) - if err != nil { - return nil, err - } - return proto.MessageV1(mt.New().Interface()), nil -} - -// UnmarshalAny unmarshals the encoded value contained in the anypb.Any message -// into the provided message m. It returns an error if the target message -// does not match the type in the Any message or if an unmarshal error occurs. -// -// The target message m may be a *DynamicAny message. If the underlying message -// type could not be resolved, then this returns protoregistry.NotFound. -// -// Deprecated: Call the any.UnmarshalTo method instead. -func UnmarshalAny(any *anypb.Any, m proto.Message) error { - if dm, ok := m.(*DynamicAny); ok { - if dm.Message == nil { - var err error - dm.Message, err = Empty(any) - if err != nil { - return err - } - } - m = dm.Message - } - - anyName, err := AnyMessageName(any) - if err != nil { - return err - } - msgName := proto.MessageName(m) - if anyName != msgName { - return fmt.Errorf("mismatched message type: got %q want %q", anyName, msgName) - } - return proto.Unmarshal(any.Value, m) -} - -// Is reports whether the Any message contains a message of the specified type. -// -// Deprecated: Call the any.MessageIs method instead. -func Is(any *anypb.Any, m proto.Message) bool { - if any == nil || m == nil { - return false - } - name := proto.MessageName(m) - if !strings.HasSuffix(any.TypeUrl, name) { - return false - } - return len(any.TypeUrl) == len(name) || any.TypeUrl[len(any.TypeUrl)-len(name)-1] == '/' -} - -// DynamicAny is a value that can be passed to UnmarshalAny to automatically -// allocate a proto.Message for the type specified in an anypb.Any message. -// The allocated message is stored in the embedded proto.Message. -// -// Example: -// var x ptypes.DynamicAny -// if err := ptypes.UnmarshalAny(a, &x); err != nil { ... } -// fmt.Printf("unmarshaled message: %v", x.Message) -// -// Deprecated: Use the any.UnmarshalNew method instead to unmarshal -// the any message contents into a new instance of the underlying message. -type DynamicAny struct{ proto.Message } - -func (m DynamicAny) String() string { - if m.Message == nil { - return "" - } - return m.Message.String() -} -func (m DynamicAny) Reset() { - if m.Message == nil { - return - } - m.Message.Reset() -} -func (m DynamicAny) ProtoMessage() { - return -} -func (m DynamicAny) ProtoReflect() protoreflect.Message { - if m.Message == nil { - return nil - } - return dynamicAny{proto.MessageReflect(m.Message)} -} - -type dynamicAny struct{ protoreflect.Message } - -func (m dynamicAny) Type() protoreflect.MessageType { - return dynamicAnyType{m.Message.Type()} -} -func (m dynamicAny) New() protoreflect.Message { - return dynamicAnyType{m.Message.Type()}.New() -} -func (m dynamicAny) Interface() protoreflect.ProtoMessage { - return DynamicAny{proto.MessageV1(m.Message.Interface())} -} - -type dynamicAnyType struct{ protoreflect.MessageType } - -func (t dynamicAnyType) New() protoreflect.Message { - return dynamicAny{t.MessageType.New()} -} -func (t dynamicAnyType) Zero() protoreflect.Message { - return dynamicAny{t.MessageType.Zero()} -} diff --git a/vendor/github.com/golang/protobuf/ptypes/any/any.pb.go b/vendor/github.com/golang/protobuf/ptypes/any/any.pb.go deleted file mode 100644 index 0ef27d33..00000000 --- a/vendor/github.com/golang/protobuf/ptypes/any/any.pb.go +++ /dev/null @@ -1,62 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/golang/protobuf/ptypes/any/any.proto - -package any - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - anypb "google.golang.org/protobuf/types/known/anypb" - reflect "reflect" -) - -// Symbols defined in public import of google/protobuf/any.proto. - -type Any = anypb.Any - -var File_github_com_golang_protobuf_ptypes_any_any_proto protoreflect.FileDescriptor - -var file_github_com_golang_protobuf_ptypes_any_any_proto_rawDesc = []byte{ - 0x0a, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x6c, - 0x61, 0x6e, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x70, 0x74, 0x79, - 0x70, 0x65, 0x73, 0x2f, 0x61, 0x6e, 0x79, 0x2f, 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x1a, 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, - 0x75, 0x66, 0x2f, 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x42, 0x2b, 0x5a, 0x29, - 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x6c, 0x61, 0x6e, - 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x70, 0x74, 0x79, 0x70, 0x65, - 0x73, 0x2f, 0x61, 0x6e, 0x79, 0x3b, 0x61, 0x6e, 0x79, 0x50, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, -} - -var file_github_com_golang_protobuf_ptypes_any_any_proto_goTypes = []interface{}{} -var file_github_com_golang_protobuf_ptypes_any_any_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_github_com_golang_protobuf_ptypes_any_any_proto_init() } -func file_github_com_golang_protobuf_ptypes_any_any_proto_init() { - if File_github_com_golang_protobuf_ptypes_any_any_proto != nil { - return - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_github_com_golang_protobuf_ptypes_any_any_proto_rawDesc, - NumEnums: 0, - NumMessages: 0, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_github_com_golang_protobuf_ptypes_any_any_proto_goTypes, - DependencyIndexes: file_github_com_golang_protobuf_ptypes_any_any_proto_depIdxs, - }.Build() - File_github_com_golang_protobuf_ptypes_any_any_proto = out.File - file_github_com_golang_protobuf_ptypes_any_any_proto_rawDesc = nil - file_github_com_golang_protobuf_ptypes_any_any_proto_goTypes = nil - file_github_com_golang_protobuf_ptypes_any_any_proto_depIdxs = nil -} diff --git a/vendor/github.com/golang/protobuf/ptypes/doc.go b/vendor/github.com/golang/protobuf/ptypes/doc.go deleted file mode 100644 index d3c33259..00000000 --- a/vendor/github.com/golang/protobuf/ptypes/doc.go +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package ptypes provides functionality for interacting with well-known types. -// -// Deprecated: Well-known types have specialized functionality directly -// injected into the generated packages for each message type. -// See the deprecation notice for each function for the suggested alternative. -package ptypes diff --git a/vendor/github.com/golang/protobuf/ptypes/duration.go b/vendor/github.com/golang/protobuf/ptypes/duration.go deleted file mode 100644 index b2b55dd8..00000000 --- a/vendor/github.com/golang/protobuf/ptypes/duration.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ptypes - -import ( - "errors" - "fmt" - "time" - - durationpb "github.com/golang/protobuf/ptypes/duration" -) - -// Range of google.protobuf.Duration as specified in duration.proto. -// This is about 10,000 years in seconds. -const ( - maxSeconds = int64(10000 * 365.25 * 24 * 60 * 60) - minSeconds = -maxSeconds -) - -// Duration converts a durationpb.Duration to a time.Duration. -// Duration returns an error if dur is invalid or overflows a time.Duration. -// -// Deprecated: Call the dur.AsDuration and dur.CheckValid methods instead. -func Duration(dur *durationpb.Duration) (time.Duration, error) { - if err := validateDuration(dur); err != nil { - return 0, err - } - d := time.Duration(dur.Seconds) * time.Second - if int64(d/time.Second) != dur.Seconds { - return 0, fmt.Errorf("duration: %v is out of range for time.Duration", dur) - } - if dur.Nanos != 0 { - d += time.Duration(dur.Nanos) * time.Nanosecond - if (d < 0) != (dur.Nanos < 0) { - return 0, fmt.Errorf("duration: %v is out of range for time.Duration", dur) - } - } - return d, nil -} - -// DurationProto converts a time.Duration to a durationpb.Duration. -// -// Deprecated: Call the durationpb.New function instead. -func DurationProto(d time.Duration) *durationpb.Duration { - nanos := d.Nanoseconds() - secs := nanos / 1e9 - nanos -= secs * 1e9 - return &durationpb.Duration{ - Seconds: int64(secs), - Nanos: int32(nanos), - } -} - -// validateDuration determines whether the durationpb.Duration is valid -// according to the definition in google/protobuf/duration.proto. -// A valid durpb.Duration may still be too large to fit into a time.Duration -// Note that the range of durationpb.Duration is about 10,000 years, -// while the range of time.Duration is about 290 years. -func validateDuration(dur *durationpb.Duration) error { - if dur == nil { - return errors.New("duration: nil Duration") - } - if dur.Seconds < minSeconds || dur.Seconds > maxSeconds { - return fmt.Errorf("duration: %v: seconds out of range", dur) - } - if dur.Nanos <= -1e9 || dur.Nanos >= 1e9 { - return fmt.Errorf("duration: %v: nanos out of range", dur) - } - // Seconds and Nanos must have the same sign, unless d.Nanos is zero. - if (dur.Seconds < 0 && dur.Nanos > 0) || (dur.Seconds > 0 && dur.Nanos < 0) { - return fmt.Errorf("duration: %v: seconds and nanos have different signs", dur) - } - return nil -} diff --git a/vendor/github.com/golang/protobuf/ptypes/duration/duration.pb.go b/vendor/github.com/golang/protobuf/ptypes/duration/duration.pb.go deleted file mode 100644 index d0079ee3..00000000 --- a/vendor/github.com/golang/protobuf/ptypes/duration/duration.pb.go +++ /dev/null @@ -1,63 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/golang/protobuf/ptypes/duration/duration.proto - -package duration - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - durationpb "google.golang.org/protobuf/types/known/durationpb" - reflect "reflect" -) - -// Symbols defined in public import of google/protobuf/duration.proto. - -type Duration = durationpb.Duration - -var File_github_com_golang_protobuf_ptypes_duration_duration_proto protoreflect.FileDescriptor - -var file_github_com_golang_protobuf_ptypes_duration_duration_proto_rawDesc = []byte{ - 0x0a, 0x39, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x6c, - 0x61, 0x6e, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x70, 0x74, 0x79, - 0x70, 0x65, 0x73, 0x2f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x64, 0x75, 0x72, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x42, 0x35, 0x5a, 0x33, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, - 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x70, 0x74, 0x79, 0x70, 0x65, 0x73, - 0x2f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x50, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var file_github_com_golang_protobuf_ptypes_duration_duration_proto_goTypes = []interface{}{} -var file_github_com_golang_protobuf_ptypes_duration_duration_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_github_com_golang_protobuf_ptypes_duration_duration_proto_init() } -func file_github_com_golang_protobuf_ptypes_duration_duration_proto_init() { - if File_github_com_golang_protobuf_ptypes_duration_duration_proto != nil { - return - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_github_com_golang_protobuf_ptypes_duration_duration_proto_rawDesc, - NumEnums: 0, - NumMessages: 0, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_github_com_golang_protobuf_ptypes_duration_duration_proto_goTypes, - DependencyIndexes: file_github_com_golang_protobuf_ptypes_duration_duration_proto_depIdxs, - }.Build() - File_github_com_golang_protobuf_ptypes_duration_duration_proto = out.File - file_github_com_golang_protobuf_ptypes_duration_duration_proto_rawDesc = nil - file_github_com_golang_protobuf_ptypes_duration_duration_proto_goTypes = nil - file_github_com_golang_protobuf_ptypes_duration_duration_proto_depIdxs = nil -} diff --git a/vendor/github.com/golang/protobuf/ptypes/timestamp.go b/vendor/github.com/golang/protobuf/ptypes/timestamp.go deleted file mode 100644 index 8368a3f7..00000000 --- a/vendor/github.com/golang/protobuf/ptypes/timestamp.go +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ptypes - -import ( - "errors" - "fmt" - "time" - - timestamppb "github.com/golang/protobuf/ptypes/timestamp" -) - -// Range of google.protobuf.Duration as specified in timestamp.proto. -const ( - // Seconds field of the earliest valid Timestamp. - // This is time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC).Unix(). - minValidSeconds = -62135596800 - // Seconds field just after the latest valid Timestamp. - // This is time.Date(10000, 1, 1, 0, 0, 0, 0, time.UTC).Unix(). - maxValidSeconds = 253402300800 -) - -// Timestamp converts a timestamppb.Timestamp to a time.Time. -// It returns an error if the argument is invalid. -// -// Unlike most Go functions, if Timestamp returns an error, the first return -// value is not the zero time.Time. Instead, it is the value obtained from the -// time.Unix function when passed the contents of the Timestamp, in the UTC -// locale. This may or may not be a meaningful time; many invalid Timestamps -// do map to valid time.Times. -// -// A nil Timestamp returns an error. The first return value in that case is -// undefined. -// -// Deprecated: Call the ts.AsTime and ts.CheckValid methods instead. -func Timestamp(ts *timestamppb.Timestamp) (time.Time, error) { - // Don't return the zero value on error, because corresponds to a valid - // timestamp. Instead return whatever time.Unix gives us. - var t time.Time - if ts == nil { - t = time.Unix(0, 0).UTC() // treat nil like the empty Timestamp - } else { - t = time.Unix(ts.Seconds, int64(ts.Nanos)).UTC() - } - return t, validateTimestamp(ts) -} - -// TimestampNow returns a google.protobuf.Timestamp for the current time. -// -// Deprecated: Call the timestamppb.Now function instead. -func TimestampNow() *timestamppb.Timestamp { - ts, err := TimestampProto(time.Now()) - if err != nil { - panic("ptypes: time.Now() out of Timestamp range") - } - return ts -} - -// TimestampProto converts the time.Time to a google.protobuf.Timestamp proto. -// It returns an error if the resulting Timestamp is invalid. -// -// Deprecated: Call the timestamppb.New function instead. -func TimestampProto(t time.Time) (*timestamppb.Timestamp, error) { - ts := ×tamppb.Timestamp{ - Seconds: t.Unix(), - Nanos: int32(t.Nanosecond()), - } - if err := validateTimestamp(ts); err != nil { - return nil, err - } - return ts, nil -} - -// TimestampString returns the RFC 3339 string for valid Timestamps. -// For invalid Timestamps, it returns an error message in parentheses. -// -// Deprecated: Call the ts.AsTime method instead, -// followed by a call to the Format method on the time.Time value. -func TimestampString(ts *timestamppb.Timestamp) string { - t, err := Timestamp(ts) - if err != nil { - return fmt.Sprintf("(%v)", err) - } - return t.Format(time.RFC3339Nano) -} - -// validateTimestamp determines whether a Timestamp is valid. -// A valid timestamp represents a time in the range [0001-01-01, 10000-01-01) -// and has a Nanos field in the range [0, 1e9). -// -// If the Timestamp is valid, validateTimestamp returns nil. -// Otherwise, it returns an error that describes the problem. -// -// Every valid Timestamp can be represented by a time.Time, -// but the converse is not true. -func validateTimestamp(ts *timestamppb.Timestamp) error { - if ts == nil { - return errors.New("timestamp: nil Timestamp") - } - if ts.Seconds < minValidSeconds { - return fmt.Errorf("timestamp: %v before 0001-01-01", ts) - } - if ts.Seconds >= maxValidSeconds { - return fmt.Errorf("timestamp: %v after 10000-01-01", ts) - } - if ts.Nanos < 0 || ts.Nanos >= 1e9 { - return fmt.Errorf("timestamp: %v: nanos not in range [0, 1e9)", ts) - } - return nil -} diff --git a/vendor/github.com/golang/protobuf/ptypes/timestamp/timestamp.pb.go b/vendor/github.com/golang/protobuf/ptypes/timestamp/timestamp.pb.go deleted file mode 100644 index a76f8076..00000000 --- a/vendor/github.com/golang/protobuf/ptypes/timestamp/timestamp.pb.go +++ /dev/null @@ -1,64 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/golang/protobuf/ptypes/timestamp/timestamp.proto - -package timestamp - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - timestamppb "google.golang.org/protobuf/types/known/timestamppb" - reflect "reflect" -) - -// Symbols defined in public import of google/protobuf/timestamp.proto. - -type Timestamp = timestamppb.Timestamp - -var File_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto protoreflect.FileDescriptor - -var file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_rawDesc = []byte{ - 0x0a, 0x3b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x6c, - 0x61, 0x6e, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x70, 0x74, 0x79, - 0x70, 0x65, 0x73, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2f, 0x74, 0x69, - 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, - 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x42, 0x37, - 0x5a, 0x35, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x6c, - 0x61, 0x6e, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x70, 0x74, 0x79, - 0x70, 0x65, 0x73, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x3b, 0x74, 0x69, - 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x50, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, -} - -var file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_goTypes = []interface{}{} -var file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_init() } -func file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_init() { - if File_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto != nil { - return - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_rawDesc, - NumEnums: 0, - NumMessages: 0, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_goTypes, - DependencyIndexes: file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_depIdxs, - }.Build() - File_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto = out.File - file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_rawDesc = nil - file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_goTypes = nil - file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_depIdxs = nil -} diff --git a/vendor/github.com/jellydator/ttlcache/v3/cache.go b/vendor/github.com/jellydator/ttlcache/v3/cache.go index a1547fcb..1ad3afbe 100644 --- a/vendor/github.com/jellydator/ttlcache/v3/cache.go +++ b/vendor/github.com/jellydator/ttlcache/v3/cache.go @@ -148,6 +148,10 @@ func (c *Cache[K, V]) set(key K, value V, ttl time.Duration) *Item[K, V] { c.evict(EvictionReasonCapacityReached, c.items.lru.Back()) } + if ttl == PreviousOrDefaultTTL { + ttl = c.options.ttl + } + // create a new item item := newItem(key, value, ttl, c.options.enableVersionTracking) elem = c.items.lru.PushFront(item) diff --git a/vendor/github.com/jellydator/ttlcache/v3/item.go b/vendor/github.com/jellydator/ttlcache/v3/item.go index 72568e07..c3c26cf6 100644 --- a/vendor/github.com/jellydator/ttlcache/v3/item.go +++ b/vendor/github.com/jellydator/ttlcache/v3/item.go @@ -9,6 +9,10 @@ const ( // NoTTL indicates that an item should never expire. NoTTL time.Duration = -1 + // PreviousOrDefaultTTL indicates that existing TTL of item should be used + // default TTL will be used as fallback if item doesn't exist + PreviousOrDefaultTTL time.Duration = -2 + // DefaultTTL indicates that the default TTL value of the cache // instance should be used. DefaultTTL time.Duration = 0 @@ -58,17 +62,23 @@ func (item *Item[K, V]) update(value V, ttl time.Duration) { defer item.mu.Unlock() item.value = value + + // update version if enabled + if item.version > -1 { + item.version++ + } + + // no need to update ttl or expiry in this case + if ttl == PreviousOrDefaultTTL { + return + } + item.ttl = ttl // reset expiration timestamp because the new TTL may be // 0 or below item.expiresAt = time.Time{} item.touchUnsafe() - - // update version if enabled - if item.version > -1 { - item.version++ - } } // touch updates the item's expiration timestamp. diff --git a/vendor/github.com/redis/go-redis/v9/README.md b/vendor/github.com/redis/go-redis/v9/README.md index 98edbe21..043d3f0e 100644 --- a/vendor/github.com/redis/go-redis/v9/README.md +++ b/vendor/github.com/redis/go-redis/v9/README.md @@ -51,8 +51,8 @@ key value NoSQL database that uses RocksDB as storage engine and is compatible w ## Features -- Redis 3 commands except QUIT, MONITOR, and SYNC. -- Automatic connection pooling with +- Redis commands except QUIT and SYNC. +- Automatic connection pooling. - [Pub/Sub](https://redis.uptrace.dev/guide/go-redis-pubsub.html). - [Pipelines and transactions](https://redis.uptrace.dev/guide/go-redis-pipelines.html). - [Scripting](https://redis.uptrace.dev/guide/lua-scripting.html). @@ -161,6 +161,30 @@ func ExampleClient() *redis.Client { ``` + +### Advanced Configuration + +go-redis supports extending the client identification phase to allow projects to send their own custom client identification. + +#### Default Client Identification + +By default, go-redis automatically sends the client library name and version during the connection process. This feature is available in redis-server as of version 7.2. As a result, the command is "fire and forget", meaning it should fail silently, in the case that the redis server does not support this feature. + +#### Disabling Identity Verification + +When connection identity verification is not required or needs to be explicitly disabled, a `DisableIndentity` configuration option exists. In V10 of this library, `DisableIndentity` will become `DisableIdentity` in order to fix the associated typo. + +To disable verification, set the `DisableIndentity` option to `true` in the Redis client options: + +```go +rdb := redis.NewClient(&redis.Options{ + Addr: "localhost:6379", + Password: "", + DB: 0, + DisableIndentity: true, // Disable set-info on connect +}) +``` + ## Contributing Please see [out contributing guidelines](CONTRIBUTING.md) to help us improve this library! diff --git a/vendor/github.com/redis/go-redis/v9/bitmap_commands.go b/vendor/github.com/redis/go-redis/v9/bitmap_commands.go index 550d7f52..d9fc50dc 100644 --- a/vendor/github.com/redis/go-redis/v9/bitmap_commands.go +++ b/vendor/github.com/redis/go-redis/v9/bitmap_commands.go @@ -2,6 +2,7 @@ package redis import ( "context" + "errors" ) type BitMapCmdable interface { @@ -37,15 +38,28 @@ func (c cmdable) SetBit(ctx context.Context, key string, offset int64, value int type BitCount struct { Start, End int64 + Unit string // BYTE(default) | BIT } +const BitCountIndexByte string = "BYTE" +const BitCountIndexBit string = "BIT" + func (c cmdable) BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd { args := []interface{}{"bitcount", key} if bitCount != nil { + if bitCount.Unit == "" { + bitCount.Unit = "BYTE" + } + if bitCount.Unit != BitCountIndexByte && bitCount.Unit != BitCountIndexBit { + cmd := NewIntCmd(ctx) + cmd.SetErr(errors.New("redis: invalid bitcount index")) + return cmd + } args = append( args, bitCount.Start, bitCount.End, + string(bitCount.Unit), ) } cmd := NewIntCmd(ctx, args...) diff --git a/vendor/github.com/redis/go-redis/v9/command.go b/vendor/github.com/redis/go-redis/v9/command.go index 06ed86ed..9fb9a831 100644 --- a/vendor/github.com/redis/go-redis/v9/command.go +++ b/vendor/github.com/redis/go-redis/v9/command.go @@ -5310,6 +5310,16 @@ type LibraryInfo struct { LibVer *string } +// WithLibraryName returns a valid LibraryInfo with library name only. +func WithLibraryName(libName string) LibraryInfo { + return LibraryInfo{LibName: &libName} +} + +// WithLibraryVersion returns a valid LibraryInfo with library version only. +func WithLibraryVersion(libVer string) LibraryInfo { + return LibraryInfo{LibVer: &libVer} +} + // ------------------------------------------- type InfoCmd struct { diff --git a/vendor/github.com/redis/go-redis/v9/commands.go b/vendor/github.com/redis/go-redis/v9/commands.go index 546ebafb..db595944 100644 --- a/vendor/github.com/redis/go-redis/v9/commands.go +++ b/vendor/github.com/redis/go-redis/v9/commands.go @@ -309,7 +309,7 @@ func (c statefulCmdable) ClientSetInfo(ctx context.Context, info LibraryInfo) *S var cmd *StatusCmd if info.LibName != nil { - libName := fmt.Sprintf("go-redis(%s,%s)", *info.LibName, runtime.Version()) + libName := fmt.Sprintf("go-redis(%s,%s)", *info.LibName, internal.ReplaceSpaces(runtime.Version())) cmd = NewStatusCmd(ctx, "client", "setinfo", "LIB-NAME", libName) } else { cmd = NewStatusCmd(ctx, "client", "setinfo", "LIB-VER", *info.LibVer) diff --git a/vendor/github.com/redis/go-redis/v9/generic_commands.go b/vendor/github.com/redis/go-redis/v9/generic_commands.go index bf1fb47d..dc6c3fe0 100644 --- a/vendor/github.com/redis/go-redis/v9/generic_commands.go +++ b/vendor/github.com/redis/go-redis/v9/generic_commands.go @@ -19,6 +19,7 @@ type GenericCmdable interface { Keys(ctx context.Context, pattern string) *StringSliceCmd Migrate(ctx context.Context, host, port, key string, db int, timeout time.Duration) *StatusCmd Move(ctx context.Context, key string, db int) *BoolCmd + ObjectFreq(ctx context.Context, key string) *IntCmd ObjectRefCount(ctx context.Context, key string) *IntCmd ObjectEncoding(ctx context.Context, key string) *StringCmd ObjectIdleTime(ctx context.Context, key string) *DurationCmd @@ -159,6 +160,12 @@ func (c cmdable) Move(ctx context.Context, key string, db int) *BoolCmd { return cmd } +func (c cmdable) ObjectFreq(ctx context.Context, key string) *IntCmd { + cmd := NewIntCmd(ctx, "object", "freq", key) + _ = c(ctx, cmd) + return cmd +} + func (c cmdable) ObjectRefCount(ctx context.Context, key string) *IntCmd { cmd := NewIntCmd(ctx, "object", "refcount", key) _ = c(ctx, cmd) diff --git a/vendor/github.com/redis/go-redis/v9/internal/pool/pool.go b/vendor/github.com/redis/go-redis/v9/internal/pool/pool.go index 986c05d0..2125f3e1 100644 --- a/vendor/github.com/redis/go-redis/v9/internal/pool/pool.go +++ b/vendor/github.com/redis/go-redis/v9/internal/pool/pool.go @@ -168,9 +168,12 @@ func (p *ConnPool) newConn(ctx context.Context, pooled bool) (*Conn, error) { return nil, ErrClosed } + p.connsMu.Lock() if p.cfg.MaxActiveConns > 0 && p.poolSize >= p.cfg.MaxActiveConns { + p.connsMu.Unlock() return nil, ErrPoolExhausted } + p.connsMu.Unlock() cn, err := p.dialConn(ctx, pooled) if err != nil { @@ -180,6 +183,11 @@ func (p *ConnPool) newConn(ctx context.Context, pooled bool) (*Conn, error) { p.connsMu.Lock() defer p.connsMu.Unlock() + if p.cfg.MaxActiveConns > 0 && p.poolSize >= p.cfg.MaxActiveConns { + _ = cn.Close() + return nil, ErrPoolExhausted + } + p.conns = append(p.conns, cn) if pooled { // If pool is full remove the cn on next Put. diff --git a/vendor/github.com/redis/go-redis/v9/internal/util.go b/vendor/github.com/redis/go-redis/v9/internal/util.go index 77ca4ee1..ed81ad7a 100644 --- a/vendor/github.com/redis/go-redis/v9/internal/util.go +++ b/vendor/github.com/redis/go-redis/v9/internal/util.go @@ -2,6 +2,7 @@ package internal import ( "context" + "strings" "time" "github.com/redis/go-redis/v9/internal/util" @@ -44,3 +45,22 @@ func isLower(s string) bool { } return true } + +func ReplaceSpaces(s string) string { + // Pre-allocate a builder with the same length as s to minimize allocations. + // This is a basic optimization; adjust the initial size based on your use case. + var builder strings.Builder + builder.Grow(len(s)) + + for _, char := range s { + if char == ' ' { + // Replace space with a hyphen. + builder.WriteRune('-') + } else { + // Copy the character as-is. + builder.WriteRune(char) + } + } + + return builder.String() +} diff --git a/vendor/github.com/redis/go-redis/v9/osscluster.go b/vendor/github.com/redis/go-redis/v9/osscluster.go index 9e5eb046..17f98d9d 100644 --- a/vendor/github.com/redis/go-redis/v9/osscluster.go +++ b/vendor/github.com/redis/go-redis/v9/osscluster.go @@ -62,9 +62,10 @@ type ClusterOptions struct { OnConnect func(ctx context.Context, cn *Conn) error - Protocol int - Username string - Password string + Protocol int + Username string + Password string + CredentialsProvider func() (username string, password string) MaxRetries int MinRetryBackoff time.Duration @@ -271,9 +272,10 @@ func (opt *ClusterOptions) clientOptions() *Options { Dialer: opt.Dialer, OnConnect: opt.OnConnect, - Protocol: opt.Protocol, - Username: opt.Username, - Password: opt.Password, + Protocol: opt.Protocol, + Username: opt.Username, + Password: opt.Password, + CredentialsProvider: opt.CredentialsProvider, MaxRetries: opt.MaxRetries, MinRetryBackoff: opt.MinRetryBackoff, diff --git a/vendor/github.com/redis/go-redis/v9/package.json b/vendor/github.com/redis/go-redis/v9/package.json deleted file mode 100644 index 1a690047..00000000 --- a/vendor/github.com/redis/go-redis/v9/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "redis", - "version": "9.4.0", - "main": "index.js", - "repository": "git@github.com:redis/go-redis.git", - "author": "Vladimir Mihailenco ", - "license": "BSD-2-clause" -} diff --git a/vendor/github.com/redis/go-redis/v9/redis.go b/vendor/github.com/redis/go-redis/v9/redis.go index 4dd862b8..d25a0d31 100644 --- a/vendor/github.com/redis/go-redis/v9/redis.go +++ b/vendor/github.com/redis/go-redis/v9/redis.go @@ -312,17 +312,7 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error { // difficult to rely on error strings to determine all results. return err } - if !c.opt.DisableIndentity { - libName := "" - libVer := Version() - if c.opt.IdentitySuffix != "" { - libName = c.opt.IdentitySuffix - } - libInfo := LibraryInfo{LibName: &libName} - conn.ClientSetInfo(ctx, libInfo) - libInfo = LibraryInfo{LibVer: &libVer} - conn.ClientSetInfo(ctx, libInfo) - } + _, err := conn.Pipelined(ctx, func(pipe Pipeliner) error { if !auth && password != "" { if username != "" { @@ -350,6 +340,18 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error { return err } + if !c.opt.DisableIndentity { + libName := "" + libVer := Version() + if c.opt.IdentitySuffix != "" { + libName = c.opt.IdentitySuffix + } + p := conn.Pipeline() + p.ClientSetInfo(ctx, WithLibraryName(libName)) + p.ClientSetInfo(ctx, WithLibraryVersion(libVer)) + _, _ = p.Exec(ctx) + } + if c.opt.OnConnect != nil { return c.opt.OnConnect(ctx, conn) } diff --git a/vendor/github.com/redis/go-redis/v9/sentinel.go b/vendor/github.com/redis/go-redis/v9/sentinel.go index 9ace0886..188f8849 100644 --- a/vendor/github.com/redis/go-redis/v9/sentinel.go +++ b/vendor/github.com/redis/go-redis/v9/sentinel.go @@ -153,6 +153,9 @@ func (opt *FailoverOptions) sentinelOptions(addr string) *Options { ConnMaxLifetime: opt.ConnMaxLifetime, TLSConfig: opt.TLSConfig, + + DisableIndentity: opt.DisableIndentity, + IdentitySuffix: opt.IdentitySuffix, } } @@ -190,6 +193,9 @@ func (opt *FailoverOptions) clusterOptions() *ClusterOptions { ConnMaxLifetime: opt.ConnMaxLifetime, TLSConfig: opt.TLSConfig, + + DisableIndentity: opt.DisableIndentity, + IdentitySuffix: opt.IdentitySuffix, } } diff --git a/vendor/github.com/redis/go-redis/v9/version.go b/vendor/github.com/redis/go-redis/v9/version.go index 92f49820..e2c7f3e7 100644 --- a/vendor/github.com/redis/go-redis/v9/version.go +++ b/vendor/github.com/redis/go-redis/v9/version.go @@ -2,5 +2,5 @@ package redis // Version is the current release version. func Version() string { - return "9.4.0" + return "9.5.1" } diff --git a/vendor/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go b/vendor/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go index e9e97d45..856c75dd 100644 --- a/vendor/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go +++ b/vendor/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go @@ -18,8 +18,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 -// protoc v4.22.0 +// protoc-gen-go v1.32.0 +// protoc v4.25.2 // source: grpc/binlog/v1/binarylog.proto package grpc_binarylog_v1 diff --git a/vendor/google.golang.org/grpc/encoding/proto/proto.go b/vendor/google.golang.org/grpc/encoding/proto/proto.go index 0ee3d3ba..66d5cdf0 100644 --- a/vendor/google.golang.org/grpc/encoding/proto/proto.go +++ b/vendor/google.golang.org/grpc/encoding/proto/proto.go @@ -23,8 +23,9 @@ package proto import ( "fmt" - "github.com/golang/protobuf/proto" "google.golang.org/grpc/encoding" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/protoadapt" ) // Name is the name registered for the proto compressor. @@ -38,21 +39,34 @@ func init() { type codec struct{} func (codec) Marshal(v any) ([]byte, error) { - vv, ok := v.(proto.Message) - if !ok { + vv := messageV2Of(v) + if vv == nil { return nil, fmt.Errorf("failed to marshal, message is %T, want proto.Message", v) } + return proto.Marshal(vv) } func (codec) Unmarshal(data []byte, v any) error { - vv, ok := v.(proto.Message) - if !ok { + vv := messageV2Of(v) + if vv == nil { return fmt.Errorf("failed to unmarshal, message is %T, want proto.Message", v) } + return proto.Unmarshal(data, vv) } +func messageV2Of(v any) proto.Message { + switch v := v.(type) { + case protoadapt.MessageV1: + return protoadapt.MessageV2Of(v) + case protoadapt.MessageV2: + return v + } + + return nil +} + func (codec) Name() string { return Name } diff --git a/vendor/google.golang.org/grpc/health/grpc_health_v1/health.pb.go b/vendor/google.golang.org/grpc/health/grpc_health_v1/health.pb.go index 24299efd..5bf880d4 100644 --- a/vendor/google.golang.org/grpc/health/grpc_health_v1/health.pb.go +++ b/vendor/google.golang.org/grpc/health/grpc_health_v1/health.pb.go @@ -17,8 +17,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 -// protoc v4.22.0 +// protoc-gen-go v1.32.0 +// protoc v4.25.2 // source: grpc/health/v1/health.proto package grpc_health_v1 diff --git a/vendor/google.golang.org/grpc/health/grpc_health_v1/health_grpc.pb.go b/vendor/google.golang.org/grpc/health/grpc_health_v1/health_grpc.pb.go index 4439cda0..4c46c098 100644 --- a/vendor/google.golang.org/grpc/health/grpc_health_v1/health_grpc.pb.go +++ b/vendor/google.golang.org/grpc/health/grpc_health_v1/health_grpc.pb.go @@ -18,7 +18,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v4.22.0 +// - protoc v4.25.2 // source: grpc/health/v1/health.proto package grpc_health_v1 diff --git a/vendor/google.golang.org/grpc/internal/binarylog/method_logger.go b/vendor/google.golang.org/grpc/internal/binarylog/method_logger.go index 0f31274a..e8456a77 100644 --- a/vendor/google.golang.org/grpc/internal/binarylog/method_logger.go +++ b/vendor/google.golang.org/grpc/internal/binarylog/method_logger.go @@ -25,11 +25,12 @@ import ( "sync/atomic" "time" - "github.com/golang/protobuf/proto" - "github.com/golang/protobuf/ptypes" binlogpb "google.golang.org/grpc/binarylog/grpc_binarylog_v1" "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/durationpb" + "google.golang.org/protobuf/types/known/timestamppb" ) type callIDGenerator struct { @@ -88,7 +89,7 @@ func NewTruncatingMethodLogger(h, m uint64) *TruncatingMethodLogger { // in TruncatingMethodLogger as possible. func (ml *TruncatingMethodLogger) Build(c LogEntryConfig) *binlogpb.GrpcLogEntry { m := c.toProto() - timestamp, _ := ptypes.TimestampProto(time.Now()) + timestamp := timestamppb.Now() m.Timestamp = timestamp m.CallId = ml.callID m.SequenceIdWithinCall = ml.idWithinCallGen.next() @@ -178,7 +179,7 @@ func (c *ClientHeader) toProto() *binlogpb.GrpcLogEntry { Authority: c.Authority, } if c.Timeout > 0 { - clientHeader.Timeout = ptypes.DurationProto(c.Timeout) + clientHeader.Timeout = durationpb.New(c.Timeout) } ret := &binlogpb.GrpcLogEntry{ Type: binlogpb.GrpcLogEntry_EVENT_TYPE_CLIENT_HEADER, diff --git a/vendor/google.golang.org/grpc/internal/binarylog/sink.go b/vendor/google.golang.org/grpc/internal/binarylog/sink.go index 264de387..9ea598b1 100644 --- a/vendor/google.golang.org/grpc/internal/binarylog/sink.go +++ b/vendor/google.golang.org/grpc/internal/binarylog/sink.go @@ -25,8 +25,8 @@ import ( "sync" "time" - "github.com/golang/protobuf/proto" binlogpb "google.golang.org/grpc/binarylog/grpc_binarylog_v1" + "google.golang.org/protobuf/proto" ) var ( diff --git a/vendor/google.golang.org/grpc/internal/grpcrand/grpcrand.go b/vendor/google.golang.org/grpc/internal/grpcrand/grpcrand.go index aa97273e..0126d6b5 100644 --- a/vendor/google.golang.org/grpc/internal/grpcrand/grpcrand.go +++ b/vendor/google.golang.org/grpc/internal/grpcrand/grpcrand.go @@ -1,3 +1,8 @@ +//go:build !go1.21 + +// TODO: when this file is deleted (after Go 1.20 support is dropped), delete +// all of grpcrand and call the rand package directly. + /* * * Copyright 2018 gRPC authors. diff --git a/vendor/google.golang.org/grpc/internal/grpcrand/grpcrand_go1.21.go b/vendor/google.golang.org/grpc/internal/grpcrand/grpcrand_go1.21.go new file mode 100644 index 00000000..c37299af --- /dev/null +++ b/vendor/google.golang.org/grpc/internal/grpcrand/grpcrand_go1.21.go @@ -0,0 +1,73 @@ +//go:build go1.21 + +/* + * + * Copyright 2024 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// Package grpcrand implements math/rand functions in a concurrent-safe way +// with a global random source, independent of math/rand's global source. +package grpcrand + +import "math/rand" + +// This implementation will be used for Go version 1.21 or newer. +// For older versions, the original implementation with mutex will be used. + +// Int implements rand.Int on the grpcrand global source. +func Int() int { + return rand.Int() +} + +// Int63n implements rand.Int63n on the grpcrand global source. +func Int63n(n int64) int64 { + return rand.Int63n(n) +} + +// Intn implements rand.Intn on the grpcrand global source. +func Intn(n int) int { + return rand.Intn(n) +} + +// Int31n implements rand.Int31n on the grpcrand global source. +func Int31n(n int32) int32 { + return rand.Int31n(n) +} + +// Float64 implements rand.Float64 on the grpcrand global source. +func Float64() float64 { + return rand.Float64() +} + +// Uint64 implements rand.Uint64 on the grpcrand global source. +func Uint64() uint64 { + return rand.Uint64() +} + +// Uint32 implements rand.Uint32 on the grpcrand global source. +func Uint32() uint32 { + return rand.Uint32() +} + +// ExpFloat64 implements rand.ExpFloat64 on the grpcrand global source. +func ExpFloat64() float64 { + return rand.ExpFloat64() +} + +// Shuffle implements rand.Shuffle on the grpcrand global source. +var Shuffle = func(n int, f func(int, int)) { + rand.Shuffle(n, f) +} diff --git a/vendor/google.golang.org/grpc/internal/pretty/pretty.go b/vendor/google.golang.org/grpc/internal/pretty/pretty.go index 70331913..52cfab1b 100644 --- a/vendor/google.golang.org/grpc/internal/pretty/pretty.go +++ b/vendor/google.golang.org/grpc/internal/pretty/pretty.go @@ -24,7 +24,6 @@ import ( "encoding/json" "fmt" - "github.com/golang/protobuf/jsonpb" protov1 "github.com/golang/protobuf/proto" "google.golang.org/protobuf/encoding/protojson" protov2 "google.golang.org/protobuf/proto" @@ -38,15 +37,15 @@ const jsonIndent = " " func ToJSON(e any) string { switch ee := e.(type) { case protov1.Message: - mm := jsonpb.Marshaler{Indent: jsonIndent} - ret, err := mm.MarshalToString(ee) + mm := protojson.MarshalOptions{Indent: jsonIndent} + ret, err := mm.Marshal(protov1.MessageV2(ee)) if err != nil { // This may fail for proto.Anys, e.g. for xDS v2, LDS, the v2 // messages are not imported, and this will fail because the message // is not found. return fmt.Sprintf("%+v", ee) } - return ret + return string(ret) case protov2.Message: mm := protojson.MarshalOptions{ Multiline: true, diff --git a/vendor/google.golang.org/grpc/internal/status/status.go b/vendor/google.golang.org/grpc/internal/status/status.go index 03ef2fed..c7dbc820 100644 --- a/vendor/google.golang.org/grpc/internal/status/status.go +++ b/vendor/google.golang.org/grpc/internal/status/status.go @@ -31,10 +31,11 @@ import ( "errors" "fmt" - "github.com/golang/protobuf/proto" - "github.com/golang/protobuf/ptypes" spb "google.golang.org/genproto/googleapis/rpc/status" "google.golang.org/grpc/codes" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/protoadapt" + "google.golang.org/protobuf/types/known/anypb" ) // Status represents an RPC status code, message, and details. It is immutable @@ -130,14 +131,14 @@ func (s *Status) Err() error { // WithDetails returns a new status with the provided details messages appended to the status. // If any errors are encountered, it returns nil and the first error encountered. -func (s *Status) WithDetails(details ...proto.Message) (*Status, error) { +func (s *Status) WithDetails(details ...protoadapt.MessageV1) (*Status, error) { if s.Code() == codes.OK { return nil, errors.New("no error details for status with code OK") } // s.Code() != OK implies that s.Proto() != nil. p := s.Proto() for _, detail := range details { - any, err := ptypes.MarshalAny(detail) + any, err := anypb.New(protoadapt.MessageV2Of(detail)) if err != nil { return nil, err } @@ -154,12 +155,12 @@ func (s *Status) Details() []any { } details := make([]any, 0, len(s.s.Details)) for _, any := range s.s.Details { - detail := &ptypes.DynamicAny{} - if err := ptypes.UnmarshalAny(any, detail); err != nil { + detail, err := any.UnmarshalNew() + if err != nil { details = append(details, err) continue } - details = append(details, detail.Message) + details = append(details, detail) } return details } diff --git a/vendor/google.golang.org/grpc/internal/transport/controlbuf.go b/vendor/google.golang.org/grpc/internal/transport/controlbuf.go index b330cced..83c38298 100644 --- a/vendor/google.golang.org/grpc/internal/transport/controlbuf.go +++ b/vendor/google.golang.org/grpc/internal/transport/controlbuf.go @@ -535,8 +535,8 @@ const minBatchSize = 1000 // size is too low to give stream goroutines a chance to fill it up. // // Upon exiting, if the error causing the exit is not an I/O error, run() -// flushes and closes the underlying connection. Otherwise, the connection is -// left open to allow the I/O error to be encountered by the reader instead. +// flushes the underlying connection. The connection is always left open to +// allow different closing behavior on the client and server. func (l *loopyWriter) run() (err error) { defer func() { if l.logger.V(logLevel) { @@ -544,7 +544,6 @@ func (l *loopyWriter) run() (err error) { } if !isIOError(err) { l.framer.writer.Flush() - l.conn.Close() } l.cbuf.finish() }() diff --git a/vendor/google.golang.org/grpc/internal/transport/handler_server.go b/vendor/google.golang.org/grpc/internal/transport/handler_server.go index a9d70e2a..bd39ff9a 100644 --- a/vendor/google.golang.org/grpc/internal/transport/handler_server.go +++ b/vendor/google.golang.org/grpc/internal/transport/handler_server.go @@ -35,7 +35,6 @@ import ( "sync" "time" - "github.com/golang/protobuf/proto" "golang.org/x/net/http2" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" @@ -45,6 +44,7 @@ import ( "google.golang.org/grpc/peer" "google.golang.org/grpc/stats" "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" ) // NewServerHandlerTransport returns a ServerTransport handling gRPC from diff --git a/vendor/google.golang.org/grpc/internal/transport/http2_client.go b/vendor/google.golang.org/grpc/internal/transport/http2_client.go index c33ac596..eff87996 100644 --- a/vendor/google.golang.org/grpc/internal/transport/http2_client.go +++ b/vendor/google.golang.org/grpc/internal/transport/http2_client.go @@ -451,7 +451,13 @@ func newHTTP2Client(connectCtx, ctx context.Context, addr resolver.Address, opts } go func() { t.loopy = newLoopyWriter(clientSide, t.framer, t.controlBuf, t.bdpEst, t.conn, t.logger) - t.loopy.run() + if err := t.loopy.run(); !isIOError(err) { + // Immediately close the connection, as the loopy writer returns + // when there are no more active streams and we were draining (the + // server sent a GOAWAY). For I/O errors, the reader will hit it + // after draining any remaining incoming data. + t.conn.Close() + } close(t.writerDone) }() return t, nil diff --git a/vendor/google.golang.org/grpc/internal/transport/http2_server.go b/vendor/google.golang.org/grpc/internal/transport/http2_server.go index f6bac0e8..3839c1ad 100644 --- a/vendor/google.golang.org/grpc/internal/transport/http2_server.go +++ b/vendor/google.golang.org/grpc/internal/transport/http2_server.go @@ -32,13 +32,13 @@ import ( "sync/atomic" "time" - "github.com/golang/protobuf/proto" "golang.org/x/net/http2" "golang.org/x/net/http2/hpack" "google.golang.org/grpc/internal/grpclog" "google.golang.org/grpc/internal/grpcutil" "google.golang.org/grpc/internal/pretty" "google.golang.org/grpc/internal/syscall" + "google.golang.org/protobuf/proto" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" @@ -322,8 +322,24 @@ func NewServerTransport(conn net.Conn, config *ServerConfig) (_ ServerTransport, go func() { t.loopy = newLoopyWriter(serverSide, t.framer, t.controlBuf, t.bdpEst, t.conn, t.logger) t.loopy.ssGoAwayHandler = t.outgoingGoAwayHandler - t.loopy.run() + err := t.loopy.run() close(t.loopyWriterDone) + if !isIOError(err) { + // Close the connection if a non-I/O error occurs (for I/O errors + // the reader will also encounter the error and close). Wait 1 + // second before closing the connection, or when the reader is done + // (i.e. the client already closed the connection or a connection + // error occurred). This avoids the potential problem where there + // is unread data on the receive side of the connection, which, if + // closed, would lead to a TCP RST instead of FIN, and the client + // encountering errors. For more info: + // https://github.com/grpc/grpc-go/issues/5358 + select { + case <-t.readerDone: + case <-time.After(time.Second): + } + t.conn.Close() + } }() go t.keepalive() return t, nil @@ -609,8 +625,8 @@ func (t *http2Server) operateHeaders(ctx context.Context, frame *http2.MetaHeade // traceCtx attaches trace to ctx and returns the new context. func (t *http2Server) HandleStreams(ctx context.Context, handle func(*Stream)) { defer func() { - <-t.loopyWriterDone close(t.readerDone) + <-t.loopyWriterDone }() for { t.controlBuf.throttle() @@ -636,10 +652,6 @@ func (t *http2Server) HandleStreams(ctx context.Context, handle func(*Stream)) { } continue } - if err == io.EOF || err == io.ErrUnexpectedEOF { - t.Close(err) - return - } t.Close(err) return } @@ -1329,6 +1341,7 @@ func (t *http2Server) outgoingGoAwayHandler(g *goAway) (bool, error) { if err := t.framer.fr.WriteGoAway(sid, g.code, g.debugData); err != nil { return false, err } + t.framer.writer.Flush() if retErr != nil { return false, retErr } @@ -1349,7 +1362,7 @@ func (t *http2Server) outgoingGoAwayHandler(g *goAway) (bool, error) { return false, err } go func() { - timer := time.NewTimer(time.Minute) + timer := time.NewTimer(5 * time.Second) defer timer.Stop() select { case <-t.drainEvent.Done(): diff --git a/vendor/google.golang.org/grpc/rpc_util.go b/vendor/google.golang.org/grpc/rpc_util.go index a4b6bc68..d17ede0f 100644 --- a/vendor/google.golang.org/grpc/rpc_util.go +++ b/vendor/google.golang.org/grpc/rpc_util.go @@ -189,6 +189,20 @@ type EmptyCallOption struct{} func (EmptyCallOption) before(*callInfo) error { return nil } func (EmptyCallOption) after(*callInfo, *csAttempt) {} +// StaticMethod returns a CallOption which specifies that a call is being made +// to a method that is static, which means the method is known at compile time +// and doesn't change at runtime. This can be used as a signal to stats plugins +// that this method is safe to include as a key to a measurement. +func StaticMethod() CallOption { + return StaticMethodCallOption{} +} + +// StaticMethodCallOption is a CallOption that specifies that a call comes +// from a static method. +type StaticMethodCallOption struct { + EmptyCallOption +} + // Header returns a CallOptions that retrieves the header metadata // for a unary RPC. func Header(md *metadata.MD) CallOption { @@ -958,6 +972,7 @@ const ( SupportPackageIsVersion5 = true SupportPackageIsVersion6 = true SupportPackageIsVersion7 = true + SupportPackageIsVersion8 = true ) const grpcUA = "grpc-go/" + Version diff --git a/vendor/google.golang.org/grpc/server.go b/vendor/google.golang.org/grpc/server.go index e89c5ac6..0bf5c78b 100644 --- a/vendor/google.golang.org/grpc/server.go +++ b/vendor/google.golang.org/grpc/server.go @@ -33,8 +33,6 @@ import ( "sync/atomic" "time" - "golang.org/x/net/trace" - "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" "google.golang.org/grpc/encoding" @@ -131,7 +129,7 @@ type Server struct { drain bool cv *sync.Cond // signaled when connections close for GracefulStop services map[string]*serviceInfo // service name -> service info - events trace.EventLog + events traceEventLog quit *grpcsync.Event done *grpcsync.Event @@ -670,7 +668,7 @@ func NewServer(opt ...ServerOption) *Server { s.cv = sync.NewCond(&s.mu) if EnableTracing { _, file, line, _ := runtime.Caller(1) - s.events = trace.NewEventLog("grpc.Server", fmt.Sprintf("%s:%d", file, line)) + s.events = newTraceEventLog("grpc.Server", fmt.Sprintf("%s:%d", file, line)) } if s.opts.numServerWorkers > 0 { @@ -1734,8 +1732,8 @@ func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Str ctx = contextWithServer(ctx, s) var ti *traceInfo if EnableTracing { - tr := trace.New("grpc.Recv."+methodFamily(stream.Method()), stream.Method()) - ctx = trace.NewContext(ctx, tr) + tr := newTrace("grpc.Recv."+methodFamily(stream.Method()), stream.Method()) + ctx = newTraceContext(ctx, tr) ti = &traceInfo{ tr: tr, firstLine: firstLine{ diff --git a/vendor/google.golang.org/grpc/stream.go b/vendor/google.golang.org/grpc/stream.go index d621f52b..814e9983 100644 --- a/vendor/google.golang.org/grpc/stream.go +++ b/vendor/google.golang.org/grpc/stream.go @@ -27,7 +27,6 @@ import ( "sync" "time" - "golang.org/x/net/trace" "google.golang.org/grpc/balancer" "google.golang.org/grpc/codes" "google.golang.org/grpc/encoding" @@ -431,7 +430,7 @@ func (cs *clientStream) newAttemptLocked(isTransparent bool) (*csAttempt, error) var trInfo *traceInfo if EnableTracing { trInfo = &traceInfo{ - tr: trace.New("grpc.Sent."+methodFamily(method), method), + tr: newTrace("grpc.Sent."+methodFamily(method), method), firstLine: firstLine{ client: true, }, @@ -440,7 +439,7 @@ func (cs *clientStream) newAttemptLocked(isTransparent bool) (*csAttempt, error) trInfo.firstLine.deadline = time.Until(deadline) } trInfo.tr.LazyLog(&trInfo.firstLine, false) - ctx = trace.NewContext(ctx, trInfo.tr) + ctx = newTraceContext(ctx, trInfo.tr) } if cs.cc.parsedTarget.URL.Scheme == internal.GRPCResolverSchemeExtraMetadata { diff --git a/vendor/google.golang.org/grpc/trace.go b/vendor/google.golang.org/grpc/trace.go index 9ded7932..10f4f798 100644 --- a/vendor/google.golang.org/grpc/trace.go +++ b/vendor/google.golang.org/grpc/trace.go @@ -26,8 +26,6 @@ import ( "strings" "sync" "time" - - "golang.org/x/net/trace" ) // EnableTracing controls whether to trace RPCs using the golang.org/x/net/trace package. @@ -44,9 +42,31 @@ func methodFamily(m string) string { return m } +// traceEventLog mirrors golang.org/x/net/trace.EventLog. +// +// It exists in order to avoid importing x/net/trace on grpcnotrace builds. +type traceEventLog interface { + Printf(format string, a ...any) + Errorf(format string, a ...any) + Finish() +} + +// traceLog mirrors golang.org/x/net/trace.Trace. +// +// It exists in order to avoid importing x/net/trace on grpcnotrace builds. +type traceLog interface { + LazyLog(x fmt.Stringer, sensitive bool) + LazyPrintf(format string, a ...any) + SetError() + SetRecycler(f func(any)) + SetTraceInfo(traceID, spanID uint64) + SetMaxEvents(m int) + Finish() +} + // traceInfo contains tracing information for an RPC. type traceInfo struct { - tr trace.Trace + tr traceLog firstLine firstLine } diff --git a/vendor/google.golang.org/grpc/trace_notrace.go b/vendor/google.golang.org/grpc/trace_notrace.go new file mode 100644 index 00000000..1da3a230 --- /dev/null +++ b/vendor/google.golang.org/grpc/trace_notrace.go @@ -0,0 +1,52 @@ +//go:build grpcnotrace + +/* + * + * Copyright 2024 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package grpc + +// grpcnotrace can be used to avoid importing golang.org/x/net/trace, which in +// turn enables binaries using gRPC-Go for dead code elimination, which can +// yield 10-15% improvements in binary size when tracing is not needed. + +import ( + "context" + "fmt" +) + +type notrace struct{} + +func (notrace) LazyLog(x fmt.Stringer, sensitive bool) {} +func (notrace) LazyPrintf(format string, a ...any) {} +func (notrace) SetError() {} +func (notrace) SetRecycler(f func(any)) {} +func (notrace) SetTraceInfo(traceID, spanID uint64) {} +func (notrace) SetMaxEvents(m int) {} +func (notrace) Finish() {} + +func newTrace(family, title string) traceLog { + return notrace{} +} + +func newTraceContext(ctx context.Context, tr traceLog) context.Context { + return ctx +} + +func newTraceEventLog(family, title string) traceEventLog { + return nil +} diff --git a/vendor/google.golang.org/grpc/trace_withtrace.go b/vendor/google.golang.org/grpc/trace_withtrace.go new file mode 100644 index 00000000..88d6e857 --- /dev/null +++ b/vendor/google.golang.org/grpc/trace_withtrace.go @@ -0,0 +1,39 @@ +//go:build !grpcnotrace + +/* + * + * Copyright 2024 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package grpc + +import ( + "context" + + t "golang.org/x/net/trace" +) + +func newTrace(family, title string) traceLog { + return t.New(family, title) +} + +func newTraceContext(ctx context.Context, tr traceLog) context.Context { + return t.NewContext(ctx, tr) +} + +func newTraceEventLog(family, title string) traceEventLog { + return t.NewEventLog(family, title) +} diff --git a/vendor/google.golang.org/grpc/version.go b/vendor/google.golang.org/grpc/version.go index 1ad1ba2a..df85a021 100644 --- a/vendor/google.golang.org/grpc/version.go +++ b/vendor/google.golang.org/grpc/version.go @@ -19,4 +19,4 @@ package grpc // Version is the current grpc version. -const Version = "1.61.0" +const Version = "1.62.0" diff --git a/vendor/google.golang.org/grpc/vet.sh b/vendor/google.golang.org/grpc/vet.sh index 5da38a40..7a33c215 100644 --- a/vendor/google.golang.org/grpc/vet.sh +++ b/vendor/google.golang.org/grpc/vet.sh @@ -41,7 +41,7 @@ if [[ "$1" = "-install" ]]; then popd if [[ -z "${VET_SKIP_PROTO}" ]]; then if [[ "${GITHUB_ACTIONS}" = "true" ]]; then - PROTOBUF_VERSION=22.0 # a.k.a v4.22.0 in pb.go files. + PROTOBUF_VERSION=25.2 # a.k.a. v4.22.0 in pb.go files. PROTOC_FILENAME=protoc-${PROTOBUF_VERSION}-linux-x86_64.zip pushd /home/runner/go wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/${PROTOC_FILENAME} diff --git a/vendor/google.golang.org/protobuf/protoadapt/convert.go b/vendor/google.golang.org/protobuf/protoadapt/convert.go new file mode 100644 index 00000000..ea276d15 --- /dev/null +++ b/vendor/google.golang.org/protobuf/protoadapt/convert.go @@ -0,0 +1,31 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package protoadapt bridges the original and new proto APIs. +package protoadapt + +import ( + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/runtime/protoiface" + "google.golang.org/protobuf/runtime/protoimpl" +) + +// MessageV1 is the original [github.com/golang/protobuf/proto.Message] type. +type MessageV1 = protoiface.MessageV1 + +// MessageV2 is the [google.golang.org/protobuf/proto.Message] type used by the +// current [google.golang.org/protobuf] module, adding support for reflection. +type MessageV2 = proto.Message + +// MessageV1Of converts a v2 message to a v1 message. +// It returns nil if m is nil. +func MessageV1Of(m MessageV2) MessageV1 { + return protoimpl.X.ProtoMessageV1Of(m) +} + +// MessageV2Of converts a v1 message to a v2 message. +// It returns nil if m is nil. +func MessageV2Of(m MessageV1) MessageV2 { + return protoimpl.X.ProtoMessageV2Of(m) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index b93f64b5..1ac80dd8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -15,12 +15,7 @@ github.com/dgryski/go-rendezvous github.com/envoyproxy/protoc-gen-validate/validate # github.com/golang/protobuf v1.5.3 ## explicit; go 1.9 -github.com/golang/protobuf/jsonpb github.com/golang/protobuf/proto -github.com/golang/protobuf/ptypes -github.com/golang/protobuf/ptypes/any -github.com/golang/protobuf/ptypes/duration -github.com/golang/protobuf/ptypes/timestamp # github.com/golang/snappy v0.0.4 ## explicit github.com/golang/snappy @@ -61,7 +56,7 @@ github.com/jackc/pgx/v5/stdlib ## explicit; go 1.19 github.com/jackc/puddle/v2 github.com/jackc/puddle/v2/internal/genstack -# github.com/jellydator/ttlcache/v3 v3.1.1 +# github.com/jellydator/ttlcache/v3 v3.2.0 ## explicit; go 1.18 github.com/jellydator/ttlcache/v3 # github.com/mennanov/fmutils v0.2.1 @@ -76,7 +71,7 @@ github.com/ownmfa/proto/go/api # github.com/pmezard/go-difflib v1.0.0 ## explicit github.com/pmezard/go-difflib/difflib -# github.com/redis/go-redis/v9 v9.4.0 +# github.com/redis/go-redis/v9 v9.5.1 ## explicit; go 1.18 github.com/redis/go-redis/v9 github.com/redis/go-redis/v9/internal @@ -103,7 +98,7 @@ github.com/stretchr/testify/require # go.uber.org/mock v0.4.0 ## explicit; go 1.20 go.uber.org/mock/gomock -# golang.org/x/crypto v0.19.0 +# golang.org/x/crypto v0.20.0 ## explicit; go 1.18 golang.org/x/crypto/bcrypt golang.org/x/crypto/blowfish @@ -139,18 +134,18 @@ golang.org/x/text/transform golang.org/x/text/unicode/bidi golang.org/x/text/unicode/norm golang.org/x/text/width -# google.golang.org/genproto v0.0.0-20240205150955-31a09d347014 +# google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c ## explicit; go 1.19 google.golang.org/genproto/internal -# google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014 +# google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c ## explicit; go 1.19 google.golang.org/genproto/googleapis/api google.golang.org/genproto/googleapis/api/annotations google.golang.org/genproto/googleapis/api/httpbody -# google.golang.org/genproto/googleapis/rpc v0.0.0-20240205150955-31a09d347014 +# google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c ## explicit; go 1.19 google.golang.org/genproto/googleapis/rpc/status -# google.golang.org/grpc v1.61.0 +# google.golang.org/grpc v1.62.0 ## explicit; go 1.19 google.golang.org/grpc google.golang.org/grpc/attributes @@ -230,6 +225,7 @@ google.golang.org/protobuf/internal/set google.golang.org/protobuf/internal/strs google.golang.org/protobuf/internal/version google.golang.org/protobuf/proto +google.golang.org/protobuf/protoadapt google.golang.org/protobuf/reflect/protodesc google.golang.org/protobuf/reflect/protoreflect google.golang.org/protobuf/reflect/protoregistry