diff --git a/buf.gen.yaml b/buf.gen.yaml index 656df40..c782005 100644 --- a/buf.gen.yaml +++ b/buf.gen.yaml @@ -1,8 +1,8 @@ version: v2 plugins: - remote: buf.build/protocolbuffers/go:v1.34.2 - out: . + out: proto opt: paths=source_relative - - remote: buf.build/grpc/go:v1.5.1 - out: . + - remote: buf.build/connectrpc/go:v1.16.2 + out: proto opt: paths=source_relative diff --git a/cmd/frontend/main.go b/cmd/frontend/main.go index af47395..abec634 100644 --- a/cmd/frontend/main.go +++ b/cmd/frontend/main.go @@ -2,20 +2,25 @@ package main import ( "context" + "errors" "flag" "fmt" "log" - "net" + "log/slog" + "net/http" - "google.golang.org/grpc" + "connectrpc.com/grpchealth" + "connectrpc.com/grpcreflect" + "golang.org/x/net/http2" + "golang.org/x/net/http2/h2c" "github.com/rajatgoel/gh-go/internal/frontend" "github.com/rajatgoel/gh-go/internal/sqlbackend" - frontendpb "github.com/rajatgoel/gh-go/proto/frontend/v1" + frontendv1connect "github.com/rajatgoel/gh-go/proto/frontend/v1/v1connect" ) func main() { - port := flag.Int("port", 50051, "The server port") + port := flag.Int("port", 5051, "The server port") flag.Parse() ctx := context.Background() @@ -23,16 +28,26 @@ func main() { if err != nil { log.Fatalf("failed to create backend: %v", err) } - handler := frontend.New(backend) + path, handler := frontendv1connect.NewFrontendServiceHandler(frontend.New(backend)) - lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) - if err != nil { - log.Fatalf("failed to listen: %v", err) + mux := http.NewServeMux() + mux.Handle(path, handler) + + // health check + checker := grpchealth.NewStaticChecker(frontendv1connect.FrontendServiceName) + mux.Handle(grpchealth.NewHandler(checker)) + + // reflect + reflector := grpcreflect.NewStaticReflector(frontendv1connect.FrontendServiceName) + mux.Handle(grpcreflect.NewHandlerV1(reflector)) + + server := &http.Server{ + Addr: fmt.Sprintf("127.0.0.1:%d", *port), + Handler: h2c.NewHandler(mux, &http2.Server{}), } - s := grpc.NewServer() - frontendpb.RegisterFrontendServiceServer(s, handler) - if err := s.Serve(lis); err != nil { - log.Fatalf("failed to serve: %v", err) + slog.Info("starting server", "port", *port, "path", path) + if err := server.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) { + log.Fatalf("failed to start server: %v", err) } } diff --git a/go.mod b/go.mod index f859f9f..9149cd2 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,16 @@ module github.com/rajatgoel/gh-go go 1.23.0 require ( + connectrpc.com/connect v1.16.2 + connectrpc.com/grpchealth v1.3.0 + connectrpc.com/grpcreflect v1.2.0 github.com/bufbuild/buf v1.36.0 github.com/golangci/golangci-lint v1.60.0 github.com/sqlc-dev/sqlc v1.26.0 github.com/stretchr/testify v1.9.0 + golang.org/x/net v0.28.0 golang.org/x/tools v0.24.0 golang.org/x/vuln v1.1.2 - google.golang.org/grpc v1.64.1 google.golang.org/protobuf v1.34.2 modernc.org/sqlite v1.30.1 ) @@ -20,7 +23,6 @@ require ( buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-20240717164558-a6c49f84cc0f.2 // indirect buf.build/gen/go/bufbuild/registry/connectrpc/go v1.16.2-20240801134127-09fbc17f7c9e.1 // indirect buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.34.2-20240801134127-09fbc17f7c9e.2 // indirect - connectrpc.com/connect v1.16.2 // indirect connectrpc.com/otelconnect v0.7.1 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/4meepo/tagalign v1.3.4 // indirect @@ -259,7 +261,6 @@ require ( golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect golang.org/x/exp/typeparams v0.0.0-20240314144324-c7f7c6466f7f // indirect golang.org/x/mod v0.20.0 // indirect - golang.org/x/net v0.28.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.24.0 // indirect golang.org/x/telemetry v0.0.0-20240522233618-39ace7a40ae7 // indirect @@ -267,6 +268,7 @@ require ( golang.org/x/text v0.17.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240812133136-8ffd90a71988 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240812133136-8ffd90a71988 // indirect + google.golang.org/grpc v1.64.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index e38b6fc..36567ec 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,10 @@ buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.34.2-20240801134127-09f buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.34.2-20240801134127-09fbc17f7c9e.2/go.mod h1:psseUmlKRo9v5LZJtR/aTpdTLuyp9o3X7rnLT87SZEo= connectrpc.com/connect v1.16.2 h1:ybd6y+ls7GOlb7Bh5C8+ghA6SvCBajHwxssO2CGFjqE= connectrpc.com/connect v1.16.2/go.mod h1:n2kgwskMHXC+lVqb18wngEpF95ldBHXjZYJussz5FRc= +connectrpc.com/grpchealth v1.3.0 h1:FA3OIwAvuMokQIXQrY5LbIy8IenftksTP/lG4PbYN+E= +connectrpc.com/grpchealth v1.3.0/go.mod h1:3vpqmX25/ir0gVgW6RdnCPPZRcR6HvqtXX5RNPmDXHM= +connectrpc.com/grpcreflect v1.2.0 h1:Q6og1S7HinmtbEuBvARLNwYmTbhEGRpHDhqrPNlmK+U= +connectrpc.com/grpcreflect v1.2.0/go.mod h1:nwSOKmE8nU5u/CidgHtPYk1PFI3U9ignz7iDMxOYkSY= connectrpc.com/otelconnect v0.7.1 h1:scO5pOb0i4yUE66CnNrHeK1x51yq0bE0ehPg6WvzXJY= connectrpc.com/otelconnect v0.7.1/go.mod h1:dh3bFgHBTb2bkqGCeVVOtHJreSns7uu9wwL2Tbz17ms= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= diff --git a/internal/frontend/handler.go b/internal/frontend/handler.go index f5149ab..8bc0e75 100644 --- a/internal/frontend/handler.go +++ b/internal/frontend/handler.go @@ -3,32 +3,35 @@ package frontend import ( "context" + "connectrpc.com/connect" + "github.com/rajatgoel/gh-go/internal/sqlbackend" frontendpb "github.com/rajatgoel/gh-go/proto/frontend/v1" + frontendv1connect "github.com/rajatgoel/gh-go/proto/frontend/v1/v1connect" ) type handler struct { - frontendpb.UnimplementedFrontendServiceServer + frontendv1connect.UnimplementedFrontendServiceHandler backend sqlbackend.Backend } func (h *handler) Put( ctx context.Context, - req *frontendpb.PutRequest, -) (*frontendpb.PutResponse, error) { - h.backend.Put(ctx, req.Key, req.Value) - return &frontendpb.PutResponse{}, nil + req *connect.Request[frontendpb.PutRequest], +) (*connect.Response[frontendpb.PutResponse], error) { + h.backend.Put(ctx, req.Msg.Key, req.Msg.Value) + return connect.NewResponse(&frontendpb.PutResponse{}), nil } func (h *handler) Get( ctx context.Context, - req *frontendpb.GetRequest, -) (*frontendpb.GetResponse, error) { - value := h.backend.Get(ctx, req.Key) - return &frontendpb.GetResponse{Value: value}, nil + req *connect.Request[frontendpb.GetRequest], +) (*connect.Response[frontendpb.GetResponse], error) { + value := h.backend.Get(ctx, req.Msg.Key) + return connect.NewResponse(&frontendpb.GetResponse{Value: value}), nil } -func New(backend sqlbackend.Backend) frontendpb.FrontendServiceServer { +func New(backend sqlbackend.Backend) frontendv1connect.FrontendServiceHandler { return &handler{backend: backend} } diff --git a/itest/frontend_test.go b/itest/frontend_test.go index 785e62b..8726d2b 100644 --- a/itest/frontend_test.go +++ b/itest/frontend_test.go @@ -2,30 +2,46 @@ package itest import ( "context" + "net/http" + "net/http/httptest" "testing" + "connectrpc.com/connect" "github.com/stretchr/testify/require" "github.com/rajatgoel/gh-go/internal/frontend" "github.com/rajatgoel/gh-go/internal/sqlbackend" frontendpb "github.com/rajatgoel/gh-go/proto/frontend/v1" + frontendv1connect "github.com/rajatgoel/gh-go/proto/frontend/v1/v1connect" ) func TestStub(t *testing.T) { b, err := sqlbackend.New(context.Background()) require.NoError(t, err) - h := frontend.New(b) + + mux := http.NewServeMux() + mux.Handle(frontendv1connect.NewFrontendServiceHandler(frontend.New(b))) + server := httptest.NewServer(mux) + t.Cleanup(func() { server.Close() }) key, value := int64(1), "value" - _, err = h.Put(context.Background(), &frontendpb.PutRequest{ + client := frontendv1connect.NewFrontendServiceClient(http.DefaultClient, server.URL) + + resp, err := client.Get(context.Background(), connect.NewRequest(&frontendpb.GetRequest{ + Key: key, + })) + require.NoError(t, err) + require.Empty(t, resp.Msg.Value) + + _, err = client.Put(context.Background(), connect.NewRequest(&frontendpb.PutRequest{ Key: key, Value: value, - }) + })) require.NoError(t, err) - resp, err := h.Get(context.Background(), &frontendpb.GetRequest{ + resp, err = client.Get(context.Background(), connect.NewRequest(&frontendpb.GetRequest{ Key: key, - }) + })) require.NoError(t, err) - require.Equal(t, value, resp.Value) + require.Equal(t, value, resp.Msg.Value) } diff --git a/proto/frontend/v1/service.pb.go b/proto/frontend/v1/service.pb.go index e0ea590..4d890a1 100644 --- a/proto/frontend/v1/service.pb.go +++ b/proto/frontend/v1/service.pb.go @@ -2,7 +2,7 @@ // versions: // protoc-gen-go v1.34.2 // protoc (unknown) -// source: proto/frontend/v1/service.proto +// source: frontend/v1/service.proto package v1 @@ -32,7 +32,7 @@ type PutRequest struct { func (x *PutRequest) Reset() { *x = PutRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_frontend_v1_service_proto_msgTypes[0] + mi := &file_frontend_v1_service_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -45,7 +45,7 @@ func (x *PutRequest) String() string { func (*PutRequest) ProtoMessage() {} func (x *PutRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_frontend_v1_service_proto_msgTypes[0] + mi := &file_frontend_v1_service_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -58,7 +58,7 @@ func (x *PutRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PutRequest.ProtoReflect.Descriptor instead. func (*PutRequest) Descriptor() ([]byte, []int) { - return file_proto_frontend_v1_service_proto_rawDescGZIP(), []int{0} + return file_frontend_v1_service_proto_rawDescGZIP(), []int{0} } func (x *PutRequest) GetKey() int64 { @@ -84,7 +84,7 @@ type PutResponse struct { func (x *PutResponse) Reset() { *x = PutResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_frontend_v1_service_proto_msgTypes[1] + mi := &file_frontend_v1_service_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -97,7 +97,7 @@ func (x *PutResponse) String() string { func (*PutResponse) ProtoMessage() {} func (x *PutResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_frontend_v1_service_proto_msgTypes[1] + mi := &file_frontend_v1_service_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -110,7 +110,7 @@ func (x *PutResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PutResponse.ProtoReflect.Descriptor instead. func (*PutResponse) Descriptor() ([]byte, []int) { - return file_proto_frontend_v1_service_proto_rawDescGZIP(), []int{1} + return file_frontend_v1_service_proto_rawDescGZIP(), []int{1} } type GetRequest struct { @@ -124,7 +124,7 @@ type GetRequest struct { func (x *GetRequest) Reset() { *x = GetRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_frontend_v1_service_proto_msgTypes[2] + mi := &file_frontend_v1_service_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -137,7 +137,7 @@ func (x *GetRequest) String() string { func (*GetRequest) ProtoMessage() {} func (x *GetRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_frontend_v1_service_proto_msgTypes[2] + mi := &file_frontend_v1_service_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -150,7 +150,7 @@ func (x *GetRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetRequest.ProtoReflect.Descriptor instead. func (*GetRequest) Descriptor() ([]byte, []int) { - return file_proto_frontend_v1_service_proto_rawDescGZIP(), []int{2} + return file_frontend_v1_service_proto_rawDescGZIP(), []int{2} } func (x *GetRequest) GetKey() int64 { @@ -171,7 +171,7 @@ type GetResponse struct { func (x *GetResponse) Reset() { *x = GetResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_frontend_v1_service_proto_msgTypes[3] + mi := &file_frontend_v1_service_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -184,7 +184,7 @@ func (x *GetResponse) String() string { func (*GetResponse) ProtoMessage() {} func (x *GetResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_frontend_v1_service_proto_msgTypes[3] + mi := &file_frontend_v1_service_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -197,7 +197,7 @@ func (x *GetResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetResponse.ProtoReflect.Descriptor instead. func (*GetResponse) Descriptor() ([]byte, []int) { - return file_proto_frontend_v1_service_proto_rawDescGZIP(), []int{3} + return file_frontend_v1_service_proto_rawDescGZIP(), []int{3} } func (x *GetResponse) GetValue() string { @@ -207,55 +207,55 @@ func (x *GetResponse) GetValue() string { return "" } -var File_proto_frontend_v1_service_proto protoreflect.FileDescriptor - -var file_proto_frontend_v1_service_proto_rawDesc = []byte{ - 0x0a, 0x1f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, - 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x12, 0x0b, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x76, 0x31, 0x22, 0x34, - 0x0a, 0x0a, 0x50, 0x75, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, - 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, - 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x22, 0x0d, 0x0a, 0x0b, 0x50, 0x75, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x22, 0x1e, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, - 0x6b, 0x65, 0x79, 0x22, 0x23, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x32, 0x85, 0x01, 0x0a, 0x0f, 0x46, 0x72, 0x6f, - 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x38, 0x0a, 0x03, - 0x50, 0x75, 0x74, 0x12, 0x17, 0x2e, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x76, - 0x31, 0x2e, 0x50, 0x75, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x66, - 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x75, 0x74, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x38, 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, 0x17, 0x2e, - 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52, +var File_frontend_v1_service_proto protoreflect.FileDescriptor + +var file_frontend_v1_service_proto_rawDesc = []byte{ + 0x0a, 0x19, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x66, 0x72, 0x6f, + 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x76, 0x31, 0x22, 0x34, 0x0a, 0x0a, 0x50, 0x75, 0x74, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x0d, + 0x0a, 0x0b, 0x50, 0x75, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1e, 0x0a, + 0x0a, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, + 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x23, 0x0a, + 0x0b, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x32, 0x85, 0x01, 0x0a, 0x0f, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x38, 0x0a, 0x03, 0x50, 0x75, 0x74, 0x12, 0x17, 0x2e, + 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x75, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, - 0x64, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x42, 0x2e, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, - 0x61, 0x6a, 0x61, 0x74, 0x67, 0x6f, 0x65, 0x6c, 0x2f, 0x67, 0x68, 0x2d, 0x67, 0x6f, 0x2f, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2f, 0x76, 0x31, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x64, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x75, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x38, 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, 0x17, 0x2e, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, + 0x6e, 0x64, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x18, 0x2e, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x76, 0x31, 0x2e, 0x47, + 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x2e, 0x5a, 0x2c, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x61, 0x6a, 0x61, 0x74, 0x67, 0x6f, + 0x65, 0x6c, 0x2f, 0x67, 0x68, 0x2d, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x66, + 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( - file_proto_frontend_v1_service_proto_rawDescOnce sync.Once - file_proto_frontend_v1_service_proto_rawDescData = file_proto_frontend_v1_service_proto_rawDesc + file_frontend_v1_service_proto_rawDescOnce sync.Once + file_frontend_v1_service_proto_rawDescData = file_frontend_v1_service_proto_rawDesc ) -func file_proto_frontend_v1_service_proto_rawDescGZIP() []byte { - file_proto_frontend_v1_service_proto_rawDescOnce.Do(func() { - file_proto_frontend_v1_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_frontend_v1_service_proto_rawDescData) +func file_frontend_v1_service_proto_rawDescGZIP() []byte { + file_frontend_v1_service_proto_rawDescOnce.Do(func() { + file_frontend_v1_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_frontend_v1_service_proto_rawDescData) }) - return file_proto_frontend_v1_service_proto_rawDescData + return file_frontend_v1_service_proto_rawDescData } -var file_proto_frontend_v1_service_proto_msgTypes = make([]protoimpl.MessageInfo, 4) -var file_proto_frontend_v1_service_proto_goTypes = []any{ +var file_frontend_v1_service_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_frontend_v1_service_proto_goTypes = []any{ (*PutRequest)(nil), // 0: frontend.v1.PutRequest (*PutResponse)(nil), // 1: frontend.v1.PutResponse (*GetRequest)(nil), // 2: frontend.v1.GetRequest (*GetResponse)(nil), // 3: frontend.v1.GetResponse } -var file_proto_frontend_v1_service_proto_depIdxs = []int32{ +var file_frontend_v1_service_proto_depIdxs = []int32{ 0, // 0: frontend.v1.FrontendService.Put:input_type -> frontend.v1.PutRequest 2, // 1: frontend.v1.FrontendService.Get:input_type -> frontend.v1.GetRequest 1, // 2: frontend.v1.FrontendService.Put:output_type -> frontend.v1.PutResponse @@ -267,13 +267,13 @@ var file_proto_frontend_v1_service_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for field type_name } -func init() { file_proto_frontend_v1_service_proto_init() } -func file_proto_frontend_v1_service_proto_init() { - if File_proto_frontend_v1_service_proto != nil { +func init() { file_frontend_v1_service_proto_init() } +func file_frontend_v1_service_proto_init() { + if File_frontend_v1_service_proto != nil { return } if !protoimpl.UnsafeEnabled { - file_proto_frontend_v1_service_proto_msgTypes[0].Exporter = func(v any, i int) any { + file_frontend_v1_service_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*PutRequest); i { case 0: return &v.state @@ -285,7 +285,7 @@ func file_proto_frontend_v1_service_proto_init() { return nil } } - file_proto_frontend_v1_service_proto_msgTypes[1].Exporter = func(v any, i int) any { + file_frontend_v1_service_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*PutResponse); i { case 0: return &v.state @@ -297,7 +297,7 @@ func file_proto_frontend_v1_service_proto_init() { return nil } } - file_proto_frontend_v1_service_proto_msgTypes[2].Exporter = func(v any, i int) any { + file_frontend_v1_service_proto_msgTypes[2].Exporter = func(v any, i int) any { switch v := v.(*GetRequest); i { case 0: return &v.state @@ -309,7 +309,7 @@ func file_proto_frontend_v1_service_proto_init() { return nil } } - file_proto_frontend_v1_service_proto_msgTypes[3].Exporter = func(v any, i int) any { + file_frontend_v1_service_proto_msgTypes[3].Exporter = func(v any, i int) any { switch v := v.(*GetResponse); i { case 0: return &v.state @@ -326,18 +326,18 @@ func file_proto_frontend_v1_service_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_proto_frontend_v1_service_proto_rawDesc, + RawDescriptor: file_frontend_v1_service_proto_rawDesc, NumEnums: 0, NumMessages: 4, NumExtensions: 0, NumServices: 1, }, - GoTypes: file_proto_frontend_v1_service_proto_goTypes, - DependencyIndexes: file_proto_frontend_v1_service_proto_depIdxs, - MessageInfos: file_proto_frontend_v1_service_proto_msgTypes, + GoTypes: file_frontend_v1_service_proto_goTypes, + DependencyIndexes: file_frontend_v1_service_proto_depIdxs, + MessageInfos: file_frontend_v1_service_proto_msgTypes, }.Build() - File_proto_frontend_v1_service_proto = out.File - file_proto_frontend_v1_service_proto_rawDesc = nil - file_proto_frontend_v1_service_proto_goTypes = nil - file_proto_frontend_v1_service_proto_depIdxs = nil + File_frontend_v1_service_proto = out.File + file_frontend_v1_service_proto_rawDesc = nil + file_frontend_v1_service_proto_goTypes = nil + file_frontend_v1_service_proto_depIdxs = nil } diff --git a/proto/frontend/v1/service_grpc.pb.go b/proto/frontend/v1/service_grpc.pb.go deleted file mode 100644 index 895dcdd..0000000 --- a/proto/frontend/v1/service_grpc.pb.go +++ /dev/null @@ -1,159 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. -// versions: -// - protoc-gen-go-grpc v1.5.1 -// - protoc (unknown) -// source: proto/frontend/v1/service.proto - -package v1 - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.64.0 or later. -const _ = grpc.SupportPackageIsVersion9 - -const ( - FrontendService_Put_FullMethodName = "/frontend.v1.FrontendService/Put" - FrontendService_Get_FullMethodName = "/frontend.v1.FrontendService/Get" -) - -// FrontendServiceClient is the client API for FrontendService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type FrontendServiceClient interface { - Put(ctx context.Context, in *PutRequest, opts ...grpc.CallOption) (*PutResponse, error) - Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) -} - -type frontendServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewFrontendServiceClient(cc grpc.ClientConnInterface) FrontendServiceClient { - return &frontendServiceClient{cc} -} - -func (c *frontendServiceClient) Put(ctx context.Context, in *PutRequest, opts ...grpc.CallOption) (*PutResponse, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(PutResponse) - err := c.cc.Invoke(ctx, FrontendService_Put_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *frontendServiceClient) Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(GetResponse) - err := c.cc.Invoke(ctx, FrontendService_Get_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -// FrontendServiceServer is the server API for FrontendService service. -// All implementations must embed UnimplementedFrontendServiceServer -// for forward compatibility. -type FrontendServiceServer interface { - Put(context.Context, *PutRequest) (*PutResponse, error) - Get(context.Context, *GetRequest) (*GetResponse, error) - mustEmbedUnimplementedFrontendServiceServer() -} - -// UnimplementedFrontendServiceServer must be embedded to have -// forward compatible implementations. -// -// NOTE: this should be embedded by value instead of pointer to avoid a nil -// pointer dereference when methods are called. -type UnimplementedFrontendServiceServer struct{} - -func (UnimplementedFrontendServiceServer) Put(context.Context, *PutRequest) (*PutResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Put not implemented") -} -func (UnimplementedFrontendServiceServer) Get(context.Context, *GetRequest) (*GetResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Get not implemented") -} -func (UnimplementedFrontendServiceServer) mustEmbedUnimplementedFrontendServiceServer() {} -func (UnimplementedFrontendServiceServer) testEmbeddedByValue() {} - -// UnsafeFrontendServiceServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to FrontendServiceServer will -// result in compilation errors. -type UnsafeFrontendServiceServer interface { - mustEmbedUnimplementedFrontendServiceServer() -} - -func RegisterFrontendServiceServer(s grpc.ServiceRegistrar, srv FrontendServiceServer) { - // If the following call pancis, it indicates UnimplementedFrontendServiceServer was - // embedded by pointer and is nil. This will cause panics if an - // unimplemented method is ever invoked, so we test this at initialization - // time to prevent it from happening at runtime later due to I/O. - if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { - t.testEmbeddedByValue() - } - s.RegisterService(&FrontendService_ServiceDesc, srv) -} - -func _FrontendService_Put_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(PutRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(FrontendServiceServer).Put(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: FrontendService_Put_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(FrontendServiceServer).Put(ctx, req.(*PutRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _FrontendService_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(FrontendServiceServer).Get(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: FrontendService_Get_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(FrontendServiceServer).Get(ctx, req.(*GetRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// FrontendService_ServiceDesc is the grpc.ServiceDesc for FrontendService service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var FrontendService_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "frontend.v1.FrontendService", - HandlerType: (*FrontendServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Put", - Handler: _FrontendService_Put_Handler, - }, - { - MethodName: "Get", - Handler: _FrontendService_Get_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "proto/frontend/v1/service.proto", -} diff --git a/proto/frontend/v1/v1connect/service.connect.go b/proto/frontend/v1/v1connect/service.connect.go new file mode 100644 index 0000000..cf72ce6 --- /dev/null +++ b/proto/frontend/v1/v1connect/service.connect.go @@ -0,0 +1,141 @@ +// Code generated by protoc-gen-connect-go. DO NOT EDIT. +// +// Source: frontend/v1/service.proto + +package v1connect + +import ( + connect "connectrpc.com/connect" + context "context" + errors "errors" + v1 "github.com/rajatgoel/gh-go/proto/frontend/v1" + http "net/http" + 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 ( + // FrontendServiceName is the fully-qualified name of the FrontendService service. + FrontendServiceName = "frontend.v1.FrontendService" +) + +// 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 ( + // FrontendServicePutProcedure is the fully-qualified name of the FrontendService's Put RPC. + FrontendServicePutProcedure = "/frontend.v1.FrontendService/Put" + // FrontendServiceGetProcedure is the fully-qualified name of the FrontendService's Get RPC. + FrontendServiceGetProcedure = "/frontend.v1.FrontendService/Get" +) + +// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. +var ( + frontendServiceServiceDescriptor = v1.File_frontend_v1_service_proto.Services().ByName("FrontendService") + frontendServicePutMethodDescriptor = frontendServiceServiceDescriptor.Methods().ByName("Put") + frontendServiceGetMethodDescriptor = frontendServiceServiceDescriptor.Methods().ByName("Get") +) + +// FrontendServiceClient is a client for the frontend.v1.FrontendService service. +type FrontendServiceClient interface { + Put(context.Context, *connect.Request[v1.PutRequest]) (*connect.Response[v1.PutResponse], error) + Get(context.Context, *connect.Request[v1.GetRequest]) (*connect.Response[v1.GetResponse], error) +} + +// NewFrontendServiceClient constructs a client for the frontend.v1.FrontendService 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 NewFrontendServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) FrontendServiceClient { + baseURL = strings.TrimRight(baseURL, "/") + return &frontendServiceClient{ + put: connect.NewClient[v1.PutRequest, v1.PutResponse]( + httpClient, + baseURL+FrontendServicePutProcedure, + connect.WithSchema(frontendServicePutMethodDescriptor), + connect.WithClientOptions(opts...), + ), + get: connect.NewClient[v1.GetRequest, v1.GetResponse]( + httpClient, + baseURL+FrontendServiceGetProcedure, + connect.WithSchema(frontendServiceGetMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// frontendServiceClient implements FrontendServiceClient. +type frontendServiceClient struct { + put *connect.Client[v1.PutRequest, v1.PutResponse] + get *connect.Client[v1.GetRequest, v1.GetResponse] +} + +// Put calls frontend.v1.FrontendService.Put. +func (c *frontendServiceClient) Put(ctx context.Context, req *connect.Request[v1.PutRequest]) (*connect.Response[v1.PutResponse], error) { + return c.put.CallUnary(ctx, req) +} + +// Get calls frontend.v1.FrontendService.Get. +func (c *frontendServiceClient) Get(ctx context.Context, req *connect.Request[v1.GetRequest]) (*connect.Response[v1.GetResponse], error) { + return c.get.CallUnary(ctx, req) +} + +// FrontendServiceHandler is an implementation of the frontend.v1.FrontendService service. +type FrontendServiceHandler interface { + Put(context.Context, *connect.Request[v1.PutRequest]) (*connect.Response[v1.PutResponse], error) + Get(context.Context, *connect.Request[v1.GetRequest]) (*connect.Response[v1.GetResponse], error) +} + +// NewFrontendServiceHandler 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 NewFrontendServiceHandler(svc FrontendServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { + frontendServicePutHandler := connect.NewUnaryHandler( + FrontendServicePutProcedure, + svc.Put, + connect.WithSchema(frontendServicePutMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + frontendServiceGetHandler := connect.NewUnaryHandler( + FrontendServiceGetProcedure, + svc.Get, + connect.WithSchema(frontendServiceGetMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/frontend.v1.FrontendService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case FrontendServicePutProcedure: + frontendServicePutHandler.ServeHTTP(w, r) + case FrontendServiceGetProcedure: + frontendServiceGetHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedFrontendServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedFrontendServiceHandler struct{} + +func (UnimplementedFrontendServiceHandler) Put(context.Context, *connect.Request[v1.PutRequest]) (*connect.Response[v1.PutResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("frontend.v1.FrontendService.Put is not implemented")) +} + +func (UnimplementedFrontendServiceHandler) Get(context.Context, *connect.Request[v1.GetRequest]) (*connect.Response[v1.GetResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("frontend.v1.FrontendService.Get is not implemented")) +}