From c015ff9539d27bf5e922728a4c253319da257061 Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Wed, 12 Sep 2018 20:29:07 +0200 Subject: [PATCH 1/2] chore: switch to moul.io/protoc-gen-gotemplate --- .travis.yml | 3 +- Dockerfile | 4 +-- README.md | 2 +- cmd/web-editor/static/index.html | 4 +-- encoder.go | 2 +- examples/go-kit/glide.yaml | 2 +- examples/go-kit/main.go | 30 +++++++++---------- .../session/gen/client/grpc/client.go | 4 +-- .../session/gen/endpoints/endpoints.go | 2 +- .../session/gen/transports/grpc/grpc.go | 4 +-- .../session/gen/transports/http/http.go | 4 +-- examples/go-kit/services/session/service.go | 2 +- .../services/sprint/gen/client/grpc/client.go | 4 +-- .../sprint/gen/endpoints/endpoints.go | 2 +- .../sprint/gen/transports/grpc/grpc.go | 4 +-- .../sprint/gen/transports/http/http.go | 4 +-- examples/go-kit/services/sprint/service.go | 2 +- .../services/user/gen/client/grpc/client.go | 4 +-- .../services/user/gen/endpoints/endpoints.go | 2 +- .../services/user/gen/transports/grpc/grpc.go | 4 +-- .../services/user/gen/transports/http/http.go | 4 +-- examples/go-kit/services/user/service.go | 2 +- examples/helpers/helpers.proto | 2 +- examples/import/Makefile | 2 +- .../output/models/article/article.pb.go | 2 +- examples/import/output/output.go | 6 ++-- examples/import/templates/output.go.tmpl | 6 ++-- examples/single-package-mode/Makefile | 2 +- .../single-package-mode/output/bbb/bbb.pb.go | 2 +- .../single-package-mode/output/bbb/service.go | 2 +- .../single-package-mode/proto/aaa/aaa.proto | 4 +-- .../single-package-mode/proto/bbb/bbb.proto | 4 +-- main.go | 4 +-- slides/README.md | 16 +++++----- 34 files changed, 74 insertions(+), 73 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1ceb1e8..76545aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: go -go: 1.8.x +go: 1.11.x +go_import_path: moul.io/protoc-gen-gotemplate install: - go get github.com/Masterminds/glide - wget https://raw.githubusercontent.com/grpc-ecosystem/grpc-gateway/master/.travis/install-protoc.sh && chmod +x install-protoc.sh && ./install-protoc.sh 3.4.0 diff --git a/Dockerfile b/Dockerfile index b631dc3..db66eac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN apk --update add make git go rsync libc-dev \ && go get -u golang.org/x/tools/cmd/goimports # Install protoc-gen-gotemplate -COPY . /go/src/github.com/moul/protoc-gen-gotemplate -WORKDIR /go/src/github.com/moul/protoc-gen-gotemplate +COPY . /go/src/moul.io/protoc-gen-gotemplate +WORKDIR /go/src/moul.io/protoc-gen-gotemplate RUN git remote set-url origin https://github.com/moul/protoc-gen-gotemplate RUN go install . ./cmd/web-editor diff --git a/README.md b/README.md index c3af012..d87aff2 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ See the project helpers for the complete list. * Install the **Go** compiler and tools from https://golang.org/doc/install * Install **protobuf**: `go get -u github.com/golang/protobuf/{proto,protoc-gen-go}` -* Install **protoc-gen-gotemplate**: `go get -u github.com/moul/protoc-gen-gotemplate` +* Install **protoc-gen-gotemplate**: `go get -u moul.io/protoc-gen-gotemplate` ## Docker diff --git a/cmd/web-editor/static/index.html b/cmd/web-editor/static/index.html index 278c848..ee28ac1 100644 --- a/cmd/web-editor/static/index.html +++ b/cmd/web-editor/static/index.html @@ -129,10 +129,10 @@
Command: protoc --gotemplate_out=template_dir=.:. example.proto
-
Powered by protoc-gen-gotemplate
+
Powered by protoc-gen-gotemplate
- Fork me on GitHub + Fork me on GitHub diff --git a/encoder.go b/encoder.go index f5d5fe7..8258b3b 100644 --- a/encoder.go +++ b/encoder.go @@ -12,7 +12,7 @@ import ( "github.com/golang/protobuf/protoc-gen-go/descriptor" "github.com/golang/protobuf/protoc-gen-go/plugin" - pgghelpers "github.com/moul/protoc-gen-gotemplate/helpers" + pgghelpers "moul.io/protoc-gen-gotemplate/helpers" ) type GenericTemplateBasedEncoder struct { diff --git a/examples/go-kit/glide.yaml b/examples/go-kit/glide.yaml index 807973a..a7ec331 100644 --- a/examples/go-kit/glide.yaml +++ b/examples/go-kit/glide.yaml @@ -1,4 +1,4 @@ -package: github.com/moul/protoc-gen-gotemplate/examples/go-kit +package: moul.io/protoc-gen-gotemplate/examples/go-kit import: - package: github.com/go-kit/kit subpackages: diff --git a/examples/go-kit/main.go b/examples/go-kit/main.go index e544e3c..1de10ff 100644 --- a/examples/go-kit/main.go +++ b/examples/go-kit/main.go @@ -12,23 +12,23 @@ import ( "github.com/gorilla/handlers" "google.golang.org/grpc" - session_svc "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session" - session_endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints" - session_pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" - session_grpctransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/transports/grpc" - session_httptransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/transports/http" + session_svc "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session" + session_endpoints "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints" + session_pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" + session_grpctransport "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session/gen/transports/grpc" + session_httptransport "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session/gen/transports/http" - sprint_svc "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint" - sprint_endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints" - sprint_pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" - sprint_grpctransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/transports/grpc" - sprint_httptransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/transports/http" + sprint_svc "moul.io/protoc-gen-gotemplate/examples/go-kit/services/sprint" + sprint_endpoints "moul.io/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints" + sprint_pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" + sprint_grpctransport "moul.io/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/transports/grpc" + sprint_httptransport "moul.io/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/transports/http" - user_svc "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user" - user_endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints" - user_pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb" - user_grpctransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/transports/grpc" - user_httptransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/transports/http" + user_svc "moul.io/protoc-gen-gotemplate/examples/go-kit/services/user" + user_endpoints "moul.io/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints" + user_pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb" + user_grpctransport "moul.io/protoc-gen-gotemplate/examples/go-kit/services/user/gen/transports/grpc" + user_httptransport "moul.io/protoc-gen-gotemplate/examples/go-kit/services/user/gen/transports/http" ) func main() { diff --git a/examples/go-kit/services/session/gen/client/grpc/client.go b/examples/go-kit/services/session/gen/client/grpc/client.go index 9d69bb5..d09c75c 100644 --- a/examples/go-kit/services/session/gen/client/grpc/client.go +++ b/examples/go-kit/services/session/gen/client/grpc/client.go @@ -9,8 +9,8 @@ import ( grpctransport "github.com/go-kit/kit/transport/grpc" "google.golang.org/grpc" - endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" + endpoints "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" ) func New(conn *grpc.ClientConn, logger log.Logger) pb.SessionServiceServer { diff --git a/examples/go-kit/services/session/gen/endpoints/endpoints.go b/examples/go-kit/services/session/gen/endpoints/endpoints.go index edba02a..597ef54 100644 --- a/examples/go-kit/services/session/gen/endpoints/endpoints.go +++ b/examples/go-kit/services/session/gen/endpoints/endpoints.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/go-kit/kit/endpoint" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" oldcontext "golang.org/x/net/context" ) diff --git a/examples/go-kit/services/session/gen/transports/grpc/grpc.go b/examples/go-kit/services/session/gen/transports/grpc/grpc.go index eccbb3d..99b65b3 100644 --- a/examples/go-kit/services/session/gen/transports/grpc/grpc.go +++ b/examples/go-kit/services/session/gen/transports/grpc/grpc.go @@ -7,8 +7,8 @@ import ( grpctransport "github.com/go-kit/kit/transport/grpc" oldcontext "golang.org/x/net/context" - endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" + endpoints "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" ) // avoid import errors diff --git a/examples/go-kit/services/session/gen/transports/http/http.go b/examples/go-kit/services/session/gen/transports/http/http.go index b608681..d83c9c5 100644 --- a/examples/go-kit/services/session/gen/transports/http/http.go +++ b/examples/go-kit/services/session/gen/transports/http/http.go @@ -8,8 +8,8 @@ import ( gokit_endpoint "github.com/go-kit/kit/endpoint" httptransport "github.com/go-kit/kit/transport/http" - endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" + endpoints "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" ) var _ = log.Printf diff --git a/examples/go-kit/services/session/service.go b/examples/go-kit/services/session/service.go index b7e2ea2..412b6eb 100644 --- a/examples/go-kit/services/session/service.go +++ b/examples/go-kit/services/session/service.go @@ -5,7 +5,7 @@ import ( "golang.org/x/net/context" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" ) type Service struct{} diff --git a/examples/go-kit/services/sprint/gen/client/grpc/client.go b/examples/go-kit/services/sprint/gen/client/grpc/client.go index a7ef1d2..ef39bac 100644 --- a/examples/go-kit/services/sprint/gen/client/grpc/client.go +++ b/examples/go-kit/services/sprint/gen/client/grpc/client.go @@ -9,8 +9,8 @@ import ( grpctransport "github.com/go-kit/kit/transport/grpc" "google.golang.org/grpc" - endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" + endpoints "moul.io/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" ) func New(conn *grpc.ClientConn, logger log.Logger) pb.SprintServiceServer { diff --git a/examples/go-kit/services/sprint/gen/endpoints/endpoints.go b/examples/go-kit/services/sprint/gen/endpoints/endpoints.go index 47869d5..0b4558a 100644 --- a/examples/go-kit/services/sprint/gen/endpoints/endpoints.go +++ b/examples/go-kit/services/sprint/gen/endpoints/endpoints.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/go-kit/kit/endpoint" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" oldcontext "golang.org/x/net/context" ) diff --git a/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go b/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go index 5fd10c8..a301589 100644 --- a/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go +++ b/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go @@ -7,8 +7,8 @@ import ( grpctransport "github.com/go-kit/kit/transport/grpc" oldcontext "golang.org/x/net/context" - endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" + endpoints "moul.io/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" ) // avoid import errors diff --git a/examples/go-kit/services/sprint/gen/transports/http/http.go b/examples/go-kit/services/sprint/gen/transports/http/http.go index b6df66a..40259f5 100644 --- a/examples/go-kit/services/sprint/gen/transports/http/http.go +++ b/examples/go-kit/services/sprint/gen/transports/http/http.go @@ -8,8 +8,8 @@ import ( gokit_endpoint "github.com/go-kit/kit/endpoint" httptransport "github.com/go-kit/kit/transport/http" - endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" + endpoints "moul.io/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" ) var _ = log.Printf diff --git a/examples/go-kit/services/sprint/service.go b/examples/go-kit/services/sprint/service.go index 6b26f7c..0b3606f 100644 --- a/examples/go-kit/services/sprint/service.go +++ b/examples/go-kit/services/sprint/service.go @@ -5,7 +5,7 @@ import ( "golang.org/x/net/context" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" ) type Service struct{} diff --git a/examples/go-kit/services/user/gen/client/grpc/client.go b/examples/go-kit/services/user/gen/client/grpc/client.go index 105f036..ea61cb8 100644 --- a/examples/go-kit/services/user/gen/client/grpc/client.go +++ b/examples/go-kit/services/user/gen/client/grpc/client.go @@ -9,8 +9,8 @@ import ( grpctransport "github.com/go-kit/kit/transport/grpc" "google.golang.org/grpc" - endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb" + endpoints "moul.io/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb" ) func New(conn *grpc.ClientConn, logger log.Logger) pb.UserServiceServer { diff --git a/examples/go-kit/services/user/gen/endpoints/endpoints.go b/examples/go-kit/services/user/gen/endpoints/endpoints.go index bb13e4a..f995b6e 100644 --- a/examples/go-kit/services/user/gen/endpoints/endpoints.go +++ b/examples/go-kit/services/user/gen/endpoints/endpoints.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/go-kit/kit/endpoint" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb" oldcontext "golang.org/x/net/context" ) diff --git a/examples/go-kit/services/user/gen/transports/grpc/grpc.go b/examples/go-kit/services/user/gen/transports/grpc/grpc.go index 636107f..3d225ba 100644 --- a/examples/go-kit/services/user/gen/transports/grpc/grpc.go +++ b/examples/go-kit/services/user/gen/transports/grpc/grpc.go @@ -7,8 +7,8 @@ import ( grpctransport "github.com/go-kit/kit/transport/grpc" oldcontext "golang.org/x/net/context" - endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb" + endpoints "moul.io/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb" ) // avoid import errors diff --git a/examples/go-kit/services/user/gen/transports/http/http.go b/examples/go-kit/services/user/gen/transports/http/http.go index 409ab6f..498cd5b 100644 --- a/examples/go-kit/services/user/gen/transports/http/http.go +++ b/examples/go-kit/services/user/gen/transports/http/http.go @@ -8,8 +8,8 @@ import ( gokit_endpoint "github.com/go-kit/kit/endpoint" httptransport "github.com/go-kit/kit/transport/http" - endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb" + endpoints "moul.io/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb" ) var _ = log.Printf diff --git a/examples/go-kit/services/user/service.go b/examples/go-kit/services/user/service.go index b4bb7f1..253bf5c 100644 --- a/examples/go-kit/services/user/service.go +++ b/examples/go-kit/services/user/service.go @@ -5,7 +5,7 @@ import ( "golang.org/x/net/context" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb" ) type Service struct{} diff --git a/examples/helpers/helpers.proto b/examples/helpers/helpers.proto index d45e9bf..6dbf122 100644 --- a/examples/helpers/helpers.proto +++ b/examples/helpers/helpers.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package dummy; -option go_package = "github.com/moul/protoc-gen-gotemplate/examples/helpers"; +option go_package = "moul.io/protoc-gen-gotemplate/examples/helpers"; message Dummy1 { float aaa = 1; diff --git a/examples/import/Makefile b/examples/import/Makefile index af733c7..9cf5779 100644 --- a/examples/import/Makefile +++ b/examples/import/Makefile @@ -3,7 +3,7 @@ build: mkdir -p output # generate pb.go inluding imported proto - protoc --go_out=Mproto/common.proto=github.com/moul/protoc-gen-gotemplate/examples/import/output/models/common:./output proto/article.proto + protoc --go_out=Mproto/common.proto=moul.io/protoc-gen-gotemplate/examples/import/output/models/common:./output proto/article.proto protoc --go_out=,plugins=grpc:./output proto/common.proto # build our go file based on our template diff --git a/examples/import/output/models/article/article.pb.go b/examples/import/output/models/article/article.pb.go index eaa6c2b..16b2651 100644 --- a/examples/import/output/models/article/article.pb.go +++ b/examples/import/output/models/article/article.pb.go @@ -17,7 +17,7 @@ package article import proto "github.com/golang/protobuf/proto" import fmt "fmt" import math "math" -import common "github.com/moul/protoc-gen-gotemplate/examples/import/output/models/common" +import common "moul.io/protoc-gen-gotemplate/examples/import/output/models/common" // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal diff --git a/examples/import/output/output.go b/examples/import/output/output.go index 4911f1a..b51b6d0 100644 --- a/examples/import/output/output.go +++ b/examples/import/output/output.go @@ -2,8 +2,8 @@ package company import ( - "github.com/moul/protoc-gen-gotemplate/examples/import/output/models/article" - "github.com/moul/protoc-gen-gotemplate/examples/import/output/models/common" + "moul.io/protoc-gen-gotemplate/examples/import/output/models/article" + "moul.io/protoc-gen-gotemplate/examples/import/output/models/common" ) type Repository interface { @@ -37,4 +37,4 @@ func (sdk *Sdk) GetArticle(ctx context.Context, } - \ No newline at end of file + diff --git a/examples/import/templates/output.go.tmpl b/examples/import/templates/output.go.tmpl index c055713..219a3cd 100644 --- a/examples/import/templates/output.go.tmpl +++ b/examples/import/templates/output.go.tmpl @@ -3,8 +3,8 @@ package {{.File.Package}} import ( - "github.com/moul/protoc-gen-gotemplate/examples/import/output/models/article" - "github.com/moul/protoc-gen-gotemplate/examples/import/output/models/common" + "moul.io/protoc-gen-gotemplate/examples/import/output/models/article" + "moul.io/protoc-gen-gotemplate/examples/import/output/models/common" ) type Repository interface { @@ -38,4 +38,4 @@ func (sdk *Sdk) {{$m.Name}}(ctx context.Context, {{if $t.OneofDecl}} req *{{$pkg } {{end}} {{/* streaming ifs */}} -{{end}}{{end}} {{/* range with */}} \ No newline at end of file +{{end}}{{end}} {{/* range with */}} diff --git a/examples/single-package-mode/Makefile b/examples/single-package-mode/Makefile index a8ee603..d5df807 100644 --- a/examples/single-package-mode/Makefile +++ b/examples/single-package-mode/Makefile @@ -9,7 +9,7 @@ build: protoc -I./proto --go_out=plugins=grpc:output proto/aaa/aaa.proto protoc -I./proto --go_out=plugins=grpc:output proto/bbb/bbb.proto @rm -rf output/aaa output/bbb - @mv output/github.com/moul/protoc-gen-gotemplate/examples/single-package-mode/output/* output/ + @mv output/moul.io/protoc-gen-gotemplate/examples/single-package-mode/output/* output/ @rm -rf output/github.com @# protoc-gen-gotemplate diff --git a/examples/single-package-mode/output/bbb/bbb.pb.go b/examples/single-package-mode/output/bbb/bbb.pb.go index 4fa356c..333920f 100644 --- a/examples/single-package-mode/output/bbb/bbb.pb.go +++ b/examples/single-package-mode/output/bbb/bbb.pb.go @@ -17,7 +17,7 @@ package bbb import proto "github.com/golang/protobuf/proto" import fmt "fmt" import math "math" -import the_aaa_package "github.com/moul/protoc-gen-gotemplate/examples/single-package-mode/output/aaa" +import the_aaa_package "moul.io/protoc-gen-gotemplate/examples/single-package-mode/output/aaa" import ( context "golang.org/x/net/context" diff --git a/examples/single-package-mode/output/bbb/service.go b/examples/single-package-mode/output/bbb/service.go index 6f1e6b4..26a1995 100644 --- a/examples/single-package-mode/output/bbb/service.go +++ b/examples/single-package-mode/output/bbb/service.go @@ -4,7 +4,7 @@ package bbb import ( "fmt" - "github.com/moul/protoc-gen-gotemplate/examples/single-package-mode/output/aaa" + "moul.io/protoc-gen-gotemplate/examples/single-package-mode/output/aaa" "golang.org/x/net/context" ) diff --git a/examples/single-package-mode/proto/aaa/aaa.proto b/examples/single-package-mode/proto/aaa/aaa.proto index 2959414..2bc1230 100644 --- a/examples/single-package-mode/proto/aaa/aaa.proto +++ b/examples/single-package-mode/proto/aaa/aaa.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option go_package = "github.com/moul/protoc-gen-gotemplate/examples/single-package-mode/output/aaa"; +option go_package = "moul.io/protoc-gen-gotemplate/examples/single-package-mode/output/aaa"; package the.aaa.package; @@ -9,4 +9,4 @@ message AaaRequest { } message AaaReply { string error = 1; -} \ No newline at end of file +} diff --git a/examples/single-package-mode/proto/bbb/bbb.proto b/examples/single-package-mode/proto/bbb/bbb.proto index b41952f..2da408b 100644 --- a/examples/single-package-mode/proto/bbb/bbb.proto +++ b/examples/single-package-mode/proto/bbb/bbb.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package the.bbb.package; -option go_package = "github.com/moul/protoc-gen-gotemplate/examples/single-package-mode/output/bbb"; +option go_package = "moul.io/protoc-gen-gotemplate/examples/single-package-mode/output/bbb"; import "aaa/aaa.proto"; @@ -16,4 +16,4 @@ message BbbRequest { } message BbbReply { bool done = 1; -} \ No newline at end of file +} diff --git a/main.go b/main.go index 3014869..00a67a1 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,4 @@ -package main +package main // import "moul.io/protoc-gen-gotemplate" import ( "io/ioutil" @@ -11,7 +11,7 @@ import ( "github.com/golang/protobuf/protoc-gen-go/plugin" ggdescriptor "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor" - pgghelpers "github.com/moul/protoc-gen-gotemplate/helpers" + pgghelpers "moul.io/protoc-gen-gotemplate/helpers" ) var ( diff --git a/slides/README.md b/slides/README.md index f1ad91f..8fa2682 100644 --- a/slides/README.md +++ b/slides/README.md @@ -26,7 +26,7 @@ * the good old ./generate.sh bash script * go:generate * make -* protobuf + [protoc-gen-gotemplate](https://github.com/moul/protoc-gen-gotemplate) +* protobuf + [protoc-gen-gotemplate](https://moul.io/protoc-gen-gotemplate) --- @@ -69,7 +69,7 @@ package sessionsvc import ( "fmt" "golang.org/x/net/context" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" ) type Service struct{} @@ -94,8 +94,8 @@ package {{.File.Package}}_httptransport import ( gokit_endpoint "github.com/go-kit/kit/endpoint" httptransport "github.com/go-kit/kit/transport/http" - endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/endpoints" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/pb" + endpoints "moul.io/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/endpoints" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/pb" ) ``` @@ -105,8 +105,8 @@ package user_httptransport import ( gokit_endpoint "github.com/go-kit/kit/endpoint" httptransport "github.com/go-kit/kit/transport/http" - endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb" + endpoints "moul.io/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints" + pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb" ) ``` @@ -197,7 +197,7 @@ func RegisterHandlers(ctx context.Context, svc pb.UserServiceServer, mux *http.S # generation usages -* go-kit boilerplate (see [examples/go-kit](https://github.com/moul/protoc-gen-gotemplate/tree/master/examples/go-kit)) +* go-kit boilerplate (see [examples/go-kit](https://moul.io/protoc-gen-gotemplate/tree/master/examples/go-kit)) * k8s configuration * Dockerfile * documentation @@ -243,5 +243,5 @@ func RegisterHandlers(ctx context.Context, svc pb.UserServiceServer, mux *http.S # questions? -### github.com/moul/protoc-gen-gotemplate +### moul.io/protoc-gen-gotemplate ### @moul From 8b191e85f24678fbe75cb4356d7588d29846c4d0 Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Thu, 13 Sep 2018 01:54:44 +0200 Subject: [PATCH 2/2] chore: switch to go modules --- .gitignore | 2 + cmd/web-editor/main.go | 2 +- examples/go.mod | 0 go.mod | 27 + go.sum | 37 + .../github.com/Masterminds/sprig/.gitignore | 2 + vendor/github.com/dgrijalva/jwt-go/LICENSE | 8 - .../dgrijalva/jwt-go/MIGRATION_GUIDE.md | 96 - vendor/github.com/dgrijalva/jwt-go/README.md | 85 - .../dgrijalva/jwt-go/VERSION_HISTORY.md | 105 - vendor/github.com/dgrijalva/jwt-go/claims.go | 134 - vendor/github.com/dgrijalva/jwt-go/doc.go | 4 - vendor/github.com/dgrijalva/jwt-go/ecdsa.go | 147 - .../dgrijalva/jwt-go/ecdsa_utils.go | 67 - vendor/github.com/dgrijalva/jwt-go/errors.go | 63 - vendor/github.com/dgrijalva/jwt-go/hmac.go | 94 - .../github.com/dgrijalva/jwt-go/map_claims.go | 94 - vendor/github.com/dgrijalva/jwt-go/none.go | 52 - vendor/github.com/dgrijalva/jwt-go/parser.go | 131 - vendor/github.com/dgrijalva/jwt-go/rsa.go | 100 - vendor/github.com/dgrijalva/jwt-go/rsa_pss.go | 126 - .../github.com/dgrijalva/jwt-go/rsa_utils.go | 69 - .../dgrijalva/jwt-go/signing_method.go | 35 - vendor/github.com/dgrijalva/jwt-go/token.go | 108 - vendor/github.com/go-kit/kit/CONTRIBUTING.md | 18 - vendor/github.com/go-kit/kit/LICENSE | 22 - vendor/github.com/go-kit/kit/README.md | 117 - vendor/github.com/go-kit/kit/ROADMAP.md | 17 - .../github.com/go-kit/kit/auth/jwt/README.md | 122 - .../go-kit/kit/auth/jwt/middleware.go | 122 - .../go-kit/kit/auth/jwt/transport.go | 89 - vendor/github.com/go-kit/kit/coverage.bash | 47 - vendor/github.com/go-kit/kit/endpoint/doc.go | 5 - .../go-kit/kit/endpoint/endpoint.go | 28 - vendor/github.com/go-kit/kit/lint | 26 - vendor/github.com/go-kit/kit/log/README.md | 148 - vendor/github.com/go-kit/kit/log/doc.go | 93 - .../github.com/go-kit/kit/log/json_logger.go | 92 - vendor/github.com/go-kit/kit/log/log.go | 144 - .../go-kit/kit/log/logfmt_logger.go | 62 - .../github.com/go-kit/kit/log/nop_logger.go | 8 - vendor/github.com/go-kit/kit/log/stdlib.go | 116 - vendor/github.com/go-kit/kit/log/sync.go | 81 - vendor/github.com/go-kit/kit/log/value.go | 62 - .../go-kit/kit/transport/grpc/README.md | 37 - .../go-kit/kit/transport/grpc/client.go | 102 - .../go-kit/kit/transport/grpc/doc.go | 2 - .../kit/transport/grpc/encode_decode.go | 27 - .../transport/grpc/request_response_funcs.go | 53 - .../go-kit/kit/transport/grpc/server.go | 128 - .../go-kit/kit/transport/http/client.go | 115 - .../go-kit/kit/transport/http/doc.go | 2 - .../kit/transport/http/encode_decode.go | 31 - .../go-kit/kit/transport/http/err.go | 33 - .../transport/http/request_response_funcs.go | 45 - .../go-kit/kit/transport/http/server.go | 133 - vendor/github.com/go-kit/kit/update_deps.bash | 28 - vendor/github.com/go-logfmt/logfmt/LICENSE | 22 - vendor/github.com/go-logfmt/logfmt/README.md | 33 - vendor/github.com/go-logfmt/logfmt/decode.go | 237 - vendor/github.com/go-logfmt/logfmt/doc.go | 6 - vendor/github.com/go-logfmt/logfmt/encode.go | 321 - vendor/github.com/go-logfmt/logfmt/fuzz.go | 126 - .../github.com/go-logfmt/logfmt/jsonstring.go | 277 - vendor/github.com/go-stack/stack/LICENSE.md | 21 - vendor/github.com/go-stack/stack/README.md | 38 - vendor/github.com/go-stack/stack/stack.go | 349 - .../github.com/golang/protobuf/Make.protobuf | 40 - vendor/github.com/golang/protobuf/Makefile | 55 - vendor/github.com/golang/protobuf/README.md | 241 - .../protobuf/ptypes/timestamp/timestamp.pb.go | 127 - .../protobuf/ptypes/timestamp/timestamp.proto | 111 - .../grpc-ecosystem/grpc-gateway/CHANGELOG.md | 169 - .../grpc-gateway/CONTRIBUTING.md | 20 - .../grpc-ecosystem/grpc-gateway/Makefile | 143 - .../grpc-ecosystem/grpc-gateway/README.md | 245 - vendor/github.com/huandu/xstrings/.gitignore | 24 + vendor/github.com/kr/fs/LICENSE | 27 - vendor/github.com/kr/fs/Readme | 3 - vendor/github.com/kr/fs/filesystem.go | 36 - vendor/github.com/kr/fs/walk.go | 95 - vendor/github.com/kr/logfmt/Readme | 12 - vendor/github.com/kr/logfmt/decode.go | 184 - vendor/github.com/kr/logfmt/scanner.go | 149 - vendor/github.com/kr/logfmt/unquote.go | 149 - vendor/golang.org/x/crypto/CONTRIBUTING.md | 31 - vendor/golang.org/x/crypto/README | 3 - vendor/golang.org/x/crypto/codereview.cfg | 1 - vendor/golang.org/x/net/AUTHORS | 3 - vendor/golang.org/x/net/CONTRIBUTING.md | 31 - vendor/golang.org/x/net/CONTRIBUTORS | 3 - vendor/golang.org/x/net/LICENSE | 27 - vendor/golang.org/x/net/PATENTS | 22 - vendor/golang.org/x/net/README | 3 - vendor/golang.org/x/net/codereview.cfg | 1 - vendor/golang.org/x/net/context/context.go | 156 - .../x/net/context/ctxhttp/ctxhttp.go | 74 - .../x/net/context/ctxhttp/ctxhttp_pre17.go | 147 - vendor/golang.org/x/net/context/go17.go | 72 - vendor/golang.org/x/net/context/pre_go17.go | 300 - vendor/golang.org/x/net/http2/Dockerfile | 51 - vendor/golang.org/x/net/http2/Makefile | 3 - vendor/golang.org/x/net/http2/README | 20 - .../x/net/http2/client_conn_pool.go | 256 - .../x/net/http2/configure_transport.go | 80 - vendor/golang.org/x/net/http2/errors.go | 130 - vendor/golang.org/x/net/http2/fixed_buffer.go | 60 - vendor/golang.org/x/net/http2/flow.go | 50 - vendor/golang.org/x/net/http2/frame.go | 1544 ---- vendor/golang.org/x/net/http2/go16.go | 43 - vendor/golang.org/x/net/http2/go17.go | 106 - vendor/golang.org/x/net/http2/go17_not18.go | 36 - vendor/golang.org/x/net/http2/go18.go | 50 - vendor/golang.org/x/net/http2/gotrack.go | 170 - vendor/golang.org/x/net/http2/headermap.go | 78 - vendor/golang.org/x/net/http2/hpack/encode.go | 251 - vendor/golang.org/x/net/http2/hpack/hpack.go | 542 -- .../golang.org/x/net/http2/hpack/huffman.go | 212 - vendor/golang.org/x/net/http2/hpack/tables.go | 352 - vendor/golang.org/x/net/http2/http2.go | 387 - vendor/golang.org/x/net/http2/not_go16.go | 46 - vendor/golang.org/x/net/http2/not_go17.go | 87 - vendor/golang.org/x/net/http2/not_go18.go | 27 - vendor/golang.org/x/net/http2/pipe.go | 153 - vendor/golang.org/x/net/http2/server.go | 2753 ------ vendor/golang.org/x/net/http2/transport.go | 2129 ----- vendor/golang.org/x/net/http2/write.go | 370 - vendor/golang.org/x/net/http2/writesched.go | 242 - .../x/net/http2/writesched_priority.go | 452 - .../x/net/http2/writesched_random.go | 72 - vendor/golang.org/x/net/idna/idna.go | 508 -- vendor/golang.org/x/net/idna/punycode.go | 203 - vendor/golang.org/x/net/idna/tables.go | 4479 ---------- vendor/golang.org/x/net/idna/trie.go | 71 - vendor/golang.org/x/net/idna/trieval.go | 116 - .../x/net/internal/timeseries/timeseries.go | 525 -- .../golang.org/x/net/lex/httplex/httplex.go | 351 - vendor/golang.org/x/net/trace/events.go | 524 -- vendor/golang.org/x/net/trace/histogram.go | 356 - vendor/golang.org/x/net/trace/trace.go | 1071 --- vendor/golang.org/x/text/AUTHORS | 3 - vendor/golang.org/x/text/CONTRIBUTING.md | 31 - vendor/golang.org/x/text/CONTRIBUTORS | 3 - vendor/golang.org/x/text/LICENSE | 27 - vendor/golang.org/x/text/PATENTS | 22 - vendor/golang.org/x/text/README | 23 - vendor/golang.org/x/text/codereview.cfg | 1 - vendor/golang.org/x/text/doc.go | 13 - .../x/text/secure/bidirule/bidirule.go | 342 - .../golang.org/x/text/transform/transform.go | 705 -- vendor/golang.org/x/text/unicode/bidi/bidi.go | 198 - .../golang.org/x/text/unicode/bidi/bracket.go | 335 - vendor/golang.org/x/text/unicode/bidi/core.go | 1058 --- vendor/golang.org/x/text/unicode/bidi/prop.go | 206 - .../golang.org/x/text/unicode/bidi/tables.go | 1779 ---- .../golang.org/x/text/unicode/bidi/trieval.go | 60 - .../x/text/unicode/norm/composition.go | 514 -- .../x/text/unicode/norm/forminfo.go | 256 - .../golang.org/x/text/unicode/norm/input.go | 105 - vendor/golang.org/x/text/unicode/norm/iter.go | 450 - .../x/text/unicode/norm/normalize.go | 608 -- .../x/text/unicode/norm/readwriter.go | 125 - .../golang.org/x/text/unicode/norm/tables.go | 7627 ----------------- .../x/text/unicode/norm/transform.go | 88 - vendor/golang.org/x/text/unicode/norm/trie.go | 54 - .../genproto/CONTRIBUTING.md | 27 - vendor/google.golang.org/genproto/README.md | 28 - vendor/google.golang.org/genproto/regen.sh | 78 - vendor/google.golang.org/grpc/CONTRIBUTING.md | 46 - vendor/google.golang.org/grpc/LICENSE | 28 - vendor/google.golang.org/grpc/Makefile | 52 - vendor/google.golang.org/grpc/PATENTS | 22 - vendor/google.golang.org/grpc/README.md | 32 - vendor/google.golang.org/grpc/backoff.go | 80 - vendor/google.golang.org/grpc/balancer.go | 400 - vendor/google.golang.org/grpc/call.go | 232 - vendor/google.golang.org/grpc/clientconn.go | 888 -- vendor/google.golang.org/grpc/codegen.sh | 17 - .../grpc/codes/code_string.go | 16 - vendor/google.golang.org/grpc/codes/codes.go | 159 - vendor/google.golang.org/grpc/coverage.sh | 47 - .../grpc/credentials/credentials.go | 232 - .../grpc/credentials/credentials_util_go17.go | 76 - .../credentials/credentials_util_pre_go17.go | 74 - vendor/google.golang.org/grpc/doc.go | 6 - .../google.golang.org/grpc/grpclog/logger.go | 93 - vendor/google.golang.org/grpc/interceptor.go | 90 - .../grpc/internal/internal.go | 49 - .../grpc/metadata/metadata.go | 147 - .../google.golang.org/grpc/naming/naming.go | 74 - vendor/google.golang.org/grpc/peer/peer.go | 65 - vendor/google.golang.org/grpc/rpc_util.go | 457 - vendor/google.golang.org/grpc/server.go | 944 -- vendor/google.golang.org/grpc/stream.go | 526 -- vendor/google.golang.org/grpc/trace.go | 119 - .../grpc/transport/control.go | 215 - .../google.golang.org/grpc/transport/go16.go | 46 - .../google.golang.org/grpc/transport/go17.go | 46 - .../grpc/transport/handler_server.go | 397 - .../grpc/transport/http2_client.go | 1072 --- .../grpc/transport/http2_server.go | 775 -- .../grpc/transport/http_util.go | 513 -- .../grpc/transport/pre_go16.go | 51 - .../grpc/transport/transport.go | 595 -- vendor/modules.txt | 34 + vendor/vendor.json | 305 - 206 files changed, 127 insertions(+), 50492 deletions(-) create mode 100644 examples/go.mod create mode 100644 go.mod create mode 100644 go.sum create mode 100644 vendor/github.com/Masterminds/sprig/.gitignore delete mode 100644 vendor/github.com/dgrijalva/jwt-go/LICENSE delete mode 100644 vendor/github.com/dgrijalva/jwt-go/MIGRATION_GUIDE.md delete mode 100644 vendor/github.com/dgrijalva/jwt-go/README.md delete mode 100644 vendor/github.com/dgrijalva/jwt-go/VERSION_HISTORY.md delete mode 100644 vendor/github.com/dgrijalva/jwt-go/claims.go delete mode 100644 vendor/github.com/dgrijalva/jwt-go/doc.go delete mode 100644 vendor/github.com/dgrijalva/jwt-go/ecdsa.go delete mode 100644 vendor/github.com/dgrijalva/jwt-go/ecdsa_utils.go delete mode 100644 vendor/github.com/dgrijalva/jwt-go/errors.go delete mode 100644 vendor/github.com/dgrijalva/jwt-go/hmac.go delete mode 100644 vendor/github.com/dgrijalva/jwt-go/map_claims.go delete mode 100644 vendor/github.com/dgrijalva/jwt-go/none.go delete mode 100644 vendor/github.com/dgrijalva/jwt-go/parser.go delete mode 100644 vendor/github.com/dgrijalva/jwt-go/rsa.go delete mode 100644 vendor/github.com/dgrijalva/jwt-go/rsa_pss.go delete mode 100644 vendor/github.com/dgrijalva/jwt-go/rsa_utils.go delete mode 100644 vendor/github.com/dgrijalva/jwt-go/signing_method.go delete mode 100644 vendor/github.com/dgrijalva/jwt-go/token.go delete mode 100644 vendor/github.com/go-kit/kit/CONTRIBUTING.md delete mode 100644 vendor/github.com/go-kit/kit/LICENSE delete mode 100644 vendor/github.com/go-kit/kit/README.md delete mode 100644 vendor/github.com/go-kit/kit/ROADMAP.md delete mode 100644 vendor/github.com/go-kit/kit/auth/jwt/README.md delete mode 100644 vendor/github.com/go-kit/kit/auth/jwt/middleware.go delete mode 100644 vendor/github.com/go-kit/kit/auth/jwt/transport.go delete mode 100755 vendor/github.com/go-kit/kit/coverage.bash delete mode 100644 vendor/github.com/go-kit/kit/endpoint/doc.go delete mode 100644 vendor/github.com/go-kit/kit/endpoint/endpoint.go delete mode 100755 vendor/github.com/go-kit/kit/lint delete mode 100644 vendor/github.com/go-kit/kit/log/README.md delete mode 100644 vendor/github.com/go-kit/kit/log/doc.go delete mode 100644 vendor/github.com/go-kit/kit/log/json_logger.go delete mode 100644 vendor/github.com/go-kit/kit/log/log.go delete mode 100644 vendor/github.com/go-kit/kit/log/logfmt_logger.go delete mode 100644 vendor/github.com/go-kit/kit/log/nop_logger.go delete mode 100644 vendor/github.com/go-kit/kit/log/stdlib.go delete mode 100644 vendor/github.com/go-kit/kit/log/sync.go delete mode 100644 vendor/github.com/go-kit/kit/log/value.go delete mode 100644 vendor/github.com/go-kit/kit/transport/grpc/README.md delete mode 100644 vendor/github.com/go-kit/kit/transport/grpc/client.go delete mode 100644 vendor/github.com/go-kit/kit/transport/grpc/doc.go delete mode 100644 vendor/github.com/go-kit/kit/transport/grpc/encode_decode.go delete mode 100644 vendor/github.com/go-kit/kit/transport/grpc/request_response_funcs.go delete mode 100644 vendor/github.com/go-kit/kit/transport/grpc/server.go delete mode 100644 vendor/github.com/go-kit/kit/transport/http/client.go delete mode 100644 vendor/github.com/go-kit/kit/transport/http/doc.go delete mode 100644 vendor/github.com/go-kit/kit/transport/http/encode_decode.go delete mode 100644 vendor/github.com/go-kit/kit/transport/http/err.go delete mode 100644 vendor/github.com/go-kit/kit/transport/http/request_response_funcs.go delete mode 100644 vendor/github.com/go-kit/kit/transport/http/server.go delete mode 100755 vendor/github.com/go-kit/kit/update_deps.bash delete mode 100644 vendor/github.com/go-logfmt/logfmt/LICENSE delete mode 100644 vendor/github.com/go-logfmt/logfmt/README.md delete mode 100644 vendor/github.com/go-logfmt/logfmt/decode.go delete mode 100644 vendor/github.com/go-logfmt/logfmt/doc.go delete mode 100644 vendor/github.com/go-logfmt/logfmt/encode.go delete mode 100644 vendor/github.com/go-logfmt/logfmt/fuzz.go delete mode 100644 vendor/github.com/go-logfmt/logfmt/jsonstring.go delete mode 100644 vendor/github.com/go-stack/stack/LICENSE.md delete mode 100644 vendor/github.com/go-stack/stack/README.md delete mode 100644 vendor/github.com/go-stack/stack/stack.go delete mode 100644 vendor/github.com/golang/protobuf/Make.protobuf delete mode 100644 vendor/github.com/golang/protobuf/Makefile delete mode 100644 vendor/github.com/golang/protobuf/README.md delete mode 100644 vendor/github.com/golang/protobuf/ptypes/timestamp/timestamp.pb.go delete mode 100644 vendor/github.com/golang/protobuf/ptypes/timestamp/timestamp.proto delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/CHANGELOG.md delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/CONTRIBUTING.md delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/Makefile delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/README.md create mode 100644 vendor/github.com/huandu/xstrings/.gitignore delete mode 100644 vendor/github.com/kr/fs/LICENSE delete mode 100644 vendor/github.com/kr/fs/Readme delete mode 100644 vendor/github.com/kr/fs/filesystem.go delete mode 100644 vendor/github.com/kr/fs/walk.go delete mode 100644 vendor/github.com/kr/logfmt/Readme delete mode 100644 vendor/github.com/kr/logfmt/decode.go delete mode 100644 vendor/github.com/kr/logfmt/scanner.go delete mode 100644 vendor/github.com/kr/logfmt/unquote.go delete mode 100644 vendor/golang.org/x/crypto/CONTRIBUTING.md delete mode 100644 vendor/golang.org/x/crypto/README delete mode 100644 vendor/golang.org/x/crypto/codereview.cfg delete mode 100644 vendor/golang.org/x/net/AUTHORS delete mode 100644 vendor/golang.org/x/net/CONTRIBUTING.md delete mode 100644 vendor/golang.org/x/net/CONTRIBUTORS delete mode 100644 vendor/golang.org/x/net/LICENSE delete mode 100644 vendor/golang.org/x/net/PATENTS delete mode 100644 vendor/golang.org/x/net/README delete mode 100644 vendor/golang.org/x/net/codereview.cfg delete mode 100644 vendor/golang.org/x/net/context/context.go delete mode 100644 vendor/golang.org/x/net/context/ctxhttp/ctxhttp.go delete mode 100644 vendor/golang.org/x/net/context/ctxhttp/ctxhttp_pre17.go delete mode 100644 vendor/golang.org/x/net/context/go17.go delete mode 100644 vendor/golang.org/x/net/context/pre_go17.go delete mode 100644 vendor/golang.org/x/net/http2/Dockerfile delete mode 100644 vendor/golang.org/x/net/http2/Makefile delete mode 100644 vendor/golang.org/x/net/http2/README delete mode 100644 vendor/golang.org/x/net/http2/client_conn_pool.go delete mode 100644 vendor/golang.org/x/net/http2/configure_transport.go delete mode 100644 vendor/golang.org/x/net/http2/errors.go delete mode 100644 vendor/golang.org/x/net/http2/fixed_buffer.go delete mode 100644 vendor/golang.org/x/net/http2/flow.go delete mode 100644 vendor/golang.org/x/net/http2/frame.go delete mode 100644 vendor/golang.org/x/net/http2/go16.go delete mode 100644 vendor/golang.org/x/net/http2/go17.go delete mode 100644 vendor/golang.org/x/net/http2/go17_not18.go delete mode 100644 vendor/golang.org/x/net/http2/go18.go delete mode 100644 vendor/golang.org/x/net/http2/gotrack.go delete mode 100644 vendor/golang.org/x/net/http2/headermap.go delete mode 100644 vendor/golang.org/x/net/http2/hpack/encode.go delete mode 100644 vendor/golang.org/x/net/http2/hpack/hpack.go delete mode 100644 vendor/golang.org/x/net/http2/hpack/huffman.go delete mode 100644 vendor/golang.org/x/net/http2/hpack/tables.go delete mode 100644 vendor/golang.org/x/net/http2/http2.go delete mode 100644 vendor/golang.org/x/net/http2/not_go16.go delete mode 100644 vendor/golang.org/x/net/http2/not_go17.go delete mode 100644 vendor/golang.org/x/net/http2/not_go18.go delete mode 100644 vendor/golang.org/x/net/http2/pipe.go delete mode 100644 vendor/golang.org/x/net/http2/server.go delete mode 100644 vendor/golang.org/x/net/http2/transport.go delete mode 100644 vendor/golang.org/x/net/http2/write.go delete mode 100644 vendor/golang.org/x/net/http2/writesched.go delete mode 100644 vendor/golang.org/x/net/http2/writesched_priority.go delete mode 100644 vendor/golang.org/x/net/http2/writesched_random.go delete mode 100644 vendor/golang.org/x/net/idna/idna.go delete mode 100644 vendor/golang.org/x/net/idna/punycode.go delete mode 100644 vendor/golang.org/x/net/idna/tables.go delete mode 100644 vendor/golang.org/x/net/idna/trie.go delete mode 100644 vendor/golang.org/x/net/idna/trieval.go delete mode 100644 vendor/golang.org/x/net/internal/timeseries/timeseries.go delete mode 100644 vendor/golang.org/x/net/lex/httplex/httplex.go delete mode 100644 vendor/golang.org/x/net/trace/events.go delete mode 100644 vendor/golang.org/x/net/trace/histogram.go delete mode 100644 vendor/golang.org/x/net/trace/trace.go delete mode 100644 vendor/golang.org/x/text/AUTHORS delete mode 100644 vendor/golang.org/x/text/CONTRIBUTING.md delete mode 100644 vendor/golang.org/x/text/CONTRIBUTORS delete mode 100644 vendor/golang.org/x/text/LICENSE delete mode 100644 vendor/golang.org/x/text/PATENTS delete mode 100644 vendor/golang.org/x/text/README delete mode 100644 vendor/golang.org/x/text/codereview.cfg delete mode 100644 vendor/golang.org/x/text/doc.go delete mode 100644 vendor/golang.org/x/text/secure/bidirule/bidirule.go delete mode 100644 vendor/golang.org/x/text/transform/transform.go delete mode 100644 vendor/golang.org/x/text/unicode/bidi/bidi.go delete mode 100644 vendor/golang.org/x/text/unicode/bidi/bracket.go delete mode 100644 vendor/golang.org/x/text/unicode/bidi/core.go delete mode 100644 vendor/golang.org/x/text/unicode/bidi/prop.go delete mode 100644 vendor/golang.org/x/text/unicode/bidi/tables.go delete mode 100644 vendor/golang.org/x/text/unicode/bidi/trieval.go delete mode 100644 vendor/golang.org/x/text/unicode/norm/composition.go delete mode 100644 vendor/golang.org/x/text/unicode/norm/forminfo.go delete mode 100644 vendor/golang.org/x/text/unicode/norm/input.go delete mode 100644 vendor/golang.org/x/text/unicode/norm/iter.go delete mode 100644 vendor/golang.org/x/text/unicode/norm/normalize.go delete mode 100644 vendor/golang.org/x/text/unicode/norm/readwriter.go delete mode 100644 vendor/golang.org/x/text/unicode/norm/tables.go delete mode 100644 vendor/golang.org/x/text/unicode/norm/transform.go delete mode 100644 vendor/golang.org/x/text/unicode/norm/trie.go delete mode 100644 vendor/google.golang.org/genproto/CONTRIBUTING.md delete mode 100644 vendor/google.golang.org/genproto/README.md delete mode 100755 vendor/google.golang.org/genproto/regen.sh delete mode 100644 vendor/google.golang.org/grpc/CONTRIBUTING.md delete mode 100644 vendor/google.golang.org/grpc/LICENSE delete mode 100644 vendor/google.golang.org/grpc/Makefile delete mode 100644 vendor/google.golang.org/grpc/PATENTS delete mode 100644 vendor/google.golang.org/grpc/README.md delete mode 100644 vendor/google.golang.org/grpc/backoff.go delete mode 100644 vendor/google.golang.org/grpc/balancer.go delete mode 100644 vendor/google.golang.org/grpc/call.go delete mode 100644 vendor/google.golang.org/grpc/clientconn.go delete mode 100755 vendor/google.golang.org/grpc/codegen.sh delete mode 100644 vendor/google.golang.org/grpc/codes/code_string.go delete mode 100644 vendor/google.golang.org/grpc/codes/codes.go delete mode 100755 vendor/google.golang.org/grpc/coverage.sh delete mode 100644 vendor/google.golang.org/grpc/credentials/credentials.go delete mode 100644 vendor/google.golang.org/grpc/credentials/credentials_util_go17.go delete mode 100644 vendor/google.golang.org/grpc/credentials/credentials_util_pre_go17.go delete mode 100644 vendor/google.golang.org/grpc/doc.go delete mode 100644 vendor/google.golang.org/grpc/grpclog/logger.go delete mode 100644 vendor/google.golang.org/grpc/interceptor.go delete mode 100644 vendor/google.golang.org/grpc/internal/internal.go delete mode 100644 vendor/google.golang.org/grpc/metadata/metadata.go delete mode 100644 vendor/google.golang.org/grpc/naming/naming.go delete mode 100644 vendor/google.golang.org/grpc/peer/peer.go delete mode 100644 vendor/google.golang.org/grpc/rpc_util.go delete mode 100644 vendor/google.golang.org/grpc/server.go delete mode 100644 vendor/google.golang.org/grpc/stream.go delete mode 100644 vendor/google.golang.org/grpc/trace.go delete mode 100644 vendor/google.golang.org/grpc/transport/control.go delete mode 100644 vendor/google.golang.org/grpc/transport/go16.go delete mode 100644 vendor/google.golang.org/grpc/transport/go17.go delete mode 100644 vendor/google.golang.org/grpc/transport/handler_server.go delete mode 100644 vendor/google.golang.org/grpc/transport/http2_client.go delete mode 100644 vendor/google.golang.org/grpc/transport/http2_server.go delete mode 100644 vendor/google.golang.org/grpc/transport/http_util.go delete mode 100644 vendor/google.golang.org/grpc/transport/pre_go16.go delete mode 100644 vendor/google.golang.org/grpc/transport/transport.go create mode 100644 vendor/modules.txt delete mode 100644 vendor/vendor.json diff --git a/.gitignore b/.gitignore index a07ca9c..7d416d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +vendor/**/.travis.yml + /protoc-gen-gotemplate # Compiled Object files, Static and Dynamic libs (Shared Objects) diff --git a/cmd/web-editor/main.go b/cmd/web-editor/main.go index 1531080..7169819 100644 --- a/cmd/web-editor/main.go +++ b/cmd/web-editor/main.go @@ -57,7 +57,7 @@ func generate(w http.ResponseWriter, r *http.Request) { } // read output - content, err := ioutil.ReadFile(filepath.Join(dir, "example.output")) + content, err := ioutil.ReadFile(filepath.Join(dir, "example.output")) // #nosec if err != nil { returnError(w, err) return diff --git a/examples/go.mod b/examples/go.mod new file mode 100644 index 0000000..e69de29 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..52bdf05 --- /dev/null +++ b/go.mod @@ -0,0 +1,27 @@ +module moul.io/protoc-gen-gotemplate + +require ( + github.com/Masterminds/semver v1.2.2 // indirect + github.com/Masterminds/sprig v2.14.1+incompatible + github.com/aokoli/goutils v0.0.0-20170502144750-e57d01ace047 // indirect + github.com/dgrijalva/jwt-go v0.0.0-20160621201154-c9eaceb2896d // indirect + github.com/go-kit/kit v0.0.0-20161109000648-9f5c614cd1e7 // indirect + github.com/go-logfmt/logfmt v0.3.0 // indirect + github.com/go-stack/stack v1.5.3 // indirect + github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect + github.com/golang/protobuf v0.0.0-20161117033126-8ee79997227b + github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f // indirect + github.com/gorilla/handlers v0.0.0-20161028133215-e1b2144f2167 + github.com/gorilla/mux v1.5.0 + github.com/grpc-ecosystem/grpc-gateway v1.2.2 + github.com/huandu/xstrings v0.0.0-20151130125119-3959339b3335 + github.com/imdario/mergo v0.0.0-20171009183408-7fe0c75c13ab // indirect + github.com/kr/fs v0.0.0-20131111012553-2788f0dbd169 // indirect + github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 // indirect + github.com/satori/go.uuid v1.1.0 // indirect + golang.org/x/crypto v0.0.0-20170516161655-0fe963104e9d // indirect + golang.org/x/net v0.0.0-20170108160505-da2b4fa28524 // indirect + golang.org/x/text v0.0.0-20161216064924-a49bea13b776 // indirect + google.golang.org/genproto v0.0.0-20170517234824-bb3573be0c48 + google.golang.org/grpc v1.0.4 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..3c7ed36 --- /dev/null +++ b/go.sum @@ -0,0 +1,37 @@ +github.com/Masterminds/semver v1.2.2 h1:ptelpryog9A0pR4TGFvIAvw2c8SaNrYkFtfrxhSviss= +github.com/Masterminds/semver v1.2.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= +github.com/Masterminds/sprig v2.14.1+incompatible h1:rTHERm50Xp1Cbb8x7xBCeDp//jMMqqR44EWw7KwSXUQ= +github.com/Masterminds/sprig v2.14.1+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= +github.com/aokoli/goutils v0.0.0-20170502144750-e57d01ace047 h1:Bn0iqJ/349f606hR0juIGyheAI6+hyg9XUOLhN9udLo= +github.com/aokoli/goutils v0.0.0-20170502144750-e57d01ace047/go.mod h1:SijmP0QR8LtwsmDs8Yii5Z/S4trXFGFC2oO5g9DP+DQ= +github.com/dgrijalva/jwt-go v0.0.0-20160621201154-c9eaceb2896d/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/go-kit/kit v0.0.0-20161109000648-9f5c614cd1e7/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-stack/stack v1.5.3/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/protobuf v0.0.0-20161117033126-8ee79997227b h1:fE/yi9pibxGEc0gSJuEShcsBXE2d5FW3OudsjE9tKzQ= +github.com/golang/protobuf v0.0.0-20161117033126-8ee79997227b/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f h1:9oNbS1z4rVpbnkHBdPZU4jo9bSmrLpII768arSyMFgk= +github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= +github.com/gorilla/handlers v0.0.0-20161028133215-e1b2144f2167 h1:uANqGlSIT3JwuQVokEBcvc9WAu5+v4cVD5szF5k+iIU= +github.com/gorilla/handlers v0.0.0-20161028133215-e1b2144f2167/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= +github.com/gorilla/mux v1.5.0 h1:mq8bRov+5x+pZNR/uAHyUEgovR9gLgYFwDQIeuYi9TM= +github.com/gorilla/mux v1.5.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/grpc-ecosystem/grpc-gateway v1.2.2 h1:oR2ZMoJtQccW6NIJ9yFxRqAr2rkmcNsCaZKT66A9zt4= +github.com/grpc-ecosystem/grpc-gateway v1.2.2/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= +github.com/huandu/xstrings v0.0.0-20151130125119-3959339b3335 h1:KZOP9q7J/P4eMBibPuVwuloXgd2dTbLAHRPqxw7NXOw= +github.com/huandu/xstrings v0.0.0-20151130125119-3959339b3335/go.mod h1:4qWG/gcEcfX4z/mBDHJ++3ReCw9ibxbsNJbcucJdbSo= +github.com/imdario/mergo v0.0.0-20171009183408-7fe0c75c13ab h1:k/Biv+LJL35wkk0Hveko1nj7as4tSHkHdZaNlzn/gcQ= +github.com/imdario/mergo v0.0.0-20171009183408-7fe0c75c13ab/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/kr/fs v0.0.0-20131111012553-2788f0dbd169/go.mod h1:glhvuHOU9Hy7/8PwwdtnarXqLagOX0b/TbZx2zLMqEg= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/satori/go.uuid v1.1.0 h1:B9KXyj+GzIpJbV7gmr873NsY6zpbxNy24CBtGrk7jHo= +github.com/satori/go.uuid v1.1.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +golang.org/x/crypto v0.0.0-20170516161655-0fe963104e9d h1:qjfFh1YMn6m60QTGoG+IlwUMhNlXJbDyCa6EkHM/N2w= +golang.org/x/crypto v0.0.0-20170516161655-0fe963104e9d/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/net v0.0.0-20170108160505-da2b4fa28524/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/text v0.0.0-20161216064924-a49bea13b776/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +google.golang.org/genproto v0.0.0-20170517234824-bb3573be0c48 h1:xfoW+Di7qQQUnjptcGb4/rpc701e3RvfNmaywfMxQVI= +google.golang.org/genproto v0.0.0-20170517234824-bb3573be0c48/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/grpc v1.0.4/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= diff --git a/vendor/github.com/Masterminds/sprig/.gitignore b/vendor/github.com/Masterminds/sprig/.gitignore new file mode 100644 index 0000000..5e3002f --- /dev/null +++ b/vendor/github.com/Masterminds/sprig/.gitignore @@ -0,0 +1,2 @@ +vendor/ +/.glide diff --git a/vendor/github.com/dgrijalva/jwt-go/LICENSE b/vendor/github.com/dgrijalva/jwt-go/LICENSE deleted file mode 100644 index df83a9c..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/LICENSE +++ /dev/null @@ -1,8 +0,0 @@ -Copyright (c) 2012 Dave Grijalva - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/vendor/github.com/dgrijalva/jwt-go/MIGRATION_GUIDE.md b/vendor/github.com/dgrijalva/jwt-go/MIGRATION_GUIDE.md deleted file mode 100644 index fd62e94..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/MIGRATION_GUIDE.md +++ /dev/null @@ -1,96 +0,0 @@ -## Migration Guide from v2 -> v3 - -Version 3 adds several new, frequently requested features. To do so, it introduces a few breaking changes. We've worked to keep these as minimal as possible. This guide explains the breaking changes and how you can quickly update your code. - -### `Token.Claims` is now an interface type - -The most requested feature from the 2.0 verison of this library was the ability to provide a custom type to the JSON parser for claims. This was implemented by introducing a new interface, `Claims`, to replace `map[string]interface{}`. We also included two concrete implementations of `Claims`: `MapClaims` and `StandardClaims`. - -`MapClaims` is an alias for `map[string]interface{}` with built in validation behavior. It is the default claims type when using `Parse`. The usage is unchanged except you must type cast the claims property. - -The old example for parsing a token looked like this.. - -```go - if token, err := jwt.Parse(tokenString, keyLookupFunc); err == nil { - fmt.Printf("Token for user %v expires %v", token.Claims["user"], token.Claims["exp"]) - } -``` - -is now directly mapped to... - -```go - if token, err := jwt.Parse(tokenString, keyLookupFunc); err == nil { - claims := token.Claims.(jwt.MapClaims) - fmt.Printf("Token for user %v expires %v", claims["user"], claims["exp"]) - } -``` - -`StandardClaims` is designed to be embedded in your custom type. You can supply a custom claims type with the new `ParseWithClaims` function. Here's an example of using a custom claims type. - -```go - type MyCustomClaims struct { - User string - *StandardClaims - } - - if token, err := jwt.ParseWithClaims(tokenString, &MyCustomClaims{}, keyLookupFunc); err == nil { - claims := token.Claims.(*MyCustomClaims) - fmt.Printf("Token for user %v expires %v", claims.User, claims.StandardClaims.ExpiresAt) - } -``` - -### `ParseFromRequest` has been moved - -To keep this library focused on the tokens without becoming overburdened with complex request processing logic, `ParseFromRequest` and its new companion `ParseFromRequestWithClaims` have been moved to a subpackage, `request`. The method signatues have also been augmented to receive a new argument: `Extractor`. - -`Extractors` do the work of picking the token string out of a request. The interface is simple and composable. - -This simple parsing example: - -```go - if token, err := jwt.ParseFromRequest(tokenString, req, keyLookupFunc); err == nil { - fmt.Printf("Token for user %v expires %v", token.Claims["user"], token.Claims["exp"]) - } -``` - -is directly mapped to: - -```go - if token, err := request.ParseFromRequest(tokenString, request.OAuth2Extractor, req, keyLookupFunc); err == nil { - fmt.Printf("Token for user %v expires %v", token.Claims["user"], token.Claims["exp"]) - } -``` - -There are several concrete `Extractor` types provided for your convenience: - -* `HeaderExtractor` will search a list of headers until one contains content. -* `ArgumentExtractor` will search a list of keys in request query and form arguments until one contains content. -* `MultiExtractor` will try a list of `Extractors` in order until one returns content. -* `AuthorizationHeaderExtractor` will look in the `Authorization` header for a `Bearer` token. -* `OAuth2Extractor` searches the places an OAuth2 token would be specified (per the spec): `Authorization` header and `access_token` argument -* `PostExtractionFilter` wraps an `Extractor`, allowing you to process the content before it's parsed. A simple example is stripping the `Bearer ` text from a header - - -### RSA signing methods no longer accept `[]byte` keys - -Due to a [critical vulnerability](https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/), we've decided the convenience of accepting `[]byte` instead of `rsa.PublicKey` or `rsa.PrivateKey` isn't worth the risk of misuse. - -To replace this behavior, we've added two helper methods: `ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error)` and `ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error)`. These are just simple helpers for unpacking PEM encoded PKCS1 and PKCS8 keys. If your keys are encoded any other way, all you need to do is convert them to the `crypto/rsa` package's types. - -```go - func keyLookupFunc(*Token) (interface{}, error) { - // Don't forget to validate the alg is what you expect: - if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok { - return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"]) - } - - // Look up key - key, err := lookupPublicKey(token.Header["kid"]) - if err != nil { - return nil, err - } - - // Unpack key from PEM encoded PKCS8 - return jwt.ParseRSAPublicKeyFromPEM(key) - } -``` diff --git a/vendor/github.com/dgrijalva/jwt-go/README.md b/vendor/github.com/dgrijalva/jwt-go/README.md deleted file mode 100644 index f48365f..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/README.md +++ /dev/null @@ -1,85 +0,0 @@ -A [go](http://www.golang.org) (or 'golang' for search engine friendliness) implementation of [JSON Web Tokens](http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html) - -[![Build Status](https://travis-ci.org/dgrijalva/jwt-go.svg?branch=master)](https://travis-ci.org/dgrijalva/jwt-go) - -**BREAKING CHANGES:*** Version 3.0.0 is here. It includes _a lot_ of changes including a few that break the API. We've tried to break as few things as possible, so there should just be a few type signature changes. A full list of breaking changes is available in `VERSION_HISTORY.md`. See `MIGRATION_GUIDE.md` for more information on updating your code. - -**NOTICE:** A vulnerability in JWT was [recently published](https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/). As this library doesn't force users to validate the `alg` is what they expected, it's possible your usage is effected. There will be an update soon to remedy this, and it will likey require backwards-incompatible changes to the API. In the short term, please make sure your implementation verifies the `alg` is what you expect. - - -## What the heck is a JWT? - -JWT.io has [a great introduction](https://jwt.io/introduction) to JSON Web Tokens. - -In short, it's a signed JSON object that does something useful (for example, authentication). It's commonly used for `Bearer` tokens in Oauth 2. A token is made of three parts, separated by `.`'s. The first two parts are JSON objects, that have been [base64url](http://tools.ietf.org/html/rfc4648) encoded. The last part is the signature, encoded the same way. - -The first part is called the header. It contains the necessary information for verifying the last part, the signature. For example, which encryption method was used for signing and what key was used. - -The part in the middle is the interesting bit. It's called the Claims and contains the actual stuff you care about. Refer to [the RFC](http://self-issued.info/docs/draft-jones-json-web-token.html) for information about reserved keys and the proper way to add your own. - -## What's in the box? - -This library supports the parsing and verification as well as the generation and signing of JWTs. Current supported signing algorithms are HMAC SHA, RSA, RSA-PSS, and ECDSA, though hooks are present for adding your own. - -## Examples - -See [the project documentation](https://godoc.org/github.com/dgrijalva/jwt-go) for examples of usage: - -* [Simple example of parsing and validating a token](https://godoc.org/github.com/dgrijalva/jwt-go#example-Parse--Hmac) -* [Simple example of building and signing a token](https://godoc.org/github.com/dgrijalva/jwt-go#example-New--Hmac) -* [Directory of Examples](https://godoc.org/github.com/dgrijalva/jwt-go#pkg-examples) - -## Extensions - -This library publishes all the necessary components for adding your own signing methods. Simply implement the `SigningMethod` interface and register a factory method using `RegisterSigningMethod`. - -Here's an example of an extension that integrates with the Google App Engine signing tools: https://github.com/someone1/gcp-jwt-go - -## Compliance - -This library was last reviewed to comply with [RTF 7519](http://www.rfc-editor.org/info/rfc7519) dated May 2015 with a few notable differences: - -* In order to protect against accidental use of [Unsecured JWTs](http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#UnsecuredJWT), tokens using `alg=none` will only be accepted if the constant `jwt.UnsafeAllowNoneSignatureType` is provided as the key. - -## Project Status & Versioning - -This library is considered production ready. Feedback and feature requests are appreciated. The API should be considered stable. There should be very few backwards-incompatible changes outside of major version updates (and only with good reason). - -This project uses [Semantic Versioning 2.0.0](http://semver.org). Accepted pull requests will land on `master`. Periodically, versions will be tagged from `master`. You can find all the releases on [the project releases page](https://github.com/dgrijalva/jwt-go/releases). - -While we try to make it obvious when we make breaking changes, there isn't a great mechanism for pushing announcements out to users. You may want to use this alternative package include: `gopkg.in/dgrijalva/jwt-go.v2`. It will do the right thing WRT semantic versioning. - -## Usage Tips - -### Signing vs Encryption - -A token is simply a JSON object that is signed by its author. this tells you exactly two things about the data: - -* The author of the token was in the possession of the signing secret -* The data has not been modified since it was signed - -It's important to know that JWT does not provide encryption, which means anyone who has access to the token can read its contents. If you need to protect (encrypt) the data, there is a companion spec, `JWE`, that provides this functionality. JWE is currently outside the scope of this library. - -### Choosing a Signing Method - -There are several signing methods available, and you should probably take the time to learn about the various options before choosing one. The principal design decision is most likely going to be symmetric vs asymmetric. - -Symmetric signing methods, such as HSA, use only a single secret. This is probably the simplest signing method to use since any `[]byte` can be used as a valid secret. They are also slightly computationally faster to use, though this rarely is enough to matter. Symmetric signing methods work the best when both producers and consumers of tokens are trusted, or even the same system. Since the same secret is used to both sign and validate tokens, you can't easily distribute the key for validation. - -Asymmetric signing methods, such as RSA, use different keys for signing and verifying tokens. This makes it possible to produce tokens with a private key, and allow any consumer to access the public key for verification. - -### JWT and OAuth - -It's worth mentioning that OAuth and JWT are not the same thing. A JWT token is simply a signed JSON object. It can be used anywhere such a thing is useful. There is some confusion, though, as JWT is the most common type of bearer token used in OAuth2 authentication. - -Without going too far down the rabbit hole, here's a description of the interaction of these technologies: - -* OAuth is a protocol for allowing an identity provider to be separate from the service a user is logging in to. For example, whenever you use Facebook to log into a different service (Yelp, Spotify, etc), you are using OAuth. -* OAuth defines several options for passing around authentication data. One popular method is called a "bearer token". A bearer token is simply a string that _should_ only be held by an authenticated user. Thus, simply presenting this token proves your identity. You can probably derive from here why a JWT might make a good bearer token. -* Because bearer tokens are used for authentication, it's important they're kept secret. This is why transactions that use bearer tokens typically happen over SSL. - -## More - -Documentation can be found [on godoc.org](http://godoc.org/github.com/dgrijalva/jwt-go). - -The command line utility included in this project (cmd/jwt) provides a straightforward example of token creation and parsing as well as a useful tool for debugging your own integration. You'll also find several implementation examples in to documentation. diff --git a/vendor/github.com/dgrijalva/jwt-go/VERSION_HISTORY.md b/vendor/github.com/dgrijalva/jwt-go/VERSION_HISTORY.md deleted file mode 100644 index b605b45..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/VERSION_HISTORY.md +++ /dev/null @@ -1,105 +0,0 @@ -## `jwt-go` Version History - -#### 3.0.0 - -* **Compatibility Breaking Changes**: See MIGRATION_GUIDE.md for tips on updating your code - * Dropped support for `[]byte` keys when using RSA signing methods. This convenience feature could contribute to security vulnerabilities involving mismatched key types with signing methods. - * `ParseFromRequest` has been moved to `request` subpackage and usage has changed - * The `Claims` property on `Token` is now type `Claims` instead of `map[string]interface{}`. The default value is type `MapClaims`, which is an alias to `map[string]interface{}`. This makes it possible to use a custom type when decoding claims. -* Other Additions and Changes - * Added `Claims` interface type to allow users to decode the claims into a custom type - * Added `ParseWithClaims`, which takes a third argument of type `Claims`. Use this function instead of `Parse` if you have a custom type you'd like to decode into. - * Dramatically improved the functionality and flexibility of `ParseFromRequest`, which is now in the `request` subpackage - * Added `ParseFromRequestWithClaims` which is the `FromRequest` equivalent of `ParseWithClaims` - * Added new interface type `Extractor`, which is used for extracting JWT strings from http requests. Used with `ParseFromRequest` and `ParseFromRequestWithClaims`. - * Added several new, more specific, validation errors to error type bitmask - * Moved examples from README to executable example files - * Signing method registry is now thread safe - * Added new property to `ValidationError`, which contains the raw error returned by calls made by parse/verify (such as those returned by keyfunc or json parser) - -#### 2.7.0 - -This will likely be the last backwards compatible release before 3.0.0, excluding essential bug fixes. - -* Added new option `-show` to the `jwt` command that will just output the decoded token without verifying -* Error text for expired tokens includes how long it's been expired -* Fixed incorrect error returned from `ParseRSAPublicKeyFromPEM` -* Documentation updates - -#### 2.6.0 - -* Exposed inner error within ValidationError -* Fixed validation errors when using UseJSONNumber flag -* Added several unit tests - -#### 2.5.0 - -* Added support for signing method none. You shouldn't use this. The API tries to make this clear. -* Updated/fixed some documentation -* Added more helpful error message when trying to parse tokens that begin with `BEARER ` - -#### 2.4.0 - -* Added new type, Parser, to allow for configuration of various parsing parameters - * You can now specify a list of valid signing methods. Anything outside this set will be rejected. - * You can now opt to use the `json.Number` type instead of `float64` when parsing token JSON -* Added support for [Travis CI](https://travis-ci.org/dgrijalva/jwt-go) -* Fixed some bugs with ECDSA parsing - -#### 2.3.0 - -* Added support for ECDSA signing methods -* Added support for RSA PSS signing methods (requires go v1.4) - -#### 2.2.0 - -* Gracefully handle a `nil` `Keyfunc` being passed to `Parse`. Result will now be the parsed token and an error, instead of a panic. - -#### 2.1.0 - -Backwards compatible API change that was missed in 2.0.0. - -* The `SignedString` method on `Token` now takes `interface{}` instead of `[]byte` - -#### 2.0.0 - -There were two major reasons for breaking backwards compatibility with this update. The first was a refactor required to expand the width of the RSA and HMAC-SHA signing implementations. There will likely be no required code changes to support this change. - -The second update, while unfortunately requiring a small change in integration, is required to open up this library to other signing methods. Not all keys used for all signing methods have a single standard on-disk representation. Requiring `[]byte` as the type for all keys proved too limiting. Additionally, this implementation allows for pre-parsed tokens to be reused, which might matter in an application that parses a high volume of tokens with a small set of keys. Backwards compatibilty has been maintained for passing `[]byte` to the RSA signing methods, but they will also accept `*rsa.PublicKey` and `*rsa.PrivateKey`. - -It is likely the only integration change required here will be to change `func(t *jwt.Token) ([]byte, error)` to `func(t *jwt.Token) (interface{}, error)` when calling `Parse`. - -* **Compatibility Breaking Changes** - * `SigningMethodHS256` is now `*SigningMethodHMAC` instead of `type struct` - * `SigningMethodRS256` is now `*SigningMethodRSA` instead of `type struct` - * `KeyFunc` now returns `interface{}` instead of `[]byte` - * `SigningMethod.Sign` now takes `interface{}` instead of `[]byte` for the key - * `SigningMethod.Verify` now takes `interface{}` instead of `[]byte` for the key -* Renamed type `SigningMethodHS256` to `SigningMethodHMAC`. Specific sizes are now just instances of this type. - * Added public package global `SigningMethodHS256` - * Added public package global `SigningMethodHS384` - * Added public package global `SigningMethodHS512` -* Renamed type `SigningMethodRS256` to `SigningMethodRSA`. Specific sizes are now just instances of this type. - * Added public package global `SigningMethodRS256` - * Added public package global `SigningMethodRS384` - * Added public package global `SigningMethodRS512` -* Moved sample private key for HMAC tests from an inline value to a file on disk. Value is unchanged. -* Refactored the RSA implementation to be easier to read -* Exposed helper methods `ParseRSAPrivateKeyFromPEM` and `ParseRSAPublicKeyFromPEM` - -#### 1.0.2 - -* Fixed bug in parsing public keys from certificates -* Added more tests around the parsing of keys for RS256 -* Code refactoring in RS256 implementation. No functional changes - -#### 1.0.1 - -* Fixed panic if RS256 signing method was passed an invalid key - -#### 1.0.0 - -* First versioned release -* API stabilized -* Supports creating, signing, parsing, and validating JWT tokens -* Supports RS256 and HS256 signing methods \ No newline at end of file diff --git a/vendor/github.com/dgrijalva/jwt-go/claims.go b/vendor/github.com/dgrijalva/jwt-go/claims.go deleted file mode 100644 index f0228f0..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/claims.go +++ /dev/null @@ -1,134 +0,0 @@ -package jwt - -import ( - "crypto/subtle" - "fmt" - "time" -) - -// For a type to be a Claims object, it must just have a Valid method that determines -// if the token is invalid for any supported reason -type Claims interface { - Valid() error -} - -// Structured version of Claims Section, as referenced at -// https://tools.ietf.org/html/rfc7519#section-4.1 -// See examples for how to use this with your own claim types -type StandardClaims struct { - Audience string `json:"aud,omitempty"` - ExpiresAt int64 `json:"exp,omitempty"` - Id string `json:"jti,omitempty"` - IssuedAt int64 `json:"iat,omitempty"` - Issuer string `json:"iss,omitempty"` - NotBefore int64 `json:"nbf,omitempty"` - Subject string `json:"sub,omitempty"` -} - -// Validates time based claims "exp, iat, nbf". -// There is no accounting for clock skew. -// As well, if any of the above claims are not in the token, it will still -// be considered a valid claim. -func (c StandardClaims) Valid() error { - vErr := new(ValidationError) - now := TimeFunc().Unix() - - // The claims below are optional, by default, so if they are set to the - // default value in Go, let's not fail the verification for them. - if c.VerifyExpiresAt(now, false) == false { - delta := time.Unix(now, 0).Sub(time.Unix(c.ExpiresAt, 0)) - vErr.Inner = fmt.Errorf("token is expired by %v", delta) - vErr.Errors |= ValidationErrorExpired - } - - if c.VerifyIssuedAt(now, false) == false { - vErr.Inner = fmt.Errorf("Token used before issued") - vErr.Errors |= ValidationErrorIssuedAt - } - - if c.VerifyNotBefore(now, false) == false { - vErr.Inner = fmt.Errorf("token is not valid yet") - vErr.Errors |= ValidationErrorNotValidYet - } - - if vErr.valid() { - return nil - } - - return vErr -} - -// Compares the aud claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (c *StandardClaims) VerifyAudience(cmp string, req bool) bool { - return verifyAud(c.Audience, cmp, req) -} - -// Compares the exp claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (c *StandardClaims) VerifyExpiresAt(cmp int64, req bool) bool { - return verifyExp(c.ExpiresAt, cmp, req) -} - -// Compares the iat claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (c *StandardClaims) VerifyIssuedAt(cmp int64, req bool) bool { - return verifyIat(c.IssuedAt, cmp, req) -} - -// Compares the iss claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (c *StandardClaims) VerifyIssuer(cmp string, req bool) bool { - return verifyIss(c.Issuer, cmp, req) -} - -// Compares the nbf claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (c *StandardClaims) VerifyNotBefore(cmp int64, req bool) bool { - return verifyNbf(c.NotBefore, cmp, req) -} - -// ----- helpers - -func verifyAud(aud string, cmp string, required bool) bool { - if aud == "" { - return !required - } - if subtle.ConstantTimeCompare([]byte(aud), []byte(cmp)) != 0 { - return true - } else { - return false - } -} - -func verifyExp(exp int64, now int64, required bool) bool { - if exp == 0 { - return !required - } - return now <= exp -} - -func verifyIat(iat int64, now int64, required bool) bool { - if iat == 0 { - return !required - } - return now >= iat -} - -func verifyIss(iss string, cmp string, required bool) bool { - if iss == "" { - return !required - } - if subtle.ConstantTimeCompare([]byte(iss), []byte(cmp)) != 0 { - return true - } else { - return false - } -} - -func verifyNbf(nbf int64, now int64, required bool) bool { - if nbf == 0 { - return !required - } - return now >= nbf -} diff --git a/vendor/github.com/dgrijalva/jwt-go/doc.go b/vendor/github.com/dgrijalva/jwt-go/doc.go deleted file mode 100644 index a86dc1a..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/doc.go +++ /dev/null @@ -1,4 +0,0 @@ -// Package jwt is a Go implementation of JSON Web Tokens: http://self-issued.info/docs/draft-jones-json-web-token.html -// -// See README.md for more info. -package jwt diff --git a/vendor/github.com/dgrijalva/jwt-go/ecdsa.go b/vendor/github.com/dgrijalva/jwt-go/ecdsa.go deleted file mode 100644 index 2f59a22..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/ecdsa.go +++ /dev/null @@ -1,147 +0,0 @@ -package jwt - -import ( - "crypto" - "crypto/ecdsa" - "crypto/rand" - "errors" - "math/big" -) - -var ( - // Sadly this is missing from crypto/ecdsa compared to crypto/rsa - ErrECDSAVerification = errors.New("crypto/ecdsa: verification error") -) - -// Implements the ECDSA family of signing methods signing methods -type SigningMethodECDSA struct { - Name string - Hash crypto.Hash - KeySize int - CurveBits int -} - -// Specific instances for EC256 and company -var ( - SigningMethodES256 *SigningMethodECDSA - SigningMethodES384 *SigningMethodECDSA - SigningMethodES512 *SigningMethodECDSA -) - -func init() { - // ES256 - SigningMethodES256 = &SigningMethodECDSA{"ES256", crypto.SHA256, 32, 256} - RegisterSigningMethod(SigningMethodES256.Alg(), func() SigningMethod { - return SigningMethodES256 - }) - - // ES384 - SigningMethodES384 = &SigningMethodECDSA{"ES384", crypto.SHA384, 48, 384} - RegisterSigningMethod(SigningMethodES384.Alg(), func() SigningMethod { - return SigningMethodES384 - }) - - // ES512 - SigningMethodES512 = &SigningMethodECDSA{"ES512", crypto.SHA512, 66, 521} - RegisterSigningMethod(SigningMethodES512.Alg(), func() SigningMethod { - return SigningMethodES512 - }) -} - -func (m *SigningMethodECDSA) Alg() string { - return m.Name -} - -// Implements the Verify method from SigningMethod -// For this verify method, key must be an ecdsa.PublicKey struct -func (m *SigningMethodECDSA) Verify(signingString, signature string, key interface{}) error { - var err error - - // Decode the signature - var sig []byte - if sig, err = DecodeSegment(signature); err != nil { - return err - } - - // Get the key - var ecdsaKey *ecdsa.PublicKey - switch k := key.(type) { - case *ecdsa.PublicKey: - ecdsaKey = k - default: - return ErrInvalidKeyType - } - - if len(sig) != 2*m.KeySize { - return ErrECDSAVerification - } - - r := big.NewInt(0).SetBytes(sig[:m.KeySize]) - s := big.NewInt(0).SetBytes(sig[m.KeySize:]) - - // Create hasher - if !m.Hash.Available() { - return ErrHashUnavailable - } - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - // Verify the signature - if verifystatus := ecdsa.Verify(ecdsaKey, hasher.Sum(nil), r, s); verifystatus == true { - return nil - } else { - return ErrECDSAVerification - } -} - -// Implements the Sign method from SigningMethod -// For this signing method, key must be an ecdsa.PrivateKey struct -func (m *SigningMethodECDSA) Sign(signingString string, key interface{}) (string, error) { - // Get the key - var ecdsaKey *ecdsa.PrivateKey - switch k := key.(type) { - case *ecdsa.PrivateKey: - ecdsaKey = k - default: - return "", ErrInvalidKeyType - } - - // Create the hasher - if !m.Hash.Available() { - return "", ErrHashUnavailable - } - - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - // Sign the string and return r, s - if r, s, err := ecdsa.Sign(rand.Reader, ecdsaKey, hasher.Sum(nil)); err == nil { - curveBits := ecdsaKey.Curve.Params().BitSize - - if m.CurveBits != curveBits { - return "", ErrInvalidKey - } - - keyBytes := curveBits / 8 - if curveBits%8 > 0 { - keyBytes += 1 - } - - // We serialize the outpus (r and s) into big-endian byte arrays and pad - // them with zeros on the left to make sure the sizes work out. Both arrays - // must be keyBytes long, and the output must be 2*keyBytes long. - rBytes := r.Bytes() - rBytesPadded := make([]byte, keyBytes) - copy(rBytesPadded[keyBytes-len(rBytes):], rBytes) - - sBytes := s.Bytes() - sBytesPadded := make([]byte, keyBytes) - copy(sBytesPadded[keyBytes-len(sBytes):], sBytes) - - out := append(rBytesPadded, sBytesPadded...) - - return EncodeSegment(out), nil - } else { - return "", err - } -} diff --git a/vendor/github.com/dgrijalva/jwt-go/ecdsa_utils.go b/vendor/github.com/dgrijalva/jwt-go/ecdsa_utils.go deleted file mode 100644 index d19624b..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/ecdsa_utils.go +++ /dev/null @@ -1,67 +0,0 @@ -package jwt - -import ( - "crypto/ecdsa" - "crypto/x509" - "encoding/pem" - "errors" -) - -var ( - ErrNotECPublicKey = errors.New("Key is not a valid ECDSA public key") - ErrNotECPrivateKey = errors.New("Key is not a valid ECDSA private key") -) - -// Parse PEM encoded Elliptic Curve Private Key Structure -func ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error) { - var err error - - // Parse PEM block - var block *pem.Block - if block, _ = pem.Decode(key); block == nil { - return nil, ErrKeyMustBePEMEncoded - } - - // Parse the key - var parsedKey interface{} - if parsedKey, err = x509.ParseECPrivateKey(block.Bytes); err != nil { - return nil, err - } - - var pkey *ecdsa.PrivateKey - var ok bool - if pkey, ok = parsedKey.(*ecdsa.PrivateKey); !ok { - return nil, ErrNotECPrivateKey - } - - return pkey, nil -} - -// Parse PEM encoded PKCS1 or PKCS8 public key -func ParseECPublicKeyFromPEM(key []byte) (*ecdsa.PublicKey, error) { - var err error - - // Parse PEM block - var block *pem.Block - if block, _ = pem.Decode(key); block == nil { - return nil, ErrKeyMustBePEMEncoded - } - - // Parse the key - var parsedKey interface{} - if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil { - if cert, err := x509.ParseCertificate(block.Bytes); err == nil { - parsedKey = cert.PublicKey - } else { - return nil, err - } - } - - var pkey *ecdsa.PublicKey - var ok bool - if pkey, ok = parsedKey.(*ecdsa.PublicKey); !ok { - return nil, ErrNotECPublicKey - } - - return pkey, nil -} diff --git a/vendor/github.com/dgrijalva/jwt-go/errors.go b/vendor/github.com/dgrijalva/jwt-go/errors.go deleted file mode 100644 index 662df19..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/errors.go +++ /dev/null @@ -1,63 +0,0 @@ -package jwt - -import ( - "errors" -) - -// Error constants -var ( - ErrInvalidKey = errors.New("key is invalid") - ErrInvalidKeyType = errors.New("key is of invalid type") - ErrHashUnavailable = errors.New("the requested hash function is unavailable") -) - -// The errors that might occur when parsing and validating a token -const ( - ValidationErrorMalformed uint32 = 1 << iota // Token is malformed - ValidationErrorUnverifiable // Token could not be verified because of signing problems - ValidationErrorSignatureInvalid // Signature validation failed - - // Standard Claim validation errors - ValidationErrorAudience // AUD validation failed - ValidationErrorExpired // EXP validation failed - ValidationErrorIssuedAt // IAT validation failed - ValidationErrorIssuer // ISS validation failed - ValidationErrorNotValidYet // NBF validation failed - ValidationErrorId // JTI validation failed - ValidationErrorClaimsInvalid // Generic claims validation error -) - -// Helper for constructing a ValidationError with a string error message -func NewValidationError(errorText string, errorFlags uint32) *ValidationError { - return &ValidationError{ - text: errorText, - Errors: errorFlags, - } -} - -// The error from Parse if token is not valid -type ValidationError struct { - Inner error // stores the error returned by external dependencies, i.e.: KeyFunc - Errors uint32 // bitfield. see ValidationError... constants - text string // errors that do not have a valid error just have text -} - -// Validation error is an error type -func (e ValidationError) Error() string { - if e.Inner != nil { - return e.Inner.Error() - } else if e.text != "" { - return e.text - } else { - return "token is invalid" - } - return e.Inner.Error() -} - -// No errors -func (e *ValidationError) valid() bool { - if e.Errors > 0 { - return false - } - return true -} diff --git a/vendor/github.com/dgrijalva/jwt-go/hmac.go b/vendor/github.com/dgrijalva/jwt-go/hmac.go deleted file mode 100644 index c229919..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/hmac.go +++ /dev/null @@ -1,94 +0,0 @@ -package jwt - -import ( - "crypto" - "crypto/hmac" - "errors" -) - -// Implements the HMAC-SHA family of signing methods signing methods -type SigningMethodHMAC struct { - Name string - Hash crypto.Hash -} - -// Specific instances for HS256 and company -var ( - SigningMethodHS256 *SigningMethodHMAC - SigningMethodHS384 *SigningMethodHMAC - SigningMethodHS512 *SigningMethodHMAC - ErrSignatureInvalid = errors.New("signature is invalid") -) - -func init() { - // HS256 - SigningMethodHS256 = &SigningMethodHMAC{"HS256", crypto.SHA256} - RegisterSigningMethod(SigningMethodHS256.Alg(), func() SigningMethod { - return SigningMethodHS256 - }) - - // HS384 - SigningMethodHS384 = &SigningMethodHMAC{"HS384", crypto.SHA384} - RegisterSigningMethod(SigningMethodHS384.Alg(), func() SigningMethod { - return SigningMethodHS384 - }) - - // HS512 - SigningMethodHS512 = &SigningMethodHMAC{"HS512", crypto.SHA512} - RegisterSigningMethod(SigningMethodHS512.Alg(), func() SigningMethod { - return SigningMethodHS512 - }) -} - -func (m *SigningMethodHMAC) Alg() string { - return m.Name -} - -// Verify the signature of HSXXX tokens. Returns nil if the signature is valid. -func (m *SigningMethodHMAC) Verify(signingString, signature string, key interface{}) error { - // Verify the key is the right type - keyBytes, ok := key.([]byte) - if !ok { - return ErrInvalidKeyType - } - - // Decode signature, for comparison - sig, err := DecodeSegment(signature) - if err != nil { - return err - } - - // Can we use the specified hashing method? - if !m.Hash.Available() { - return ErrHashUnavailable - } - - // This signing method is symmetric, so we validate the signature - // by reproducing the signature from the signing string and key, then - // comparing that against the provided signature. - hasher := hmac.New(m.Hash.New, keyBytes) - hasher.Write([]byte(signingString)) - if !hmac.Equal(sig, hasher.Sum(nil)) { - return ErrSignatureInvalid - } - - // No validation errors. Signature is good. - return nil -} - -// Implements the Sign method from SigningMethod for this signing method. -// Key must be []byte -func (m *SigningMethodHMAC) Sign(signingString string, key interface{}) (string, error) { - if keyBytes, ok := key.([]byte); ok { - if !m.Hash.Available() { - return "", ErrHashUnavailable - } - - hasher := hmac.New(m.Hash.New, keyBytes) - hasher.Write([]byte(signingString)) - - return EncodeSegment(hasher.Sum(nil)), nil - } - - return "", ErrInvalidKey -} diff --git a/vendor/github.com/dgrijalva/jwt-go/map_claims.go b/vendor/github.com/dgrijalva/jwt-go/map_claims.go deleted file mode 100644 index 291213c..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/map_claims.go +++ /dev/null @@ -1,94 +0,0 @@ -package jwt - -import ( - "encoding/json" - "errors" - // "fmt" -) - -// Claims type that uses the map[string]interface{} for JSON decoding -// This is the default claims type if you don't supply one -type MapClaims map[string]interface{} - -// Compares the aud claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (m MapClaims) VerifyAudience(cmp string, req bool) bool { - aud, _ := m["aud"].(string) - return verifyAud(aud, cmp, req) -} - -// Compares the exp claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (m MapClaims) VerifyExpiresAt(cmp int64, req bool) bool { - switch exp := m["exp"].(type) { - case float64: - return verifyExp(int64(exp), cmp, req) - case json.Number: - v, _ := exp.Int64() - return verifyExp(v, cmp, req) - } - return req == false -} - -// Compares the iat claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (m MapClaims) VerifyIssuedAt(cmp int64, req bool) bool { - switch iat := m["iat"].(type) { - case float64: - return verifyIat(int64(iat), cmp, req) - case json.Number: - v, _ := iat.Int64() - return verifyIat(v, cmp, req) - } - return req == false -} - -// Compares the iss claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (m MapClaims) VerifyIssuer(cmp string, req bool) bool { - iss, _ := m["iss"].(string) - return verifyIss(iss, cmp, req) -} - -// Compares the nbf claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (m MapClaims) VerifyNotBefore(cmp int64, req bool) bool { - switch nbf := m["nbf"].(type) { - case float64: - return verifyNbf(int64(nbf), cmp, req) - case json.Number: - v, _ := nbf.Int64() - return verifyNbf(v, cmp, req) - } - return req == false -} - -// Validates time based claims "exp, iat, nbf". -// There is no accounting for clock skew. -// As well, if any of the above claims are not in the token, it will still -// be considered a valid claim. -func (m MapClaims) Valid() error { - vErr := new(ValidationError) - now := TimeFunc().Unix() - - if m.VerifyExpiresAt(now, false) == false { - vErr.Inner = errors.New("Token is expired") - vErr.Errors |= ValidationErrorExpired - } - - if m.VerifyIssuedAt(now, false) == false { - vErr.Inner = errors.New("Token used before issued") - vErr.Errors |= ValidationErrorIssuedAt - } - - if m.VerifyNotBefore(now, false) == false { - vErr.Inner = errors.New("Token is not valid yet") - vErr.Errors |= ValidationErrorNotValidYet - } - - if vErr.valid() { - return nil - } - - return vErr -} diff --git a/vendor/github.com/dgrijalva/jwt-go/none.go b/vendor/github.com/dgrijalva/jwt-go/none.go deleted file mode 100644 index f04d189..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/none.go +++ /dev/null @@ -1,52 +0,0 @@ -package jwt - -// Implements the none signing method. This is required by the spec -// but you probably should never use it. -var SigningMethodNone *signingMethodNone - -const UnsafeAllowNoneSignatureType unsafeNoneMagicConstant = "none signing method allowed" - -var NoneSignatureTypeDisallowedError error - -type signingMethodNone struct{} -type unsafeNoneMagicConstant string - -func init() { - SigningMethodNone = &signingMethodNone{} - NoneSignatureTypeDisallowedError = NewValidationError("'none' signature type is not allowed", ValidationErrorSignatureInvalid) - - RegisterSigningMethod(SigningMethodNone.Alg(), func() SigningMethod { - return SigningMethodNone - }) -} - -func (m *signingMethodNone) Alg() string { - return "none" -} - -// Only allow 'none' alg type if UnsafeAllowNoneSignatureType is specified as the key -func (m *signingMethodNone) Verify(signingString, signature string, key interface{}) (err error) { - // Key must be UnsafeAllowNoneSignatureType to prevent accidentally - // accepting 'none' signing method - if _, ok := key.(unsafeNoneMagicConstant); !ok { - return NoneSignatureTypeDisallowedError - } - // If signing method is none, signature must be an empty string - if signature != "" { - return NewValidationError( - "'none' signing method with non-empty signature", - ValidationErrorSignatureInvalid, - ) - } - - // Accept 'none' signing method. - return nil -} - -// Only allow 'none' signing if UnsafeAllowNoneSignatureType is specified as the key -func (m *signingMethodNone) Sign(signingString string, key interface{}) (string, error) { - if _, ok := key.(unsafeNoneMagicConstant); ok { - return "", nil - } - return "", NoneSignatureTypeDisallowedError -} diff --git a/vendor/github.com/dgrijalva/jwt-go/parser.go b/vendor/github.com/dgrijalva/jwt-go/parser.go deleted file mode 100644 index 7bf1c4e..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/parser.go +++ /dev/null @@ -1,131 +0,0 @@ -package jwt - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" -) - -type Parser struct { - ValidMethods []string // If populated, only these methods will be considered valid - UseJSONNumber bool // Use JSON Number format in JSON decoder - SkipClaimsValidation bool // Skip claims validation during token parsing -} - -// Parse, validate, and return a token. -// keyFunc will receive the parsed token and should return the key for validating. -// If everything is kosher, err will be nil -func (p *Parser) Parse(tokenString string, keyFunc Keyfunc) (*Token, error) { - return p.ParseWithClaims(tokenString, MapClaims{}, keyFunc) -} - -func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc) (*Token, error) { - parts := strings.Split(tokenString, ".") - if len(parts) != 3 { - return nil, NewValidationError("token contains an invalid number of segments", ValidationErrorMalformed) - } - - var err error - token := &Token{Raw: tokenString} - - // parse Header - var headerBytes []byte - if headerBytes, err = DecodeSegment(parts[0]); err != nil { - if strings.HasPrefix(strings.ToLower(tokenString), "bearer ") { - return token, NewValidationError("tokenstring should not contain 'bearer '", ValidationErrorMalformed) - } - return token, &ValidationError{Inner: err, Errors: ValidationErrorMalformed} - } - if err = json.Unmarshal(headerBytes, &token.Header); err != nil { - return token, &ValidationError{Inner: err, Errors: ValidationErrorMalformed} - } - - // parse Claims - var claimBytes []byte - token.Claims = claims - - if claimBytes, err = DecodeSegment(parts[1]); err != nil { - return token, &ValidationError{Inner: err, Errors: ValidationErrorMalformed} - } - dec := json.NewDecoder(bytes.NewBuffer(claimBytes)) - if p.UseJSONNumber { - dec.UseNumber() - } - // JSON Decode. Special case for map type to avoid weird pointer behavior - if c, ok := token.Claims.(MapClaims); ok { - err = dec.Decode(&c) - } else { - err = dec.Decode(&claims) - } - // Handle decode error - if err != nil { - return token, &ValidationError{Inner: err, Errors: ValidationErrorMalformed} - } - - // Lookup signature method - if method, ok := token.Header["alg"].(string); ok { - if token.Method = GetSigningMethod(method); token.Method == nil { - return token, NewValidationError("signing method (alg) is unavailable.", ValidationErrorUnverifiable) - } - } else { - return token, NewValidationError("signing method (alg) is unspecified.", ValidationErrorUnverifiable) - } - - // Verify signing method is in the required set - if p.ValidMethods != nil { - var signingMethodValid = false - var alg = token.Method.Alg() - for _, m := range p.ValidMethods { - if m == alg { - signingMethodValid = true - break - } - } - if !signingMethodValid { - // signing method is not in the listed set - return token, NewValidationError(fmt.Sprintf("signing method %v is invalid", alg), ValidationErrorSignatureInvalid) - } - } - - // Lookup key - var key interface{} - if keyFunc == nil { - // keyFunc was not provided. short circuiting validation - return token, NewValidationError("no Keyfunc was provided.", ValidationErrorUnverifiable) - } - if key, err = keyFunc(token); err != nil { - // keyFunc returned an error - return token, &ValidationError{Inner: err, Errors: ValidationErrorUnverifiable} - } - - vErr := &ValidationError{} - - // Validate Claims - if !p.SkipClaimsValidation { - if err := token.Claims.Valid(); err != nil { - - // If the Claims Valid returned an error, check if it is a validation error, - // If it was another error type, create a ValidationError with a generic ClaimsInvalid flag set - if e, ok := err.(*ValidationError); !ok { - vErr = &ValidationError{Inner: err, Errors: ValidationErrorClaimsInvalid} - } else { - vErr = e - } - } - } - - // Perform validation - token.Signature = parts[2] - if err = token.Method.Verify(strings.Join(parts[0:2], "."), token.Signature, key); err != nil { - vErr.Inner = err - vErr.Errors |= ValidationErrorSignatureInvalid - } - - if vErr.valid() { - token.Valid = true - return token, nil - } - - return token, vErr -} diff --git a/vendor/github.com/dgrijalva/jwt-go/rsa.go b/vendor/github.com/dgrijalva/jwt-go/rsa.go deleted file mode 100644 index 0ae0b19..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/rsa.go +++ /dev/null @@ -1,100 +0,0 @@ -package jwt - -import ( - "crypto" - "crypto/rand" - "crypto/rsa" -) - -// Implements the RSA family of signing methods signing methods -type SigningMethodRSA struct { - Name string - Hash crypto.Hash -} - -// Specific instances for RS256 and company -var ( - SigningMethodRS256 *SigningMethodRSA - SigningMethodRS384 *SigningMethodRSA - SigningMethodRS512 *SigningMethodRSA -) - -func init() { - // RS256 - SigningMethodRS256 = &SigningMethodRSA{"RS256", crypto.SHA256} - RegisterSigningMethod(SigningMethodRS256.Alg(), func() SigningMethod { - return SigningMethodRS256 - }) - - // RS384 - SigningMethodRS384 = &SigningMethodRSA{"RS384", crypto.SHA384} - RegisterSigningMethod(SigningMethodRS384.Alg(), func() SigningMethod { - return SigningMethodRS384 - }) - - // RS512 - SigningMethodRS512 = &SigningMethodRSA{"RS512", crypto.SHA512} - RegisterSigningMethod(SigningMethodRS512.Alg(), func() SigningMethod { - return SigningMethodRS512 - }) -} - -func (m *SigningMethodRSA) Alg() string { - return m.Name -} - -// Implements the Verify method from SigningMethod -// For this signing method, must be an rsa.PublicKey structure. -func (m *SigningMethodRSA) Verify(signingString, signature string, key interface{}) error { - var err error - - // Decode the signature - var sig []byte - if sig, err = DecodeSegment(signature); err != nil { - return err - } - - var rsaKey *rsa.PublicKey - var ok bool - - if rsaKey, ok = key.(*rsa.PublicKey); !ok { - return ErrInvalidKeyType - } - - // Create hasher - if !m.Hash.Available() { - return ErrHashUnavailable - } - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - // Verify the signature - return rsa.VerifyPKCS1v15(rsaKey, m.Hash, hasher.Sum(nil), sig) -} - -// Implements the Sign method from SigningMethod -// For this signing method, must be an rsa.PrivateKey structure. -func (m *SigningMethodRSA) Sign(signingString string, key interface{}) (string, error) { - var rsaKey *rsa.PrivateKey - var ok bool - - // Validate type of key - if rsaKey, ok = key.(*rsa.PrivateKey); !ok { - return "", ErrInvalidKey - } - - // Create the hasher - if !m.Hash.Available() { - return "", ErrHashUnavailable - } - - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - // Sign the string and return the encoded bytes - if sigBytes, err := rsa.SignPKCS1v15(rand.Reader, rsaKey, m.Hash, hasher.Sum(nil)); err == nil { - return EncodeSegment(sigBytes), nil - } else { - return "", err - } -} diff --git a/vendor/github.com/dgrijalva/jwt-go/rsa_pss.go b/vendor/github.com/dgrijalva/jwt-go/rsa_pss.go deleted file mode 100644 index 10ee9db..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/rsa_pss.go +++ /dev/null @@ -1,126 +0,0 @@ -// +build go1.4 - -package jwt - -import ( - "crypto" - "crypto/rand" - "crypto/rsa" -) - -// Implements the RSAPSS family of signing methods signing methods -type SigningMethodRSAPSS struct { - *SigningMethodRSA - Options *rsa.PSSOptions -} - -// Specific instances for RS/PS and company -var ( - SigningMethodPS256 *SigningMethodRSAPSS - SigningMethodPS384 *SigningMethodRSAPSS - SigningMethodPS512 *SigningMethodRSAPSS -) - -func init() { - // PS256 - SigningMethodPS256 = &SigningMethodRSAPSS{ - &SigningMethodRSA{ - Name: "PS256", - Hash: crypto.SHA256, - }, - &rsa.PSSOptions{ - SaltLength: rsa.PSSSaltLengthAuto, - Hash: crypto.SHA256, - }, - } - RegisterSigningMethod(SigningMethodPS256.Alg(), func() SigningMethod { - return SigningMethodPS256 - }) - - // PS384 - SigningMethodPS384 = &SigningMethodRSAPSS{ - &SigningMethodRSA{ - Name: "PS384", - Hash: crypto.SHA384, - }, - &rsa.PSSOptions{ - SaltLength: rsa.PSSSaltLengthAuto, - Hash: crypto.SHA384, - }, - } - RegisterSigningMethod(SigningMethodPS384.Alg(), func() SigningMethod { - return SigningMethodPS384 - }) - - // PS512 - SigningMethodPS512 = &SigningMethodRSAPSS{ - &SigningMethodRSA{ - Name: "PS512", - Hash: crypto.SHA512, - }, - &rsa.PSSOptions{ - SaltLength: rsa.PSSSaltLengthAuto, - Hash: crypto.SHA512, - }, - } - RegisterSigningMethod(SigningMethodPS512.Alg(), func() SigningMethod { - return SigningMethodPS512 - }) -} - -// Implements the Verify method from SigningMethod -// For this verify method, key must be an rsa.PublicKey struct -func (m *SigningMethodRSAPSS) Verify(signingString, signature string, key interface{}) error { - var err error - - // Decode the signature - var sig []byte - if sig, err = DecodeSegment(signature); err != nil { - return err - } - - var rsaKey *rsa.PublicKey - switch k := key.(type) { - case *rsa.PublicKey: - rsaKey = k - default: - return ErrInvalidKey - } - - // Create hasher - if !m.Hash.Available() { - return ErrHashUnavailable - } - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - return rsa.VerifyPSS(rsaKey, m.Hash, hasher.Sum(nil), sig, m.Options) -} - -// Implements the Sign method from SigningMethod -// For this signing method, key must be an rsa.PrivateKey struct -func (m *SigningMethodRSAPSS) Sign(signingString string, key interface{}) (string, error) { - var rsaKey *rsa.PrivateKey - - switch k := key.(type) { - case *rsa.PrivateKey: - rsaKey = k - default: - return "", ErrInvalidKeyType - } - - // Create the hasher - if !m.Hash.Available() { - return "", ErrHashUnavailable - } - - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - // Sign the string and return the encoded bytes - if sigBytes, err := rsa.SignPSS(rand.Reader, rsaKey, m.Hash, hasher.Sum(nil), m.Options); err == nil { - return EncodeSegment(sigBytes), nil - } else { - return "", err - } -} diff --git a/vendor/github.com/dgrijalva/jwt-go/rsa_utils.go b/vendor/github.com/dgrijalva/jwt-go/rsa_utils.go deleted file mode 100644 index 213a90d..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/rsa_utils.go +++ /dev/null @@ -1,69 +0,0 @@ -package jwt - -import ( - "crypto/rsa" - "crypto/x509" - "encoding/pem" - "errors" -) - -var ( - ErrKeyMustBePEMEncoded = errors.New("Invalid Key: Key must be PEM encoded PKCS1 or PKCS8 private key") - ErrNotRSAPrivateKey = errors.New("Key is not a valid RSA private key") - ErrNotRSAPublicKey = errors.New("Key is not a valid RSA public key") -) - -// Parse PEM encoded PKCS1 or PKCS8 private key -func ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error) { - var err error - - // Parse PEM block - var block *pem.Block - if block, _ = pem.Decode(key); block == nil { - return nil, ErrKeyMustBePEMEncoded - } - - var parsedKey interface{} - if parsedKey, err = x509.ParsePKCS1PrivateKey(block.Bytes); err != nil { - if parsedKey, err = x509.ParsePKCS8PrivateKey(block.Bytes); err != nil { - return nil, err - } - } - - var pkey *rsa.PrivateKey - var ok bool - if pkey, ok = parsedKey.(*rsa.PrivateKey); !ok { - return nil, ErrNotRSAPrivateKey - } - - return pkey, nil -} - -// Parse PEM encoded PKCS1 or PKCS8 public key -func ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error) { - var err error - - // Parse PEM block - var block *pem.Block - if block, _ = pem.Decode(key); block == nil { - return nil, ErrKeyMustBePEMEncoded - } - - // Parse the key - var parsedKey interface{} - if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil { - if cert, err := x509.ParseCertificate(block.Bytes); err == nil { - parsedKey = cert.PublicKey - } else { - return nil, err - } - } - - var pkey *rsa.PublicKey - var ok bool - if pkey, ok = parsedKey.(*rsa.PublicKey); !ok { - return nil, ErrNotRSAPublicKey - } - - return pkey, nil -} diff --git a/vendor/github.com/dgrijalva/jwt-go/signing_method.go b/vendor/github.com/dgrijalva/jwt-go/signing_method.go deleted file mode 100644 index ed1f212..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/signing_method.go +++ /dev/null @@ -1,35 +0,0 @@ -package jwt - -import ( - "sync" -) - -var signingMethods = map[string]func() SigningMethod{} -var signingMethodLock = new(sync.RWMutex) - -// Implement SigningMethod to add new methods for signing or verifying tokens. -type SigningMethod interface { - Verify(signingString, signature string, key interface{}) error // Returns nil if signature is valid - Sign(signingString string, key interface{}) (string, error) // Returns encoded signature or error - Alg() string // returns the alg identifier for this method (example: 'HS256') -} - -// Register the "alg" name and a factory function for signing method. -// This is typically done during init() in the method's implementation -func RegisterSigningMethod(alg string, f func() SigningMethod) { - signingMethodLock.Lock() - defer signingMethodLock.Unlock() - - signingMethods[alg] = f -} - -// Get a signing method from an "alg" string -func GetSigningMethod(alg string) (method SigningMethod) { - signingMethodLock.RLock() - defer signingMethodLock.RUnlock() - - if methodF, ok := signingMethods[alg]; ok { - method = methodF() - } - return -} diff --git a/vendor/github.com/dgrijalva/jwt-go/token.go b/vendor/github.com/dgrijalva/jwt-go/token.go deleted file mode 100644 index d637e08..0000000 --- a/vendor/github.com/dgrijalva/jwt-go/token.go +++ /dev/null @@ -1,108 +0,0 @@ -package jwt - -import ( - "encoding/base64" - "encoding/json" - "strings" - "time" -) - -// TimeFunc provides the current time when parsing token to validate "exp" claim (expiration time). -// You can override it to use another time value. This is useful for testing or if your -// server uses a different time zone than your tokens. -var TimeFunc = time.Now - -// Parse methods use this callback function to supply -// the key for verification. The function receives the parsed, -// but unverified Token. This allows you to use properties in the -// Header of the token (such as `kid`) to identify which key to use. -type Keyfunc func(*Token) (interface{}, error) - -// A JWT Token. Different fields will be used depending on whether you're -// creating or parsing/verifying a token. -type Token struct { - Raw string // The raw token. Populated when you Parse a token - Method SigningMethod // The signing method used or to be used - Header map[string]interface{} // The first segment of the token - Claims Claims // The second segment of the token - Signature string // The third segment of the token. Populated when you Parse a token - Valid bool // Is the token valid? Populated when you Parse/Verify a token -} - -// Create a new Token. Takes a signing method -func New(method SigningMethod) *Token { - return NewWithClaims(method, MapClaims{}) -} - -func NewWithClaims(method SigningMethod, claims Claims) *Token { - return &Token{ - Header: map[string]interface{}{ - "typ": "JWT", - "alg": method.Alg(), - }, - Claims: claims, - Method: method, - } -} - -// Get the complete, signed token -func (t *Token) SignedString(key interface{}) (string, error) { - var sig, sstr string - var err error - if sstr, err = t.SigningString(); err != nil { - return "", err - } - if sig, err = t.Method.Sign(sstr, key); err != nil { - return "", err - } - return strings.Join([]string{sstr, sig}, "."), nil -} - -// Generate the signing string. This is the -// most expensive part of the whole deal. Unless you -// need this for something special, just go straight for -// the SignedString. -func (t *Token) SigningString() (string, error) { - var err error - parts := make([]string, 2) - for i, _ := range parts { - var jsonValue []byte - if i == 0 { - if jsonValue, err = json.Marshal(t.Header); err != nil { - return "", err - } - } else { - if jsonValue, err = json.Marshal(t.Claims); err != nil { - return "", err - } - } - - parts[i] = EncodeSegment(jsonValue) - } - return strings.Join(parts, "."), nil -} - -// Parse, validate, and return a token. -// keyFunc will receive the parsed token and should return the key for validating. -// If everything is kosher, err will be nil -func Parse(tokenString string, keyFunc Keyfunc) (*Token, error) { - return new(Parser).Parse(tokenString, keyFunc) -} - -func ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc) (*Token, error) { - return new(Parser).ParseWithClaims(tokenString, claims, keyFunc) -} - -// Encode JWT specific base64url encoding with padding stripped -func EncodeSegment(seg []byte) string { - return strings.TrimRight(base64.URLEncoding.EncodeToString(seg), "=") -} - -// Decode JWT specific base64url encoding with padding stripped -func DecodeSegment(seg string) ([]byte, error) { - if l := len(seg) % 4; l > 0 { - seg += strings.Repeat("=", 4-l) - } - - return base64.URLEncoding.DecodeString(seg) -} diff --git a/vendor/github.com/go-kit/kit/CONTRIBUTING.md b/vendor/github.com/go-kit/kit/CONTRIBUTING.md deleted file mode 100644 index c0751f8..0000000 --- a/vendor/github.com/go-kit/kit/CONTRIBUTING.md +++ /dev/null @@ -1,18 +0,0 @@ -# Contributing - -First, thank you for contributing! We love and encourage pull requests from everyone. - -Before submitting major changes, here are a few guidelines to follow: - -1. Check the [open issues][issues] and [pull requests][prs] for existing discussions. -1. Open an [issue][issues] first, to discuss a new feature or enhancement. -1. Write tests, and make sure the test suite passes locally and on CI. -1. Open a pull request, and reference the relevant issue(s). -1. After receiving feedback, [squash your commits][squash] and add a [great commit message][message]. -1. Have fun! - -[issues]: https://github.com/go-kit/kit/issues -[prs]: https://github.com/go-kit/kit/pulls -[squash]: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html -[message]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html - diff --git a/vendor/github.com/go-kit/kit/LICENSE b/vendor/github.com/go-kit/kit/LICENSE deleted file mode 100644 index 9d83342..0000000 --- a/vendor/github.com/go-kit/kit/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Peter Bourgon - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - diff --git a/vendor/github.com/go-kit/kit/README.md b/vendor/github.com/go-kit/kit/README.md deleted file mode 100644 index e65c7ee..0000000 --- a/vendor/github.com/go-kit/kit/README.md +++ /dev/null @@ -1,117 +0,0 @@ -# Go kit [![Circle CI](https://circleci.com/gh/go-kit/kit.svg?style=svg)](https://circleci.com/gh/go-kit/kit) [![Drone.io](https://drone.io/github.com/go-kit/kit/status.png)](https://drone.io/github.com/go-kit/kit/latest) [![Travis CI](https://travis-ci.org/go-kit/kit.svg?branch=master)](https://travis-ci.org/go-kit/kit) [![GoDoc](https://godoc.org/github.com/go-kit/kit?status.svg)](https://godoc.org/github.com/go-kit/kit) [![Coverage Status](https://coveralls.io/repos/go-kit/kit/badge.svg?branch=master&service=github)](https://coveralls.io/github/go-kit/kit?branch=master) [![Go Report Card](https://goreportcard.com/badge/go-kit/kit)](https://goreportcard.com/report/go-kit/kit) - -**Go kit** is a **distributed programming toolkit** for building microservices -in large organizations. We solve common problems in distributed systems, so -you can focus on your business logic. - -- Website: [gokit.io](https://gokit.io) -- Mailing list: [go-kit](https://groups.google.com/forum/#!forum/go-kit) -- Slack: [gophers.slack.com](https://gophers.slack.com) **#go-kit** ([invite](https://gophersinvite.herokuapp.com/)) - -## Motivation - -Go has emerged as the language of the server, but it remains underrepresented -in large, consumer-focused tech companies like Facebook, Twitter, Netflix, and -SoundCloud. These organizations have largely adopted JVM-based stacks for -their business logic, owing in large part to libraries and ecosystems that -directly support their microservice architectures. - -To reach its next level of success, Go needs more than simple primitives and -idioms. It needs a comprehensive toolkit, for coherent distributed programming -in the large. Go kit is a set of packages and best practices, which provide a -comprehensive, robust, and trustable way of building microservices for -organizations of any size. - -For more details, see - [the website](https://gokit.io), - [the motivating blog post](http://peter.bourgon.org/go-kit/) and - [the video of the talk](https://www.youtube.com/watch?v=iFR_7AKkJFU). -See also the - [Go kit talk at GopherCon 2015](https://www.youtube.com/watch?v=1AjaZi4QuGo). - -## Goals - -- Operate in a heterogeneous SOA — expect to interact with mostly non-Go-kit services -- RPC as the primary messaging pattern -- Pluggable serialization and transport — not just JSON over HTTP -- Operate within existing infrastructures — no mandates for specific tools or technologies - -## Non-goals - -- Supporting messaging patterns other than RPC (for now) — e.g. MPI, pub/sub, CQRS, etc. -- Re-implementing functionality that can be provided by adapting existing software -- Having opinions on operational concerns: deployment, configuration, process supervision, orchestration, etc. - -## Contributing - -Please see [CONTRIBUTING.md](/CONTRIBUTING.md). -Thank you, [contributors](https://github.com/go-kit/kit/graphs/contributors)! - -## Dependency management - -Go kit is a library, designed to be imported into a binary package. -Vendoring is currently the best way for binary package authors - to ensure reliable, reproducible builds. -Therefore, we strongly recommend our users use vendoring for all of their dependencies, - including Go kit. -To avoid compatibility and availability issues, - Go kit doesn't vendor its own dependencies, - and doesn't recommend use of third-party import proxies. - -There are several tools which make vendoring easier, including - [gb](http://getgb.io), - [glide](https://github.com/Masterminds/glide), - [gvt](https://github.com/FiloSottile/gvt), - [govendor](https://github.com/kardianos/govendor), and - [vendetta](https://github.com/dpw/vendetta). -In addition, Go kit uses a variety of continuous integration providers - to find and fix compatibility problems as soon as they occur. - -## Related projects - -Projects with a ★ have had particular influence on Go kit's design (or vice-versa). - -### Service frameworks - -- [gizmo](https://github.com/nytimes/gizmo), a microservice toolkit from The New York Times ★ -- [go-micro](https://github.com/myodc/go-micro), a microservices client/server library ★ -- [h2](https://github.com/hailocab/h2), a microservices framework ★ -- [gotalk](https://github.com/rsms/gotalk), async peer communication protocol & library -- [Kite](https://github.com/koding/kite), a micro-service framework -- [gocircuit](https://github.com/gocircuit/circuit), dynamic cloud orchestration - -### Individual components - -- [afex/hystrix-go](https://github.com/afex/hystrix-go), client-side latency and fault tolerance library -- [armon/go-metrics](https://github.com/armon/go-metrics), library for exporting performance and runtime metrics to external metrics systems -- [codahale/lunk](https://github.com/codahale/lunk), structured logging in the style of Google's Dapper or Twitter's Zipkin -- [eapache/go-resiliency](https://github.com/eapache/go-resiliency), resiliency patterns -- [sasbury/logging](https://github.com/sasbury/logging), a tagged style of logging -- [grpc/grpc-go](https://github.com/grpc/grpc-go), HTTP/2 based RPC -- [inconshreveable/log15](https://github.com/inconshreveable/log15), simple, powerful logging for Go ★ -- [mailgun/vulcand](https://github.com/vulcand/vulcand), programmatic load balancer backed by etcd -- [mattheath/phosphor](https://github.com/mondough/phosphor), distributed system tracing -- [pivotal-golang/lager](https://github.com/pivotal-golang/lager), an opinionated logging library -- [rubyist/circuitbreaker](https://github.com/rubyist/circuitbreaker), circuit breaker library -- [Sirupsen/logrus](https://github.com/Sirupsen/logrus), structured, pluggable logging for Go ★ -- [sourcegraph/appdash](https://github.com/sourcegraph/appdash), application tracing system based on Google's Dapper -- [spacemonkeygo/monitor](https://github.com/spacemonkeygo/monitor), data collection, monitoring, instrumentation, and Zipkin client library -- [streadway/handy](https://github.com/streadway/handy), net/http handler filters -- [vitess/rpcplus](https://godoc.org/github.com/youtube/vitess/go/rpcplus), package rpc + context.Context -- [gdamore/mangos](https://github.com/gdamore/mangos), nanomsg implementation in pure Go - -### Web frameworks - -- [Gorilla](http://www.gorillatoolkit.org) -- [Gin](https://gin-gonic.github.io/gin/) -- [Negroni](https://github.com/codegangsta/negroni) -- [Goji](https://github.com/zenazn/goji) -- [Martini](https://github.com/go-martini/martini) -- [Beego](http://beego.me/) -- [Revel](https://revel.github.io/) (considered harmful) - -## Additional reading - -- [Architecting for the Cloud](http://fr.slideshare.net/stonse/architecting-for-the-cloud-using-netflixoss-codemash-workshop-29852233) — Netflix -- [Dapper, a Large-Scale Distributed Systems Tracing Infrastructure](http://research.google.com/pubs/pub36356.html) — Google -- [Your Server as a Function](http://monkey.org/~marius/funsrv.pdf) (PDF) — Twitter diff --git a/vendor/github.com/go-kit/kit/ROADMAP.md b/vendor/github.com/go-kit/kit/ROADMAP.md deleted file mode 100644 index 5c462aa..0000000 --- a/vendor/github.com/go-kit/kit/ROADMAP.md +++ /dev/null @@ -1,17 +0,0 @@ -# Roadmap - -This is a coarse-grained roadmap of Go kit development direction in the short -to mid-term future. It will be kept reasonably up-to-date by the project -maintainers. Suggest new ideas, enhancements, and features using the standard -[issues](https://github.com/go-kit/kit/issues) model. - -## Prioritized - -1. kitgen code generation (#308, #70) -1. package pubsub (#298, #295) - -## Unprioritized - -- package log/levels refactor (#250, #269, #252) -- package auth/jwt (#255) - diff --git a/vendor/github.com/go-kit/kit/auth/jwt/README.md b/vendor/github.com/go-kit/kit/auth/jwt/README.md deleted file mode 100644 index bec4f67..0000000 --- a/vendor/github.com/go-kit/kit/auth/jwt/README.md +++ /dev/null @@ -1,122 +0,0 @@ -# package auth/jwt - -`package auth/jwt` provides a set of interfaces for service authorization -through [JSON Web Tokens](https://jwt.io/). - -## Usage - -NewParser takes a key function and an expected signing method and returns an -`endpoint.Middleware`. The middleware will parse a token passed into the -context via the `jwt.JWTTokenContextKey`. If the token is valid, any claims -will be added to the context via the `jwt.JWTClaimsContextKey`. - -```go -import ( - stdjwt "github.com/dgrijalva/jwt-go" - - "github.com/go-kit/kit/auth/jwt" - "github.com/go-kit/kit/endpoint" -) - -func main() { - var exampleEndpoint endpoint.Endpoint - { - kf := func(token *stdjwt.Token) (interface{}, error) { return []byte("SigningString"), nil } - exampleEndpoint = MakeExampleEndpoint(service) - exampleEndpoint = jwt.NewParser(kf, stdjwt.SigningMethodHS256)(exampleEndpoint) - } -} -``` - -NewSigner takes a JWT key ID header, the signing key, signing method, and a -claims object. It returns an `endpoint.Middleware`. The middleware will build -the token string and add it to the context via the `jwt.JWTTokenContextKey`. - -```go -import ( - stdjwt "github.com/dgrijalva/jwt-go" - - "github.com/go-kit/kit/auth/jwt" - "github.com/go-kit/kit/endpoint" -) - -func main() { - var exampleEndpoint endpoint.Endpoint - { - exampleEndpoint = grpctransport.NewClient(...).Endpoint() - exampleEndpoint = jwt.NewSigner( - "kid-header", - []byte("SigningString"), - stdjwt.SigningMethodHS256, - jwt.Claims{}, - )(exampleEndpoint) - } -} -``` - -In order for the parser and the signer to work, the authorization headers need -to be passed between the request and the context. `ToHTTPContext()`, -`FromHTTPContext()`, `ToGRPCContext()`, and `FromGRPCContext()` are given as -helpers to do this. These functions implement the correlating transport's -RequestFunc interface and can be passed as ClientBefore or ServerBefore -options. - -Example of use in a client: - -```go -import ( - stdjwt "github.com/dgrijalva/jwt-go" - - grpctransport "github.com/go-kit/kit/transport/grpc" - "github.com/go-kit/kit/auth/jwt" - "github.com/go-kit/kit/endpoint" -) - -func main() { - - options := []httptransport.ClientOption{} - var exampleEndpoint endpoint.Endpoint - { - exampleEndpoint = grpctransport.NewClient(..., grpctransport.ClientBefore(jwt.FromGRPCContext())).Endpoint() - exampleEndpoint = jwt.NewSigner( - "kid-header", - []byte("SigningString"), - stdjwt.SigningMethodHS256, - jwt.Claims{}, - )(exampleEndpoint) - } -} -``` - -Example of use in a server: - -```go -import ( - "golang.org/x/net/context" - - "github.com/go-kit/kit/auth/jwt" - "github.com/go-kit/kit/log" - grpctransport "github.com/go-kit/kit/transport/grpc" -) - -func MakeGRPCServer(ctx context.Context, endpoints Endpoints, logger log.Logger) pb.ExampleServer { - options := []grpctransport.ServerOption{grpctransport.ServerErrorLogger(logger)} - - return &grpcServer{ - createUser: grpctransport.NewServer( - ctx, - endpoints.CreateUserEndpoint, - DecodeGRPCCreateUserRequest, - EncodeGRPCCreateUserResponse, - append(options, grpctransport.ServerBefore(jwt.ToGRPCContext()))..., - ), - getUser: grpctransport.NewServer( - ctx, - endpoints.GetUserEndpoint, - DecodeGRPCGetUserRequest, - EncodeGRPCGetUserResponse, - options..., - ), - } -} -``` diff --git a/vendor/github.com/go-kit/kit/auth/jwt/middleware.go b/vendor/github.com/go-kit/kit/auth/jwt/middleware.go deleted file mode 100644 index 8b5f826..0000000 --- a/vendor/github.com/go-kit/kit/auth/jwt/middleware.go +++ /dev/null @@ -1,122 +0,0 @@ -package jwt - -import ( - "errors" - - jwt "github.com/dgrijalva/jwt-go" - "golang.org/x/net/context" - - "github.com/go-kit/kit/endpoint" -) - -type contextKey string - -const ( - // JWTTokenContextKey holds the key used to store a JWT Token in the - // context. - JWTTokenContextKey contextKey = "JWTToken" - // JWTClaimsContxtKey holds the key used to store the JWT Claims in the - // context. - JWTClaimsContextKey contextKey = "JWTClaims" -) - -var ( - // ErrTokenContextMissing denotes a token was not passed into the parsing - // middleware's context. - ErrTokenContextMissing = errors.New("token up for parsing was not passed through the context") - // ErrTokenInvalid denotes a token was not able to be validated. - ErrTokenInvalid = errors.New("JWT Token was invalid") - // ErrTokenExpired denotes a token's expire header (exp) has since passed. - ErrTokenExpired = errors.New("JWT Token is expired") - // ErrTokenMalformed denotes a token was not formatted as a JWT token. - ErrTokenMalformed = errors.New("JWT Token is malformed") - // ErrTokenNotActive denotes a token's not before header (nbf) is in the - // future. - ErrTokenNotActive = errors.New("token is not valid yet") - // ErrUncesptedSigningMethod denotes a token was signed with an unexpected - // signing method. - ErrUnexpectedSigningMethod = errors.New("unexpected signing method") -) - -type Claims map[string]interface{} - -// NewSigner creates a new JWT token generating middleware, specifying key ID, -// signing string, signing method and the claims you would like it to contain. -// Tokens are signed with a Key ID header (kid) which is useful for determining -// the key to use for parsing. Particularly useful for clients. -func NewSigner(kid string, key []byte, method jwt.SigningMethod, claims Claims) endpoint.Middleware { - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - token := jwt.NewWithClaims(method, jwt.MapClaims(claims)) - token.Header["kid"] = kid - - // Sign and get the complete encoded token as a string using the secret - tokenString, err := token.SignedString(key) - if err != nil { - return nil, err - } - ctx = context.WithValue(ctx, JWTTokenContextKey, tokenString) - - return next(ctx, request) - } - } -} - -// NewParser creates a new JWT token parsing middleware, specifying a -// jwt.Keyfunc interface and the signing method. NewParser adds the resulting -// claims to endpoint context or returns error on invalid token. Particularly -// useful for servers. -func NewParser(keyFunc jwt.Keyfunc, method jwt.SigningMethod) endpoint.Middleware { - return func(next endpoint.Endpoint) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - // tokenString is stored in the context from the transport handlers. - tokenString, ok := ctx.Value(JWTTokenContextKey).(string) - if !ok { - return nil, ErrTokenContextMissing - } - - // Parse takes the token string and a function for looking up the - // key. The latter is especially useful if you use multiple keys - // for your application. The standard is to use 'kid' in the head - // of the token to identify which key to use, but the parsed token - // (head and claims) is provided to the callback, providing - // flexibility. - token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) { - // Don't forget to validate the alg is what you expect: - if token.Method != method { - return nil, ErrUnexpectedSigningMethod - } - - return keyFunc(token) - }) - if err != nil { - if e, ok := err.(*jwt.ValidationError); ok && e.Inner != nil { - if e.Errors&jwt.ValidationErrorMalformed != 0 { - // Token is malformed - return nil, ErrTokenMalformed - } else if e.Errors&jwt.ValidationErrorExpired != 0 { - // Token is expired - return nil, ErrTokenExpired - } else if e.Errors&jwt.ValidationErrorNotValidYet != 0 { - // Token is not active yet - return nil, ErrTokenNotActive - } - - return nil, e.Inner - } - - return nil, err - } - - if !token.Valid { - return nil, ErrTokenInvalid - } - - if claims, ok := token.Claims.(jwt.MapClaims); ok { - ctx = context.WithValue(ctx, JWTClaimsContextKey, Claims(claims)) - } - - return next(ctx, request) - } - } -} diff --git a/vendor/github.com/go-kit/kit/auth/jwt/transport.go b/vendor/github.com/go-kit/kit/auth/jwt/transport.go deleted file mode 100644 index f4ab4d8..0000000 --- a/vendor/github.com/go-kit/kit/auth/jwt/transport.go +++ /dev/null @@ -1,89 +0,0 @@ -package jwt - -import ( - "fmt" - stdhttp "net/http" - "strings" - - "golang.org/x/net/context" - "google.golang.org/grpc/metadata" - - "github.com/go-kit/kit/transport/grpc" - "github.com/go-kit/kit/transport/http" -) - -const ( - bearer string = "bearer" - bearerFormat string = "Bearer %s" -) - -// ToHTTPContext moves JWT token from request header to context. Particularly -// useful for servers. -func ToHTTPContext() http.RequestFunc { - return func(ctx context.Context, r *stdhttp.Request) context.Context { - token, ok := extractTokenFromAuthHeader(r.Header.Get("Authorization")) - if !ok { - return ctx - } - - return context.WithValue(ctx, JWTTokenContextKey, token) - } -} - -// FromHTTPContext moves JWT token from context to request header. Particularly -// useful for clients. -func FromHTTPContext() http.RequestFunc { - return func(ctx context.Context, r *stdhttp.Request) context.Context { - token, ok := ctx.Value(JWTTokenContextKey).(string) - if ok { - r.Header.Add("Authorization", generateAuthHeaderFromToken(token)) - } - return ctx - } -} - -// ToGRPCContext moves JWT token from grpc metadata to context. Particularly -// userful for servers. -func ToGRPCContext() grpc.RequestFunc { - return func(ctx context.Context, md *metadata.MD) context.Context { - // capital "Key" is illegal in HTTP/2. - authHeader, ok := (*md)["authorization"] - if !ok { - return ctx - } - - token, ok := extractTokenFromAuthHeader(authHeader[0]) - if ok { - ctx = context.WithValue(ctx, JWTTokenContextKey, token) - } - - return ctx - } -} - -// FromGRPCContext moves JWT token from context to grpc metadata. Particularly -// useful for clients. -func FromGRPCContext() grpc.RequestFunc { - return func(ctx context.Context, md *metadata.MD) context.Context { - token, ok := ctx.Value(JWTTokenContextKey).(string) - if ok { - // capital "Key" is illegal in HTTP/2. - (*md)["authorization"] = []string{generateAuthHeaderFromToken(token)} - } - - return ctx - } -} - -func extractTokenFromAuthHeader(val string) (token string, ok bool) { - authHeaderParts := strings.Split(val, " ") - if len(authHeaderParts) != 2 || strings.ToLower(authHeaderParts[0]) != bearer { - return "", false - } - - return authHeaderParts[1], true -} - -func generateAuthHeaderFromToken(token string) string { - return fmt.Sprintf(bearerFormat, token) -} diff --git a/vendor/github.com/go-kit/kit/coverage.bash b/vendor/github.com/go-kit/kit/coverage.bash deleted file mode 100755 index f4b0524..0000000 --- a/vendor/github.com/go-kit/kit/coverage.bash +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env bash - -# This script runs the cover tool on all packages with test files. If you set a -# WEB environment variable, it will additionally open the web-based coverage -# visualizer for each package. - -set -e - -function go_files { find . -name '*_test.go' ; } -function filter { grep -v '/_' ; } -function remove_relative_prefix { sed -e 's/^\.\///g' ; } - -function directories { - go_files | filter | remove_relative_prefix | while read f - do - dirname $f - done -} - -function unique_directories { directories | sort | uniq ; } - -PATHS=${1:-$(unique_directories)} - -function report { - for path in $PATHS - do - go test -coverprofile=$path/cover.coverprofile ./$path - done -} - -function combine { - gover -} - -function clean { - find . -name cover.coverprofile | xargs rm -} - -report -combine -clean - -if [ -n "${WEB+x}" ] -then - go tool cover -html=gover.coverprofile -fi - diff --git a/vendor/github.com/go-kit/kit/endpoint/doc.go b/vendor/github.com/go-kit/kit/endpoint/doc.go deleted file mode 100644 index 84e27b9..0000000 --- a/vendor/github.com/go-kit/kit/endpoint/doc.go +++ /dev/null @@ -1,5 +0,0 @@ -// Package endpoint defines an abstraction for RPCs. -// -// Endpoints are a fundamental building block for many Go kit components. -// Endpoints are implemented by servers, and called by clients. -package endpoint diff --git a/vendor/github.com/go-kit/kit/endpoint/endpoint.go b/vendor/github.com/go-kit/kit/endpoint/endpoint.go deleted file mode 100644 index 786a288..0000000 --- a/vendor/github.com/go-kit/kit/endpoint/endpoint.go +++ /dev/null @@ -1,28 +0,0 @@ -package endpoint - -import ( - "golang.org/x/net/context" -) - -// Endpoint is the fundamental building block of servers and clients. -// It represents a single RPC method. -type Endpoint func(ctx context.Context, request interface{}) (response interface{}, err error) - -// Nop is an endpoint that does nothing and returns a nil error. -// Useful for tests. -func Nop(context.Context, interface{}) (interface{}, error) { return struct{}{}, nil } - -// Middleware is a chainable behavior modifier for endpoints. -type Middleware func(Endpoint) Endpoint - -// Chain is a helper function for composing middlewares. Requests will -// traverse them in the order they're declared. That is, the first middleware -// is treated as the outermost middleware. -func Chain(outer Middleware, others ...Middleware) Middleware { - return func(next Endpoint) Endpoint { - for i := len(others) - 1; i >= 0; i-- { // reverse - next = others[i](next) - } - return outer(next) - } -} diff --git a/vendor/github.com/go-kit/kit/lint b/vendor/github.com/go-kit/kit/lint deleted file mode 100755 index 12e3072..0000000 --- a/vendor/github.com/go-kit/kit/lint +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -set -o nounset -set -o pipefail - -if [ ! $(command -v gometalinter) ] -then - go get github.com/alecthomas/gometalinter - gometalinter --update --install -fi - -time gometalinter \ - --exclude='error return value not checked.*(Close|Log|Print).*\(errcheck\)$' \ - --exclude='.*_test\.go:.*error return value not checked.*\(errcheck\)$' \ - --exclude='/thrift/' \ - --exclude='/pb/' \ - --exclude='no args in Log call \(vet\)' \ - --disable=dupl \ - --disable=aligncheck \ - --disable=gotype \ - --cyclo-over=20 \ - --tests \ - --concurrency=2 \ - --deadline=300s \ - ./... diff --git a/vendor/github.com/go-kit/kit/log/README.md b/vendor/github.com/go-kit/kit/log/README.md deleted file mode 100644 index 2763f7f..0000000 --- a/vendor/github.com/go-kit/kit/log/README.md +++ /dev/null @@ -1,148 +0,0 @@ -# package log - -`package log` provides a minimal interface for structured logging in services. -It may be wrapped to encode conventions, enforce type-safety, provide leveled logging, and so on. -It can be used for both typical application log events, and log-structured data streams. - -## Structured logging - -Structured logging is, basically, conceding to the reality that logs are _data_, - and warrant some level of schematic rigor. -Using a stricter, key/value-oriented message format for our logs, - containing contextual and semantic information, - makes it much easier to get insight into the operational activity of the systems we build. -Consequently, `package log` is of the strong belief that - "[the benefits of structured logging outweigh the minimal effort involved](https://www.thoughtworks.com/radar/techniques/structured-logging)". - -Migrating from unstructured to structured logging is probably a lot easier than you'd expect. - -```go -// Unstructured -log.Printf("HTTP server listening on %s", addr) - -// Structured -logger.Log("transport", "HTTP", "addr", addr, "msg", "listening") -``` - -## Usage - -### Typical application logging - -```go -w := log.NewSyncWriter(os.Stderr) -logger := log.NewLogfmtLogger(w) -logger.Log("question", "what is the meaning of life?", "answer", 42) - -// Output: -// question="what is the meaning of life?" answer=42 -``` - -### Log contexts - -```go -func main() { - var logger log.Logger - logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) - logger = log.NewContext(logger).With("instance_id", 123) - - logger.Log("msg", "starting") - NewWorker(log.NewContext(logger).With("component", "worker")).Run() - NewSlacker(log.NewContext(logger).With("component", "slacker")).Run() -} - -// Output: -// instance_id=123 msg=starting -// instance_id=123 component=worker msg=running -// instance_id=123 component=slacker msg=running -``` - -### Interact with stdlib logger - -Redirect stdlib logger to Go kit logger. - -```go -import ( - "os" - stdlog "log" - kitlog "github.com/go-kit/kit/log" -) - -func main() { - logger := kitlog.NewJSONLogger(kitlog.NewSyncWriter(os.Stdout)) - stdlog.SetOutput(kitlog.NewStdlibAdapter(logger)) - stdlog.Print("I sure like pie") -} - -// Output: -// {"msg":"I sure like pie","ts":"2016/01/01 12:34:56"} -``` - -Or, if, for legacy reasons, - you need to pipe all of your logging through the stdlib log package, - you can redirect Go kit logger to the stdlib logger. - -```go -logger := kitlog.NewLogfmtLogger(kitlog.StdlibWriter{}) -logger.Log("legacy", true, "msg", "at least it's something") - -// Output: -// 2016/01/01 12:34:56 legacy=true msg="at least it's something" -``` - -### Timestamps and callers - -```go -var logger log.Logger -logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) -logger = log.NewContext(logger).With("ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller) - -logger.Log("msg", "hello") - -// Output: -// ts=2016-01-01T12:34:56Z caller=main.go:15 msg=hello -``` - -## Supported output formats - -- [Logfmt](https://brandur.org/logfmt) -- JSON - -## Enhancements - -`package log` is centered on the one-method Logger interface. - -```go -type Logger interface { - Log(keyvals ...interface{}) error -} -``` - -This interface, and its supporting code like [log.Context](https://godoc.org/github.com/go-kit/kit/log#Context), - is the product of much iteration and evaluation. -For more details on the evolution of the Logger interface, - see [The Hunt for a Logger Interface](http://go-talks.appspot.com/github.com/ChrisHines/talks/structured-logging/structured-logging.slide#1), - a talk by [Chris Hines](https://github.com/ChrisHines). -Also, please see - [#63](https://github.com/go-kit/kit/issues/63), - [#76](https://github.com/go-kit/kit/pull/76), - [#131](https://github.com/go-kit/kit/issues/131), - [#157](https://github.com/go-kit/kit/pull/157), - [#164](https://github.com/go-kit/kit/issues/164), and - [#252](https://github.com/go-kit/kit/pull/252) - to review historical conversations about package log and the Logger interface. - -Value-add packages and suggestions, - like improvements to [the leveled logger](https://godoc.org/github.com/go-kit/kit/log/levels), - are of course welcome. -Good proposals should - -- Be composable with [log.Context](https://godoc.org/github.com/go-kit/kit/log#Context), -- Not break the behavior of [log.Caller](https://godoc.org/github.com/go-kit/kit/log#Caller) in any wrapped context, and -- Be friendly to packages that accept only an unadorned log.Logger. - -## Benchmarks & comparisons - -There are a few Go logging benchmarks and comparisons that include Go kit's package log. - -- [imkira/go-loggers-bench](https://github.com/imkira/go-loggers-bench) includes kit/log -- [uber-common/zap](https://github.com/uber-common/zap), a zero-alloc logging library, includes a comparison with kit/log diff --git a/vendor/github.com/go-kit/kit/log/doc.go b/vendor/github.com/go-kit/kit/log/doc.go deleted file mode 100644 index 49d3f18..0000000 --- a/vendor/github.com/go-kit/kit/log/doc.go +++ /dev/null @@ -1,93 +0,0 @@ -// Package log provides a structured logger. -// -// Structured logging produces logs easily consumed later by humans or -// machines. Humans might be interested in debugging errors, or tracing -// specific requests. Machines might be interested in counting interesting -// events, or aggregating information for off-line processing. In both cases, -// it is important that the log messages are structured and actionable. -// Package log is designed to encourage both of these best practices. -// -// Basic Usage -// -// The fundamental interface is Logger. Loggers create log events from -// key/value data. The Logger interface has a single method, Log, which -// accepts a sequence of alternating key/value pairs, which this package names -// keyvals. -// -// type Logger interface { -// Log(keyvals ...interface{}) error -// } -// -// Here is an example of a function using a Logger to create log events. -// -// func RunTask(task Task, logger log.Logger) string { -// logger.Log("taskID", task.ID, "event", "starting task") -// ... -// logger.Log("taskID", task.ID, "event", "task complete") -// } -// -// The keys in the above example are "taskID" and "event". The values are -// task.ID, "starting task", and "task complete". Every key is followed -// immediately by its value. -// -// Keys are usually plain strings. Values may be any type that has a sensible -// encoding in the chosen log format. With structured logging it is a good -// idea to log simple values without formatting them. This practice allows -// the chosen logger to encode values in the most appropriate way. -// -// Log Context -// -// A log context stores keyvals that it includes in all log events. Building -// appropriate log contexts reduces repetition and aids consistency in the -// resulting log output. We can use a context to improve the RunTask example. -// -// func RunTask(task Task, logger log.Logger) string { -// logger = log.NewContext(logger).With("taskID", task.ID) -// logger.Log("event", "starting task") -// ... -// taskHelper(task.Cmd, logger) -// ... -// logger.Log("event", "task complete") -// } -// -// The improved version emits the same log events as the original for the -// first and last calls to Log. The call to taskHelper highlights that a -// context may be passed as a logger to other functions. Each log event -// created by the called function will include the task.ID even though the -// function does not have access to that value. Using log contexts this way -// simplifies producing log output that enables tracing the life cycle of -// individual tasks. (See the Context example for the full code of the -// above snippet.) -// -// Dynamic Context Values -// -// A Valuer function stored in a log context generates a new value each time -// the context logs an event. The Valuer example demonstrates how this -// feature works. -// -// Valuers provide the basis for consistently logging timestamps and source -// code location. The log package defines several valuers for that purpose. -// See Timestamp, DefaultTimestamp, DefaultTimestampUTC, Caller, and -// DefaultCaller. A common logger initialization sequence that ensures all log -// entries contain a timestamp and source location looks like this: -// -// logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout)) -// logger = log.NewContext(logger).With("ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller) -// -// Concurrent Safety -// -// Applications with multiple goroutines want each log event written to the -// same logger to remain separate from other log events. Package log provides -// two simple solutions for concurrent safe logging. -// -// NewSyncWriter wraps an io.Writer and serializes each call to its Write -// method. Using a SyncWriter has the benefit that the smallest practical -// portion of the logging logic is performed within a mutex, but it requires -// the formatting Logger to make only one call to Write per log event. -// -// NewSyncLogger wraps any Logger and serializes each call to its Log method. -// Using a SyncLogger has the benefit that it guarantees each log event is -// handled atomically within the wrapped logger, but it typically serializes -// both the formatting and output logic. Use a SyncLogger if the formatting -// logger may perform multiple writes per log event. -package log diff --git a/vendor/github.com/go-kit/kit/log/json_logger.go b/vendor/github.com/go-kit/kit/log/json_logger.go deleted file mode 100644 index 231e099..0000000 --- a/vendor/github.com/go-kit/kit/log/json_logger.go +++ /dev/null @@ -1,92 +0,0 @@ -package log - -import ( - "encoding" - "encoding/json" - "fmt" - "io" - "reflect" -) - -type jsonLogger struct { - io.Writer -} - -// NewJSONLogger returns a Logger that encodes keyvals to the Writer as a -// single JSON object. Each log event produces no more than one call to -// w.Write. The passed Writer must be safe for concurrent use by multiple -// goroutines if the returned Logger will be used concurrently. -func NewJSONLogger(w io.Writer) Logger { - return &jsonLogger{w} -} - -func (l *jsonLogger) Log(keyvals ...interface{}) error { - n := (len(keyvals) + 1) / 2 // +1 to handle case when len is odd - m := make(map[string]interface{}, n) - for i := 0; i < len(keyvals); i += 2 { - k := keyvals[i] - var v interface{} = ErrMissingValue - if i+1 < len(keyvals) { - v = keyvals[i+1] - } - merge(m, k, v) - } - return json.NewEncoder(l.Writer).Encode(m) -} - -func merge(dst map[string]interface{}, k, v interface{}) { - var key string - switch x := k.(type) { - case string: - key = x - case fmt.Stringer: - key = safeString(x) - default: - key = fmt.Sprint(x) - } - if x, ok := v.(error); ok { - v = safeError(x) - } - - // We want json.Marshaler and encoding.TextMarshaller to take priority over - // err.Error() and v.String(). But json.Marshall (called later) does that by - // default so we force a no-op if it's one of those 2 case. - switch x := v.(type) { - case json.Marshaler: - case encoding.TextMarshaler: - case error: - v = safeError(x) - case fmt.Stringer: - v = safeString(x) - } - - dst[key] = v -} - -func safeString(str fmt.Stringer) (s string) { - defer func() { - if panicVal := recover(); panicVal != nil { - if v := reflect.ValueOf(str); v.Kind() == reflect.Ptr && v.IsNil() { - s = "NULL" - } else { - panic(panicVal) - } - } - }() - s = str.String() - return -} - -func safeError(err error) (s interface{}) { - defer func() { - if panicVal := recover(); panicVal != nil { - if v := reflect.ValueOf(err); v.Kind() == reflect.Ptr && v.IsNil() { - s = nil - } else { - panic(panicVal) - } - } - }() - s = err.Error() - return -} diff --git a/vendor/github.com/go-kit/kit/log/log.go b/vendor/github.com/go-kit/kit/log/log.go deleted file mode 100644 index 97990fe..0000000 --- a/vendor/github.com/go-kit/kit/log/log.go +++ /dev/null @@ -1,144 +0,0 @@ -package log - -import "errors" - -// Logger is the fundamental interface for all log operations. Log creates a -// log event from keyvals, a variadic sequence of alternating keys and values. -// Implementations must be safe for concurrent use by multiple goroutines. In -// particular, any implementation of Logger that appends to keyvals or -// modifies any of its elements must make a copy first. -type Logger interface { - Log(keyvals ...interface{}) error -} - -// ErrMissingValue is appended to keyvals slices with odd length to substitute -// the missing value. -var ErrMissingValue = errors.New("(MISSING)") - -// NewContext returns a new Context that logs to logger. -func NewContext(logger Logger) *Context { - if c, ok := logger.(*Context); ok { - return c - } - return &Context{logger: logger} -} - -// Context must always have the same number of stack frames between calls to -// its Log method and the eventual binding of Valuers to their value. This -// requirement comes from the functional requirement to allow a context to -// resolve application call site information for a log.Caller stored in the -// context. To do this we must be able to predict the number of logging -// functions on the stack when bindValues is called. -// -// Three implementation details provide the needed stack depth consistency. -// The first two of these details also result in better amortized performance, -// and thus make sense even without the requirements regarding stack depth. -// The third detail, however, is subtle and tied to the implementation of the -// Go compiler. -// -// 1. NewContext avoids introducing an additional layer when asked to -// wrap another Context. -// 2. With avoids introducing an additional layer by returning a newly -// constructed Context with a merged keyvals rather than simply -// wrapping the existing Context. -// 3. All of Context's methods take pointer receivers even though they -// do not mutate the Context. -// -// Before explaining the last detail, first some background. The Go compiler -// generates wrapper methods to implement the auto dereferencing behavior when -// calling a value method through a pointer variable. These wrapper methods -// are also used when calling a value method through an interface variable -// because interfaces store a pointer to the underlying concrete value. -// Calling a pointer receiver through an interface does not require generating -// an additional function. -// -// If Context had value methods then calling Context.Log through a variable -// with type Logger would have an extra stack frame compared to calling -// Context.Log through a variable with type Context. Using pointer receivers -// avoids this problem. - -// A Context wraps a Logger and holds keyvals that it includes in all log -// events. When logging, a Context replaces all value elements (odd indexes) -// containing a Valuer with their generated value for each call to its Log -// method. -type Context struct { - logger Logger - keyvals []interface{} - hasValuer bool -} - -// Log replaces all value elements (odd indexes) containing a Valuer in the -// stored context with their generated value, appends keyvals, and passes the -// result to the wrapped Logger. -func (l *Context) Log(keyvals ...interface{}) error { - kvs := append(l.keyvals, keyvals...) - if len(kvs)%2 != 0 { - kvs = append(kvs, ErrMissingValue) - } - if l.hasValuer { - // If no keyvals were appended above then we must copy l.keyvals so - // that future log events will reevaluate the stored Valuers. - if len(keyvals) == 0 { - kvs = append([]interface{}{}, l.keyvals...) - } - bindValues(kvs[:len(l.keyvals)]) - } - return l.logger.Log(kvs...) -} - -// With returns a new Context with keyvals appended to those of the receiver. -func (l *Context) With(keyvals ...interface{}) *Context { - if len(keyvals) == 0 { - return l - } - kvs := append(l.keyvals, keyvals...) - if len(kvs)%2 != 0 { - kvs = append(kvs, ErrMissingValue) - } - return &Context{ - logger: l.logger, - // Limiting the capacity of the stored keyvals ensures that a new - // backing array is created if the slice must grow in Log or With. - // Using the extra capacity without copying risks a data race that - // would violate the Logger interface contract. - keyvals: kvs[:len(kvs):len(kvs)], - hasValuer: l.hasValuer || containsValuer(keyvals), - } -} - -// WithPrefix returns a new Context with keyvals prepended to those of the -// receiver. -func (l *Context) WithPrefix(keyvals ...interface{}) *Context { - if len(keyvals) == 0 { - return l - } - // Limiting the capacity of the stored keyvals ensures that a new - // backing array is created if the slice must grow in Log or With. - // Using the extra capacity without copying risks a data race that - // would violate the Logger interface contract. - n := len(l.keyvals) + len(keyvals) - if len(keyvals)%2 != 0 { - n++ - } - kvs := make([]interface{}, 0, n) - kvs = append(kvs, keyvals...) - if len(kvs)%2 != 0 { - kvs = append(kvs, ErrMissingValue) - } - kvs = append(kvs, l.keyvals...) - return &Context{ - logger: l.logger, - keyvals: kvs, - hasValuer: l.hasValuer || containsValuer(keyvals), - } -} - -// LoggerFunc is an adapter to allow use of ordinary functions as Loggers. If -// f is a function with the appropriate signature, LoggerFunc(f) is a Logger -// object that calls f. -type LoggerFunc func(...interface{}) error - -// Log implements Logger by calling f(keyvals...). -func (f LoggerFunc) Log(keyvals ...interface{}) error { - return f(keyvals...) -} diff --git a/vendor/github.com/go-kit/kit/log/logfmt_logger.go b/vendor/github.com/go-kit/kit/log/logfmt_logger.go deleted file mode 100644 index a003052..0000000 --- a/vendor/github.com/go-kit/kit/log/logfmt_logger.go +++ /dev/null @@ -1,62 +0,0 @@ -package log - -import ( - "bytes" - "io" - "sync" - - "github.com/go-logfmt/logfmt" -) - -type logfmtEncoder struct { - *logfmt.Encoder - buf bytes.Buffer -} - -func (l *logfmtEncoder) Reset() { - l.Encoder.Reset() - l.buf.Reset() -} - -var logfmtEncoderPool = sync.Pool{ - New: func() interface{} { - var enc logfmtEncoder - enc.Encoder = logfmt.NewEncoder(&enc.buf) - return &enc - }, -} - -type logfmtLogger struct { - w io.Writer -} - -// NewLogfmtLogger returns a logger that encodes keyvals to the Writer in -// logfmt format. Each log event produces no more than one call to w.Write. -// The passed Writer must be safe for concurrent use by multiple goroutines if -// the returned Logger will be used concurrently. -func NewLogfmtLogger(w io.Writer) Logger { - return &logfmtLogger{w} -} - -func (l logfmtLogger) Log(keyvals ...interface{}) error { - enc := logfmtEncoderPool.Get().(*logfmtEncoder) - enc.Reset() - defer logfmtEncoderPool.Put(enc) - - if err := enc.EncodeKeyvals(keyvals...); err != nil { - return err - } - - // Add newline to the end of the buffer - if err := enc.EndRecord(); err != nil { - return err - } - - // The Logger interface requires implementations to be safe for concurrent - // use by multiple goroutines. For this implementation that means making - // only one call to l.w.Write() for each call to Log. - if _, err := l.w.Write(enc.buf.Bytes()); err != nil { - return err - } - return nil -} diff --git a/vendor/github.com/go-kit/kit/log/nop_logger.go b/vendor/github.com/go-kit/kit/log/nop_logger.go deleted file mode 100644 index 1047d62..0000000 --- a/vendor/github.com/go-kit/kit/log/nop_logger.go +++ /dev/null @@ -1,8 +0,0 @@ -package log - -type nopLogger struct{} - -// NewNopLogger returns a logger that doesn't do anything. -func NewNopLogger() Logger { return nopLogger{} } - -func (nopLogger) Log(...interface{}) error { return nil } diff --git a/vendor/github.com/go-kit/kit/log/stdlib.go b/vendor/github.com/go-kit/kit/log/stdlib.go deleted file mode 100644 index 7ffd1ca..0000000 --- a/vendor/github.com/go-kit/kit/log/stdlib.go +++ /dev/null @@ -1,116 +0,0 @@ -package log - -import ( - "io" - "log" - "regexp" - "strings" -) - -// StdlibWriter implements io.Writer by invoking the stdlib log.Print. It's -// designed to be passed to a Go kit logger as the writer, for cases where -// it's necessary to redirect all Go kit log output to the stdlib logger. -// -// If you have any choice in the matter, you shouldn't use this. Prefer to -// redirect the stdlib log to the Go kit logger via NewStdlibAdapter. -type StdlibWriter struct{} - -// Write implements io.Writer. -func (w StdlibWriter) Write(p []byte) (int, error) { - log.Print(strings.TrimSpace(string(p))) - return len(p), nil -} - -// StdlibAdapter wraps a Logger and allows it to be passed to the stdlib -// logger's SetOutput. It will extract date/timestamps, filenames, and -// messages, and place them under relevant keys. -type StdlibAdapter struct { - Logger - timestampKey string - fileKey string - messageKey string -} - -// StdlibAdapterOption sets a parameter for the StdlibAdapter. -type StdlibAdapterOption func(*StdlibAdapter) - -// TimestampKey sets the key for the timestamp field. By default, it's "ts". -func TimestampKey(key string) StdlibAdapterOption { - return func(a *StdlibAdapter) { a.timestampKey = key } -} - -// FileKey sets the key for the file and line field. By default, it's "file". -func FileKey(key string) StdlibAdapterOption { - return func(a *StdlibAdapter) { a.fileKey = key } -} - -// MessageKey sets the key for the actual log message. By default, it's "msg". -func MessageKey(key string) StdlibAdapterOption { - return func(a *StdlibAdapter) { a.messageKey = key } -} - -// NewStdlibAdapter returns a new StdlibAdapter wrapper around the passed -// logger. It's designed to be passed to log.SetOutput. -func NewStdlibAdapter(logger Logger, options ...StdlibAdapterOption) io.Writer { - a := StdlibAdapter{ - Logger: logger, - timestampKey: "ts", - fileKey: "file", - messageKey: "msg", - } - for _, option := range options { - option(&a) - } - return a -} - -func (a StdlibAdapter) Write(p []byte) (int, error) { - result := subexps(p) - keyvals := []interface{}{} - var timestamp string - if date, ok := result["date"]; ok && date != "" { - timestamp = date - } - if time, ok := result["time"]; ok && time != "" { - if timestamp != "" { - timestamp += " " - } - timestamp += time - } - if timestamp != "" { - keyvals = append(keyvals, a.timestampKey, timestamp) - } - if file, ok := result["file"]; ok && file != "" { - keyvals = append(keyvals, a.fileKey, file) - } - if msg, ok := result["msg"]; ok { - keyvals = append(keyvals, a.messageKey, msg) - } - if err := a.Logger.Log(keyvals...); err != nil { - return 0, err - } - return len(p), nil -} - -const ( - logRegexpDate = `(?P[0-9]{4}/[0-9]{2}/[0-9]{2})?[ ]?` - logRegexpTime = `(?P