From 96038768cc41bf843fb48e089ad17a99edc365f8 Mon Sep 17 00:00:00 2001 From: Rene Zbinden Date: Thu, 13 Jun 2024 13:13:46 +0200 Subject: [PATCH] chore: update --- Makefile | 103 --------- Taskfile.yaml | 7 +- buf.gen.yaml | 2 +- .../namespace_api.connect.go | 179 +++++++++++++++ .../discoveryv1connect/server_api.connect.go | 178 +++++++++++++++ .../discoveryv1connect/service_api.connect.go | 214 ++++++++++++++++++ .../discoveryv1connect/token_api.connect.go | 145 ++++++++++++ tools.go | 3 +- 8 files changed, 724 insertions(+), 107 deletions(-) delete mode 100644 Makefile create mode 100644 pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect/namespace_api.connect.go create mode 100644 pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect/server_api.connect.go create mode 100644 pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect/service_api.connect.go create mode 100644 pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect/token_api.connect.go diff --git a/Makefile b/Makefile deleted file mode 100644 index 7737d8a..0000000 --- a/Makefile +++ /dev/null @@ -1,103 +0,0 @@ -# This file is generated with create-go-app: do not edit. -.PHONY: build clean test snapshot all install help setup download-goreleaser download-golangci-lint download - -# special target to export all variables -.EXPORT_ALL_VARIABLES: - -PROJECT_RELEASE := 1 -DOCKER_IMAGE_PREFIX := local -CI_PROJECT_URL := http://localhost -INSTALL_DIR := $(HOME)/bin -GO_VERSION := $(shell (go version | awk '{print $$3;}')) -BINARIES := $(shell find ./dist ! -name '*goreleaserdocker*' -path '*_linux_*' -type f -executable) -GORELEASER := 0.156.1 -GOLANGCI := 1.36.0 - - -PROTOC_BUF := 1.31.0 -PROTOC := 26.1 - -## build: build the binaries only -build: - goreleaser build --clean --snapshot - -## snapshot: create a snapshot release -snapshot: - goreleaser release --snapshot --clean --skip-sign - -## clean: cleanup -clean: - rm -rf ./dist - rm -rf ./downloads - rm -rf ./bin - -## download: installs goreleaser and golangci-lint in the correct version to ~/bin -download: download-goreleaser download-golangci-lint - -all: build - -## install: installs resulting binaries to $HOME/bin -install: build - mkdir -p $(INSTALL_DIR) && install $(BINARIES) $(INSTALL_DIR) - -## test: run linter and tests -test: - golangci-lint run - go test -v -count=1 ./... - -## test-short: run test without linting and not in verbose mode -test-short: - go test -count=1 ./... - -help: Makefile - @echo " Choose a command run in "$(PROJECTNAME)":" - @sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' - -download-goreleaser: - mkdir -p downloads - cd downloads && curl -s -L -o goreleaser_Linux_x86_64.tar.gz "https://github.com/goreleaser/goreleaser/releases/download/v$(GORELEASER)/goreleaser_Linux_x86_64.tar.gz" - cd downloads && tar -xvf goreleaser_Linux_x86_64.tar.gz - mkdir -p $(INSTALL_DIR) && install downloads/goreleaser $(INSTALL_DIR) - rm -rf downloads - -download-golangci-lint: - mkdir -p downloads - cd downloads && curl -s -L -o golangci-lint-linux-amd64.tar.gz "https://github.com/golangci/golangci-lint/releases/download/v$(GOLANGCI)/golangci-lint-$(GOLANGCI)-linux-amd64.tar.gz" - cd downloads && tar -xvf golangci-lint-linux-amd64.tar.gz - mkdir -p $(INSTALL_DIR) && install downloads/golangci-lint-$(GOLANGCI)-linux-amd64/golangci-lint $(INSTALL_DIR) - rm -rf downloads - -protoc-lint: bin/buf - ./bin/buf lint - -## protoc-generate-go: create go protoc stubs -protoc-generate-go: bin/buf bin/protoc bin/protoc-gen-go-grpc bin/protoc-gen-grpc-gateway bin/protoc-gen-go - ./bin/buf generate --path=proto/postfinance - -bin: - mkdir bin - -bin/protoc: bin - curl -sLo protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC)/protoc-$(PROTOC)-linux-x86_64.zip - unzip -o protoc.zip bin/protoc - touch bin/protoc - rm protoc.zip - -bin/buf: bin - curl -sLo - https://github.com/bufbuild/buf/releases/download/v$(PROTOC_BUF)/buf-Linux-x86_64.tar.gz | tar -C bin --strip-components=2 -xvzf - buf/bin/buf - chmod +x bin/buf - touch bin/buf - -bin/protoc-gen-go: bin - curl -sLo - https://github.com/protocolbuffers/protobuf-go/releases/download/v$(PROTOC_GEN_GO)/protoc-gen-go.v$(PROTOC_GEN_GO).linux.amd64.tar.gz | tar -xvz -C bin - chmod +x bin/protoc-gen-go - touch bin/protoc-gen-go - -bin/protoc-gen-go-grpc: bin - curl -sLo - https://github.com/grpc/grpc-go/releases/download/cmd%2Fprotoc-gen-go-grpc%2Fv$(PROTOC_GEN_GRPC_GO)/protoc-gen-go-grpc.v$(PROTOC_GEN_GRPC_GO).linux.amd64.tar.gz | tar -C bin -xvzf - ./protoc-gen-go-grpc - chmod +x bin/protoc-gen-go-grpc - touch bin/protoc-gen-go-grpc - -bin/protoc-gen-grpc-gateway: bin - curl -sLo bin/protoc-gen-grpc-gateway https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v$(PROTOC_GEN_GRPC_GATEWAY)/protoc-gen-grpc-gateway-v$(PROTOC_GEN_GRPC_GATEWAY)-linux-x86_64 - chmod +x bin/protoc-gen-grpc-gateway diff --git a/Taskfile.yaml b/Taskfile.yaml index 2e46b3c..b6c6a4e 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -34,6 +34,7 @@ tasks: sources: - proto/**/*.proto generates: + - rm -rf pkg/discoverypb - pkg/discoverypb/postfinance/discovery/v1/*.go download-protoc: @@ -64,7 +65,7 @@ tasks: - mkdir ${GOPATH} - echo $GOPATH - go install google.golang.org/protobuf/cmd/protoc-gen-go - - go install google.golang.org/grpc/cmd/protoc-gen-go-grpc + - go install connectrpc.com/connect/cmd/protoc-gen-connect-go - mkdir -p bin - mv /tmp/go/bin/* bin/ - sudo rm -rf /tmp/go @@ -73,3 +74,7 @@ tasks: generates: - bin/protoc-gen-go - bin/protoc-gen-go-grpc + + clean: + cmds: + - rm -rf bin diff --git a/buf.gen.yaml b/buf.gen.yaml index 550f983..8aa8822 100644 --- a/buf.gen.yaml +++ b/buf.gen.yaml @@ -3,6 +3,6 @@ plugins: - local: ./bin/protoc-gen-go out: pkg/discoverypb opt: paths=source_relative - - local: ./bin/protoc-gen-go-grpc + - local: ./bin/protoc-gen-connect-go out: pkg/discoverypb opt: paths=source_relative diff --git a/pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect/namespace_api.connect.go b/pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect/namespace_api.connect.go new file mode 100644 index 0000000..625f8d1 --- /dev/null +++ b/pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect/namespace_api.connect.go @@ -0,0 +1,179 @@ +// Code generated by protoc-gen-connect-go. DO NOT EDIT. +// +// Source: postfinance/discovery/v1/namespace_api.proto + +package discoveryv1connect + +import ( + connect "connectrpc.com/connect" + context "context" + errors "errors" + http "net/http" + v1 "postfinance/discovery/v1" + strings "strings" +) + +// This is a compile-time assertion to ensure that this generated file and the connect package are +// compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of connect newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of connect or updating the connect +// version compiled into your binary. +const _ = connect.IsAtLeastVersion1_13_0 + +const ( + // NamespaceAPIName is the fully-qualified name of the NamespaceAPI service. + NamespaceAPIName = "postfinance.discovery.v1.NamespaceAPI" +) + +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period. +const ( + // NamespaceAPIRegisterNamespaceProcedure is the fully-qualified name of the NamespaceAPI's + // RegisterNamespace RPC. + NamespaceAPIRegisterNamespaceProcedure = "/postfinance.discovery.v1.NamespaceAPI/RegisterNamespace" + // NamespaceAPIUnregisterNamespaceProcedure is the fully-qualified name of the NamespaceAPI's + // UnregisterNamespace RPC. + NamespaceAPIUnregisterNamespaceProcedure = "/postfinance.discovery.v1.NamespaceAPI/UnregisterNamespace" + // NamespaceAPIListNamespaceProcedure is the fully-qualified name of the NamespaceAPI's + // ListNamespace RPC. + NamespaceAPIListNamespaceProcedure = "/postfinance.discovery.v1.NamespaceAPI/ListNamespace" +) + +// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. +var ( + namespaceAPIServiceDescriptor = v1.File_postfinance_discovery_v1_namespace_api_proto.Services().ByName("NamespaceAPI") + namespaceAPIRegisterNamespaceMethodDescriptor = namespaceAPIServiceDescriptor.Methods().ByName("RegisterNamespace") + namespaceAPIUnregisterNamespaceMethodDescriptor = namespaceAPIServiceDescriptor.Methods().ByName("UnregisterNamespace") + namespaceAPIListNamespaceMethodDescriptor = namespaceAPIServiceDescriptor.Methods().ByName("ListNamespace") +) + +// NamespaceAPIClient is a client for the postfinance.discovery.v1.NamespaceAPI service. +type NamespaceAPIClient interface { + // RegisterNamespace registers a namespace. + RegisterNamespace(context.Context, *connect.Request[v1.RegisterNamespaceRequest]) (*connect.Response[v1.RegisterNamespaceResponse], error) + // UnRegisterNamespace unregisters a namespace. + UnregisterNamespace(context.Context, *connect.Request[v1.UnregisterNamespaceRequest]) (*connect.Response[v1.UnregisterNamespaceResponse], error) + // ListNamespace lists all namespaces. + ListNamespace(context.Context, *connect.Request[v1.ListNamespaceRequest]) (*connect.Response[v1.ListNamespaceResponse], error) +} + +// NewNamespaceAPIClient constructs a client for the postfinance.discovery.v1.NamespaceAPI service. +// By default, it uses the Connect protocol with the binary Protobuf Codec, asks for gzipped +// responses, and sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the +// connect.WithGRPC() or connect.WithGRPCWeb() options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewNamespaceAPIClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) NamespaceAPIClient { + baseURL = strings.TrimRight(baseURL, "/") + return &namespaceAPIClient{ + registerNamespace: connect.NewClient[v1.RegisterNamespaceRequest, v1.RegisterNamespaceResponse]( + httpClient, + baseURL+NamespaceAPIRegisterNamespaceProcedure, + connect.WithSchema(namespaceAPIRegisterNamespaceMethodDescriptor), + connect.WithClientOptions(opts...), + ), + unregisterNamespace: connect.NewClient[v1.UnregisterNamespaceRequest, v1.UnregisterNamespaceResponse]( + httpClient, + baseURL+NamespaceAPIUnregisterNamespaceProcedure, + connect.WithSchema(namespaceAPIUnregisterNamespaceMethodDescriptor), + connect.WithClientOptions(opts...), + ), + listNamespace: connect.NewClient[v1.ListNamespaceRequest, v1.ListNamespaceResponse]( + httpClient, + baseURL+NamespaceAPIListNamespaceProcedure, + connect.WithSchema(namespaceAPIListNamespaceMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// namespaceAPIClient implements NamespaceAPIClient. +type namespaceAPIClient struct { + registerNamespace *connect.Client[v1.RegisterNamespaceRequest, v1.RegisterNamespaceResponse] + unregisterNamespace *connect.Client[v1.UnregisterNamespaceRequest, v1.UnregisterNamespaceResponse] + listNamespace *connect.Client[v1.ListNamespaceRequest, v1.ListNamespaceResponse] +} + +// RegisterNamespace calls postfinance.discovery.v1.NamespaceAPI.RegisterNamespace. +func (c *namespaceAPIClient) RegisterNamespace(ctx context.Context, req *connect.Request[v1.RegisterNamespaceRequest]) (*connect.Response[v1.RegisterNamespaceResponse], error) { + return c.registerNamespace.CallUnary(ctx, req) +} + +// UnregisterNamespace calls postfinance.discovery.v1.NamespaceAPI.UnregisterNamespace. +func (c *namespaceAPIClient) UnregisterNamespace(ctx context.Context, req *connect.Request[v1.UnregisterNamespaceRequest]) (*connect.Response[v1.UnregisterNamespaceResponse], error) { + return c.unregisterNamespace.CallUnary(ctx, req) +} + +// ListNamespace calls postfinance.discovery.v1.NamespaceAPI.ListNamespace. +func (c *namespaceAPIClient) ListNamespace(ctx context.Context, req *connect.Request[v1.ListNamespaceRequest]) (*connect.Response[v1.ListNamespaceResponse], error) { + return c.listNamespace.CallUnary(ctx, req) +} + +// NamespaceAPIHandler is an implementation of the postfinance.discovery.v1.NamespaceAPI service. +type NamespaceAPIHandler interface { + // RegisterNamespace registers a namespace. + RegisterNamespace(context.Context, *connect.Request[v1.RegisterNamespaceRequest]) (*connect.Response[v1.RegisterNamespaceResponse], error) + // UnRegisterNamespace unregisters a namespace. + UnregisterNamespace(context.Context, *connect.Request[v1.UnregisterNamespaceRequest]) (*connect.Response[v1.UnregisterNamespaceResponse], error) + // ListNamespace lists all namespaces. + ListNamespace(context.Context, *connect.Request[v1.ListNamespaceRequest]) (*connect.Response[v1.ListNamespaceResponse], error) +} + +// NewNamespaceAPIHandler builds an HTTP handler from the service implementation. It returns the +// path on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewNamespaceAPIHandler(svc NamespaceAPIHandler, opts ...connect.HandlerOption) (string, http.Handler) { + namespaceAPIRegisterNamespaceHandler := connect.NewUnaryHandler( + NamespaceAPIRegisterNamespaceProcedure, + svc.RegisterNamespace, + connect.WithSchema(namespaceAPIRegisterNamespaceMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + namespaceAPIUnregisterNamespaceHandler := connect.NewUnaryHandler( + NamespaceAPIUnregisterNamespaceProcedure, + svc.UnregisterNamespace, + connect.WithSchema(namespaceAPIUnregisterNamespaceMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + namespaceAPIListNamespaceHandler := connect.NewUnaryHandler( + NamespaceAPIListNamespaceProcedure, + svc.ListNamespace, + connect.WithSchema(namespaceAPIListNamespaceMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/postfinance.discovery.v1.NamespaceAPI/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case NamespaceAPIRegisterNamespaceProcedure: + namespaceAPIRegisterNamespaceHandler.ServeHTTP(w, r) + case NamespaceAPIUnregisterNamespaceProcedure: + namespaceAPIUnregisterNamespaceHandler.ServeHTTP(w, r) + case NamespaceAPIListNamespaceProcedure: + namespaceAPIListNamespaceHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedNamespaceAPIHandler returns CodeUnimplemented from all methods. +type UnimplementedNamespaceAPIHandler struct{} + +func (UnimplementedNamespaceAPIHandler) RegisterNamespace(context.Context, *connect.Request[v1.RegisterNamespaceRequest]) (*connect.Response[v1.RegisterNamespaceResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("postfinance.discovery.v1.NamespaceAPI.RegisterNamespace is not implemented")) +} + +func (UnimplementedNamespaceAPIHandler) UnregisterNamespace(context.Context, *connect.Request[v1.UnregisterNamespaceRequest]) (*connect.Response[v1.UnregisterNamespaceResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("postfinance.discovery.v1.NamespaceAPI.UnregisterNamespace is not implemented")) +} + +func (UnimplementedNamespaceAPIHandler) ListNamespace(context.Context, *connect.Request[v1.ListNamespaceRequest]) (*connect.Response[v1.ListNamespaceResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("postfinance.discovery.v1.NamespaceAPI.ListNamespace is not implemented")) +} diff --git a/pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect/server_api.connect.go b/pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect/server_api.connect.go new file mode 100644 index 0000000..59a581a --- /dev/null +++ b/pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect/server_api.connect.go @@ -0,0 +1,178 @@ +// Code generated by protoc-gen-connect-go. DO NOT EDIT. +// +// Source: postfinance/discovery/v1/server_api.proto + +package discoveryv1connect + +import ( + connect "connectrpc.com/connect" + context "context" + errors "errors" + http "net/http" + v1 "postfinance/discovery/v1" + strings "strings" +) + +// This is a compile-time assertion to ensure that this generated file and the connect package are +// compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of connect newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of connect or updating the connect +// version compiled into your binary. +const _ = connect.IsAtLeastVersion1_13_0 + +const ( + // ServerAPIName is the fully-qualified name of the ServerAPI service. + ServerAPIName = "postfinance.discovery.v1.ServerAPI" +) + +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period. +const ( + // ServerAPIRegisterServerProcedure is the fully-qualified name of the ServerAPI's RegisterServer + // RPC. + ServerAPIRegisterServerProcedure = "/postfinance.discovery.v1.ServerAPI/RegisterServer" + // ServerAPIUnregisterServerProcedure is the fully-qualified name of the ServerAPI's + // UnregisterServer RPC. + ServerAPIUnregisterServerProcedure = "/postfinance.discovery.v1.ServerAPI/UnregisterServer" + // ServerAPIListServerProcedure is the fully-qualified name of the ServerAPI's ListServer RPC. + ServerAPIListServerProcedure = "/postfinance.discovery.v1.ServerAPI/ListServer" +) + +// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. +var ( + serverAPIServiceDescriptor = v1.File_postfinance_discovery_v1_server_api_proto.Services().ByName("ServerAPI") + serverAPIRegisterServerMethodDescriptor = serverAPIServiceDescriptor.Methods().ByName("RegisterServer") + serverAPIUnregisterServerMethodDescriptor = serverAPIServiceDescriptor.Methods().ByName("UnregisterServer") + serverAPIListServerMethodDescriptor = serverAPIServiceDescriptor.Methods().ByName("ListServer") +) + +// ServerAPIClient is a client for the postfinance.discovery.v1.ServerAPI service. +type ServerAPIClient interface { + // RegisterServer registers a server. + RegisterServer(context.Context, *connect.Request[v1.RegisterServerRequest]) (*connect.Response[v1.RegisterServerResponse], error) + // UnRegisterServer unregisters a server. + UnregisterServer(context.Context, *connect.Request[v1.UnregisterServerRequest]) (*connect.Response[v1.UnregisterServerResponse], error) + // ListServer lists all servers. + ListServer(context.Context, *connect.Request[v1.ListServerRequest]) (*connect.Response[v1.ListServerResponse], error) +} + +// NewServerAPIClient constructs a client for the postfinance.discovery.v1.ServerAPI service. By +// default, it uses the Connect protocol with the binary Protobuf Codec, asks for gzipped responses, +// and sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the +// connect.WithGRPC() or connect.WithGRPCWeb() options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewServerAPIClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) ServerAPIClient { + baseURL = strings.TrimRight(baseURL, "/") + return &serverAPIClient{ + registerServer: connect.NewClient[v1.RegisterServerRequest, v1.RegisterServerResponse]( + httpClient, + baseURL+ServerAPIRegisterServerProcedure, + connect.WithSchema(serverAPIRegisterServerMethodDescriptor), + connect.WithClientOptions(opts...), + ), + unregisterServer: connect.NewClient[v1.UnregisterServerRequest, v1.UnregisterServerResponse]( + httpClient, + baseURL+ServerAPIUnregisterServerProcedure, + connect.WithSchema(serverAPIUnregisterServerMethodDescriptor), + connect.WithClientOptions(opts...), + ), + listServer: connect.NewClient[v1.ListServerRequest, v1.ListServerResponse]( + httpClient, + baseURL+ServerAPIListServerProcedure, + connect.WithSchema(serverAPIListServerMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// serverAPIClient implements ServerAPIClient. +type serverAPIClient struct { + registerServer *connect.Client[v1.RegisterServerRequest, v1.RegisterServerResponse] + unregisterServer *connect.Client[v1.UnregisterServerRequest, v1.UnregisterServerResponse] + listServer *connect.Client[v1.ListServerRequest, v1.ListServerResponse] +} + +// RegisterServer calls postfinance.discovery.v1.ServerAPI.RegisterServer. +func (c *serverAPIClient) RegisterServer(ctx context.Context, req *connect.Request[v1.RegisterServerRequest]) (*connect.Response[v1.RegisterServerResponse], error) { + return c.registerServer.CallUnary(ctx, req) +} + +// UnregisterServer calls postfinance.discovery.v1.ServerAPI.UnregisterServer. +func (c *serverAPIClient) UnregisterServer(ctx context.Context, req *connect.Request[v1.UnregisterServerRequest]) (*connect.Response[v1.UnregisterServerResponse], error) { + return c.unregisterServer.CallUnary(ctx, req) +} + +// ListServer calls postfinance.discovery.v1.ServerAPI.ListServer. +func (c *serverAPIClient) ListServer(ctx context.Context, req *connect.Request[v1.ListServerRequest]) (*connect.Response[v1.ListServerResponse], error) { + return c.listServer.CallUnary(ctx, req) +} + +// ServerAPIHandler is an implementation of the postfinance.discovery.v1.ServerAPI service. +type ServerAPIHandler interface { + // RegisterServer registers a server. + RegisterServer(context.Context, *connect.Request[v1.RegisterServerRequest]) (*connect.Response[v1.RegisterServerResponse], error) + // UnRegisterServer unregisters a server. + UnregisterServer(context.Context, *connect.Request[v1.UnregisterServerRequest]) (*connect.Response[v1.UnregisterServerResponse], error) + // ListServer lists all servers. + ListServer(context.Context, *connect.Request[v1.ListServerRequest]) (*connect.Response[v1.ListServerResponse], error) +} + +// NewServerAPIHandler builds an HTTP handler from the service implementation. It returns the path +// on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewServerAPIHandler(svc ServerAPIHandler, opts ...connect.HandlerOption) (string, http.Handler) { + serverAPIRegisterServerHandler := connect.NewUnaryHandler( + ServerAPIRegisterServerProcedure, + svc.RegisterServer, + connect.WithSchema(serverAPIRegisterServerMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + serverAPIUnregisterServerHandler := connect.NewUnaryHandler( + ServerAPIUnregisterServerProcedure, + svc.UnregisterServer, + connect.WithSchema(serverAPIUnregisterServerMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + serverAPIListServerHandler := connect.NewUnaryHandler( + ServerAPIListServerProcedure, + svc.ListServer, + connect.WithSchema(serverAPIListServerMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/postfinance.discovery.v1.ServerAPI/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case ServerAPIRegisterServerProcedure: + serverAPIRegisterServerHandler.ServeHTTP(w, r) + case ServerAPIUnregisterServerProcedure: + serverAPIUnregisterServerHandler.ServeHTTP(w, r) + case ServerAPIListServerProcedure: + serverAPIListServerHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedServerAPIHandler returns CodeUnimplemented from all methods. +type UnimplementedServerAPIHandler struct{} + +func (UnimplementedServerAPIHandler) RegisterServer(context.Context, *connect.Request[v1.RegisterServerRequest]) (*connect.Response[v1.RegisterServerResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("postfinance.discovery.v1.ServerAPI.RegisterServer is not implemented")) +} + +func (UnimplementedServerAPIHandler) UnregisterServer(context.Context, *connect.Request[v1.UnregisterServerRequest]) (*connect.Response[v1.UnregisterServerResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("postfinance.discovery.v1.ServerAPI.UnregisterServer is not implemented")) +} + +func (UnimplementedServerAPIHandler) ListServer(context.Context, *connect.Request[v1.ListServerRequest]) (*connect.Response[v1.ListServerResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("postfinance.discovery.v1.ServerAPI.ListServer is not implemented")) +} diff --git a/pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect/service_api.connect.go b/pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect/service_api.connect.go new file mode 100644 index 0000000..8cf85de --- /dev/null +++ b/pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect/service_api.connect.go @@ -0,0 +1,214 @@ +// Code generated by protoc-gen-connect-go. DO NOT EDIT. +// +// Source: postfinance/discovery/v1/service_api.proto + +package discoveryv1connect + +import ( + connect "connectrpc.com/connect" + context "context" + errors "errors" + http "net/http" + v1 "postfinance/discovery/v1" + strings "strings" +) + +// This is a compile-time assertion to ensure that this generated file and the connect package are +// compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of connect newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of connect or updating the connect +// version compiled into your binary. +const _ = connect.IsAtLeastVersion1_13_0 + +const ( + // ServiceAPIName is the fully-qualified name of the ServiceAPI service. + ServiceAPIName = "postfinance.discovery.v1.ServiceAPI" +) + +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period. +const ( + // ServiceAPIRegisterServiceProcedure is the fully-qualified name of the ServiceAPI's + // RegisterService RPC. + ServiceAPIRegisterServiceProcedure = "/postfinance.discovery.v1.ServiceAPI/RegisterService" + // ServiceAPIUnRegisterServiceProcedure is the fully-qualified name of the ServiceAPI's + // UnRegisterService RPC. + ServiceAPIUnRegisterServiceProcedure = "/postfinance.discovery.v1.ServiceAPI/UnRegisterService" + // ServiceAPIListServiceProcedure is the fully-qualified name of the ServiceAPI's ListService RPC. + ServiceAPIListServiceProcedure = "/postfinance.discovery.v1.ServiceAPI/ListService" + // ServiceAPIListTargetGroupProcedure is the fully-qualified name of the ServiceAPI's + // ListTargetGroup RPC. + ServiceAPIListTargetGroupProcedure = "/postfinance.discovery.v1.ServiceAPI/ListTargetGroup" +) + +// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. +var ( + serviceAPIServiceDescriptor = v1.File_postfinance_discovery_v1_service_api_proto.Services().ByName("ServiceAPI") + serviceAPIRegisterServiceMethodDescriptor = serviceAPIServiceDescriptor.Methods().ByName("RegisterService") + serviceAPIUnRegisterServiceMethodDescriptor = serviceAPIServiceDescriptor.Methods().ByName("UnRegisterService") + serviceAPIListServiceMethodDescriptor = serviceAPIServiceDescriptor.Methods().ByName("ListService") + serviceAPIListTargetGroupMethodDescriptor = serviceAPIServiceDescriptor.Methods().ByName("ListTargetGroup") +) + +// ServiceAPIClient is a client for the postfinance.discovery.v1.ServiceAPI service. +type ServiceAPIClient interface { + // RegisterService registers a service. + RegisterService(context.Context, *connect.Request[v1.RegisterServiceRequest]) (*connect.Response[v1.RegisterServiceResponse], error) + // UnRegisterService unregisters a service. + UnRegisterService(context.Context, *connect.Request[v1.UnRegisterServiceRequest]) (*connect.Response[v1.UnRegisterServiceResponse], error) + // ListService lists all services. + ListService(context.Context, *connect.Request[v1.ListServiceRequest]) (*connect.Response[v1.ListServiceResponse], error) + // ListTargetGroup converts services to prometheus target groups. Those can + // be used for http_sd (see: https://prometheus.io/docs/prometheus/latest/http_sd/ + // for more information). + ListTargetGroup(context.Context, *connect.Request[v1.ListTargetGroupRequest]) (*connect.Response[v1.ListTargetGroupResponse], error) +} + +// NewServiceAPIClient constructs a client for the postfinance.discovery.v1.ServiceAPI service. By +// default, it uses the Connect protocol with the binary Protobuf Codec, asks for gzipped responses, +// and sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the +// connect.WithGRPC() or connect.WithGRPCWeb() options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewServiceAPIClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) ServiceAPIClient { + baseURL = strings.TrimRight(baseURL, "/") + return &serviceAPIClient{ + registerService: connect.NewClient[v1.RegisterServiceRequest, v1.RegisterServiceResponse]( + httpClient, + baseURL+ServiceAPIRegisterServiceProcedure, + connect.WithSchema(serviceAPIRegisterServiceMethodDescriptor), + connect.WithClientOptions(opts...), + ), + unRegisterService: connect.NewClient[v1.UnRegisterServiceRequest, v1.UnRegisterServiceResponse]( + httpClient, + baseURL+ServiceAPIUnRegisterServiceProcedure, + connect.WithSchema(serviceAPIUnRegisterServiceMethodDescriptor), + connect.WithClientOptions(opts...), + ), + listService: connect.NewClient[v1.ListServiceRequest, v1.ListServiceResponse]( + httpClient, + baseURL+ServiceAPIListServiceProcedure, + connect.WithSchema(serviceAPIListServiceMethodDescriptor), + connect.WithClientOptions(opts...), + ), + listTargetGroup: connect.NewClient[v1.ListTargetGroupRequest, v1.ListTargetGroupResponse]( + httpClient, + baseURL+ServiceAPIListTargetGroupProcedure, + connect.WithSchema(serviceAPIListTargetGroupMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// serviceAPIClient implements ServiceAPIClient. +type serviceAPIClient struct { + registerService *connect.Client[v1.RegisterServiceRequest, v1.RegisterServiceResponse] + unRegisterService *connect.Client[v1.UnRegisterServiceRequest, v1.UnRegisterServiceResponse] + listService *connect.Client[v1.ListServiceRequest, v1.ListServiceResponse] + listTargetGroup *connect.Client[v1.ListTargetGroupRequest, v1.ListTargetGroupResponse] +} + +// RegisterService calls postfinance.discovery.v1.ServiceAPI.RegisterService. +func (c *serviceAPIClient) RegisterService(ctx context.Context, req *connect.Request[v1.RegisterServiceRequest]) (*connect.Response[v1.RegisterServiceResponse], error) { + return c.registerService.CallUnary(ctx, req) +} + +// UnRegisterService calls postfinance.discovery.v1.ServiceAPI.UnRegisterService. +func (c *serviceAPIClient) UnRegisterService(ctx context.Context, req *connect.Request[v1.UnRegisterServiceRequest]) (*connect.Response[v1.UnRegisterServiceResponse], error) { + return c.unRegisterService.CallUnary(ctx, req) +} + +// ListService calls postfinance.discovery.v1.ServiceAPI.ListService. +func (c *serviceAPIClient) ListService(ctx context.Context, req *connect.Request[v1.ListServiceRequest]) (*connect.Response[v1.ListServiceResponse], error) { + return c.listService.CallUnary(ctx, req) +} + +// ListTargetGroup calls postfinance.discovery.v1.ServiceAPI.ListTargetGroup. +func (c *serviceAPIClient) ListTargetGroup(ctx context.Context, req *connect.Request[v1.ListTargetGroupRequest]) (*connect.Response[v1.ListTargetGroupResponse], error) { + return c.listTargetGroup.CallUnary(ctx, req) +} + +// ServiceAPIHandler is an implementation of the postfinance.discovery.v1.ServiceAPI service. +type ServiceAPIHandler interface { + // RegisterService registers a service. + RegisterService(context.Context, *connect.Request[v1.RegisterServiceRequest]) (*connect.Response[v1.RegisterServiceResponse], error) + // UnRegisterService unregisters a service. + UnRegisterService(context.Context, *connect.Request[v1.UnRegisterServiceRequest]) (*connect.Response[v1.UnRegisterServiceResponse], error) + // ListService lists all services. + ListService(context.Context, *connect.Request[v1.ListServiceRequest]) (*connect.Response[v1.ListServiceResponse], error) + // ListTargetGroup converts services to prometheus target groups. Those can + // be used for http_sd (see: https://prometheus.io/docs/prometheus/latest/http_sd/ + // for more information). + ListTargetGroup(context.Context, *connect.Request[v1.ListTargetGroupRequest]) (*connect.Response[v1.ListTargetGroupResponse], error) +} + +// NewServiceAPIHandler builds an HTTP handler from the service implementation. It returns the path +// on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewServiceAPIHandler(svc ServiceAPIHandler, opts ...connect.HandlerOption) (string, http.Handler) { + serviceAPIRegisterServiceHandler := connect.NewUnaryHandler( + ServiceAPIRegisterServiceProcedure, + svc.RegisterService, + connect.WithSchema(serviceAPIRegisterServiceMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + serviceAPIUnRegisterServiceHandler := connect.NewUnaryHandler( + ServiceAPIUnRegisterServiceProcedure, + svc.UnRegisterService, + connect.WithSchema(serviceAPIUnRegisterServiceMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + serviceAPIListServiceHandler := connect.NewUnaryHandler( + ServiceAPIListServiceProcedure, + svc.ListService, + connect.WithSchema(serviceAPIListServiceMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + serviceAPIListTargetGroupHandler := connect.NewUnaryHandler( + ServiceAPIListTargetGroupProcedure, + svc.ListTargetGroup, + connect.WithSchema(serviceAPIListTargetGroupMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/postfinance.discovery.v1.ServiceAPI/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case ServiceAPIRegisterServiceProcedure: + serviceAPIRegisterServiceHandler.ServeHTTP(w, r) + case ServiceAPIUnRegisterServiceProcedure: + serviceAPIUnRegisterServiceHandler.ServeHTTP(w, r) + case ServiceAPIListServiceProcedure: + serviceAPIListServiceHandler.ServeHTTP(w, r) + case ServiceAPIListTargetGroupProcedure: + serviceAPIListTargetGroupHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedServiceAPIHandler returns CodeUnimplemented from all methods. +type UnimplementedServiceAPIHandler struct{} + +func (UnimplementedServiceAPIHandler) RegisterService(context.Context, *connect.Request[v1.RegisterServiceRequest]) (*connect.Response[v1.RegisterServiceResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("postfinance.discovery.v1.ServiceAPI.RegisterService is not implemented")) +} + +func (UnimplementedServiceAPIHandler) UnRegisterService(context.Context, *connect.Request[v1.UnRegisterServiceRequest]) (*connect.Response[v1.UnRegisterServiceResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("postfinance.discovery.v1.ServiceAPI.UnRegisterService is not implemented")) +} + +func (UnimplementedServiceAPIHandler) ListService(context.Context, *connect.Request[v1.ListServiceRequest]) (*connect.Response[v1.ListServiceResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("postfinance.discovery.v1.ServiceAPI.ListService is not implemented")) +} + +func (UnimplementedServiceAPIHandler) ListTargetGroup(context.Context, *connect.Request[v1.ListTargetGroupRequest]) (*connect.Response[v1.ListTargetGroupResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("postfinance.discovery.v1.ServiceAPI.ListTargetGroup is not implemented")) +} diff --git a/pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect/token_api.connect.go b/pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect/token_api.connect.go new file mode 100644 index 0000000..f163c64 --- /dev/null +++ b/pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect/token_api.connect.go @@ -0,0 +1,145 @@ +// Code generated by protoc-gen-connect-go. DO NOT EDIT. +// +// Source: postfinance/discovery/v1/token_api.proto + +package discoveryv1connect + +import ( + connect "connectrpc.com/connect" + context "context" + errors "errors" + http "net/http" + v1 "postfinance/discovery/v1" + strings "strings" +) + +// This is a compile-time assertion to ensure that this generated file and the connect package are +// compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of connect newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of connect or updating the connect +// version compiled into your binary. +const _ = connect.IsAtLeastVersion1_13_0 + +const ( + // TokenAPIName is the fully-qualified name of the TokenAPI service. + TokenAPIName = "postfinance.discovery.v1.TokenAPI" +) + +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period. +const ( + // TokenAPICreateProcedure is the fully-qualified name of the TokenAPI's Create RPC. + TokenAPICreateProcedure = "/postfinance.discovery.v1.TokenAPI/Create" + // TokenAPIInfoProcedure is the fully-qualified name of the TokenAPI's Info RPC. + TokenAPIInfoProcedure = "/postfinance.discovery.v1.TokenAPI/Info" +) + +// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. +var ( + tokenAPIServiceDescriptor = v1.File_postfinance_discovery_v1_token_api_proto.Services().ByName("TokenAPI") + tokenAPICreateMethodDescriptor = tokenAPIServiceDescriptor.Methods().ByName("Create") + tokenAPIInfoMethodDescriptor = tokenAPIServiceDescriptor.Methods().ByName("Info") +) + +// TokenAPIClient is a client for the postfinance.discovery.v1.TokenAPI service. +type TokenAPIClient interface { + // Create creates a token. + Create(context.Context, *connect.Request[v1.CreateRequest]) (*connect.Response[v1.CreateResponse], error) + // Info gives token information. + Info(context.Context, *connect.Request[v1.InfoRequest]) (*connect.Response[v1.InfoResponse], error) +} + +// NewTokenAPIClient constructs a client for the postfinance.discovery.v1.TokenAPI service. By +// default, it uses the Connect protocol with the binary Protobuf Codec, asks for gzipped responses, +// and sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the +// connect.WithGRPC() or connect.WithGRPCWeb() options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewTokenAPIClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) TokenAPIClient { + baseURL = strings.TrimRight(baseURL, "/") + return &tokenAPIClient{ + create: connect.NewClient[v1.CreateRequest, v1.CreateResponse]( + httpClient, + baseURL+TokenAPICreateProcedure, + connect.WithSchema(tokenAPICreateMethodDescriptor), + connect.WithClientOptions(opts...), + ), + info: connect.NewClient[v1.InfoRequest, v1.InfoResponse]( + httpClient, + baseURL+TokenAPIInfoProcedure, + connect.WithSchema(tokenAPIInfoMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// tokenAPIClient implements TokenAPIClient. +type tokenAPIClient struct { + create *connect.Client[v1.CreateRequest, v1.CreateResponse] + info *connect.Client[v1.InfoRequest, v1.InfoResponse] +} + +// Create calls postfinance.discovery.v1.TokenAPI.Create. +func (c *tokenAPIClient) Create(ctx context.Context, req *connect.Request[v1.CreateRequest]) (*connect.Response[v1.CreateResponse], error) { + return c.create.CallUnary(ctx, req) +} + +// Info calls postfinance.discovery.v1.TokenAPI.Info. +func (c *tokenAPIClient) Info(ctx context.Context, req *connect.Request[v1.InfoRequest]) (*connect.Response[v1.InfoResponse], error) { + return c.info.CallUnary(ctx, req) +} + +// TokenAPIHandler is an implementation of the postfinance.discovery.v1.TokenAPI service. +type TokenAPIHandler interface { + // Create creates a token. + Create(context.Context, *connect.Request[v1.CreateRequest]) (*connect.Response[v1.CreateResponse], error) + // Info gives token information. + Info(context.Context, *connect.Request[v1.InfoRequest]) (*connect.Response[v1.InfoResponse], error) +} + +// NewTokenAPIHandler builds an HTTP handler from the service implementation. It returns the path on +// which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewTokenAPIHandler(svc TokenAPIHandler, opts ...connect.HandlerOption) (string, http.Handler) { + tokenAPICreateHandler := connect.NewUnaryHandler( + TokenAPICreateProcedure, + svc.Create, + connect.WithSchema(tokenAPICreateMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + tokenAPIInfoHandler := connect.NewUnaryHandler( + TokenAPIInfoProcedure, + svc.Info, + connect.WithSchema(tokenAPIInfoMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/postfinance.discovery.v1.TokenAPI/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case TokenAPICreateProcedure: + tokenAPICreateHandler.ServeHTTP(w, r) + case TokenAPIInfoProcedure: + tokenAPIInfoHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedTokenAPIHandler returns CodeUnimplemented from all methods. +type UnimplementedTokenAPIHandler struct{} + +func (UnimplementedTokenAPIHandler) Create(context.Context, *connect.Request[v1.CreateRequest]) (*connect.Response[v1.CreateResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("postfinance.discovery.v1.TokenAPI.Create is not implemented")) +} + +func (UnimplementedTokenAPIHandler) Info(context.Context, *connect.Request[v1.InfoRequest]) (*connect.Response[v1.InfoResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("postfinance.discovery.v1.TokenAPI.Info is not implemented")) +} diff --git a/tools.go b/tools.go index d7f5f8a..554c177 100644 --- a/tools.go +++ b/tools.go @@ -1,10 +1,9 @@ //go:build tools // +build tools -package proto +package discovery import ( _ "connectrpc.com/connect" - _ "google.golang.org/grpc/cmd/protoc-gen-go-grpc" _ "google.golang.org/protobuf/cmd/protoc-gen-go" )