diff --git a/internal/cmd/protoc-gen-go-flipt-sdk/grpc.go b/internal/cmd/protoc-gen-go-flipt-sdk/grpc.go index 63bd613487..f3fe0fb46f 100644 --- a/internal/cmd/protoc-gen-go-flipt-sdk/grpc.go +++ b/internal/cmd/protoc-gen-go-flipt-sdk/grpc.go @@ -36,6 +36,14 @@ func generateGRPC(gen *protogen.Plugin) { ) if len(file.Services) < 2 { + srv := file.Services[0] + if srv.Comments.Leading != "" { + leading := strings.TrimPrefix(string(srv.Comments.Leading), "//") + if strings.TrimSpace(leading) == ignoreDecl { + continue + } + } + returnType := file.Services[0].GoName + "Client" g.P("func (t Transport) ", method, "() ", relativeImport(g, file, returnType), "{") g.P("return ", relativeImport(g, file, "New"+returnType), "(t.cc)") @@ -52,6 +60,13 @@ func generateGRPC(gen *protogen.Plugin) { g.P("}\n") for _, srv := range file.Services { + if srv.Comments.Leading != "" { + leading := strings.TrimPrefix(string(srv.Comments.Leading), "//") + if strings.TrimSpace(leading) == ignoreDecl { + continue + } + } + returnType := srv.GoName + "Client" g.P("func (t ", groupType, ") ", returnType, "() ", relativeImport(g, file, returnType), " {") g.P("return ", relativeImport(g, file, "New"+returnType), "(t.cc)") diff --git a/internal/cmd/protoc-gen-go-flipt-sdk/http.go b/internal/cmd/protoc-gen-go-flipt-sdk/http.go index a15656dae6..5ee1f5d930 100644 --- a/internal/cmd/protoc-gen-go-flipt-sdk/http.go +++ b/internal/cmd/protoc-gen-go-flipt-sdk/http.go @@ -141,6 +141,13 @@ func generateHTTP(gen *protogen.Plugin, grpcAPIConfig string) { if len(file.Services) < 2 { srv := file.Services[0] + if srv.Comments.Leading != "" { + leading := strings.TrimPrefix(string(srv.Comments.Leading), "//") + if strings.TrimSpace(leading) == ignoreDecl { + continue + } + } + returnType := srv.GoName + "Client" g.P("type ", returnType, " struct {") @@ -168,6 +175,13 @@ func generateHTTP(gen *protogen.Plugin, grpcAPIConfig string) { g.P("}\n") for _, srv := range file.Services { + if srv.Comments.Leading != "" { + leading := strings.TrimPrefix(string(srv.Comments.Leading), "//") + if strings.TrimSpace(leading) == ignoreDecl { + continue + } + } + var ( returnType = srv.GoName + "Client" unexportedReturnType = unexport(returnType) diff --git a/internal/cmd/protoc-gen-go-flipt-sdk/main.go b/internal/cmd/protoc-gen-go-flipt-sdk/main.go index dfb7e663c4..9a78c5fcc6 100644 --- a/internal/cmd/protoc-gen-go-flipt-sdk/main.go +++ b/internal/cmd/protoc-gen-go-flipt-sdk/main.go @@ -13,6 +13,8 @@ import ( const ( importPath = "go.flipt.io/flipt/sdk/go" emptyImport = "google.golang.org/protobuf/types/known/emptypb" + + ignoreDecl = "flipt:sdk:ignore" ) func main() { @@ -30,6 +32,7 @@ func main() { // warning. gen.SupportedFeatures |= uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL) for _, f := range gen.Files { + if !f.Generate { continue } @@ -129,6 +132,13 @@ func generateSubSDK(gen *protogen.Plugin, file *protogen.File) (typ, client stri } for _, srv := range file.Services { + if srv.Comments.Leading != "" { + leading := strings.TrimPrefix(string(srv.Comments.Leading), "//") + if strings.TrimSpace(leading) == ignoreDecl { + continue + } + } + serviceName := srv.GoName if oneServicePackage { serviceName = typ diff --git a/rpc/flipt/evaluation/evaluation.proto b/rpc/flipt/evaluation/evaluation.proto index df97420fe2..8b5b2c7599 100644 --- a/rpc/flipt/evaluation/evaluation.proto +++ b/rpc/flipt/evaluation/evaluation.proto @@ -162,6 +162,7 @@ message EvaluationNamespaceSnapshotRequest { string key = 1; } +// flipt:sdk:ignore service DataService { rpc EvaluationSnapshotNamespace(EvaluationNamespaceSnapshotRequest) returns (EvaluationNamespaceSnapshot); } diff --git a/sdk/go/evaluation.sdk.gen.go b/sdk/go/evaluation.sdk.gen.go index ed57289df5..0dac688afd 100644 --- a/sdk/go/evaluation.sdk.gen.go +++ b/sdk/go/evaluation.sdk.gen.go @@ -51,22 +51,3 @@ func (x *EvaluationService) Batch(ctx context.Context, v *evaluation.BatchEvalua } return x.transport.Batch(ctx, v) } - -type DataService struct { - transport evaluation.DataServiceClient - tokenProvider ClientTokenProvider -} - -func (s Evaluation) DataService() *DataService { - return &DataService{ - transport: s.transport.DataServiceClient(), - tokenProvider: s.tokenProvider, - } -} -func (x *DataService) EvaluationSnapshotNamespace(ctx context.Context, v *evaluation.EvaluationNamespaceSnapshotRequest) (*evaluation.EvaluationNamespaceSnapshot, error) { - ctx, err := authenticate(ctx, x.tokenProvider) - if err != nil { - return nil, err - } - return x.transport.EvaluationSnapshotNamespace(ctx, v) -} diff --git a/sdk/go/grpc/grpc.sdk.gen.go b/sdk/go/grpc/grpc.sdk.gen.go index b1387c99a0..1cefb6f63e 100644 --- a/sdk/go/grpc/grpc.sdk.gen.go +++ b/sdk/go/grpc/grpc.sdk.gen.go @@ -65,10 +65,6 @@ func (t evaluationClient) EvaluationServiceClient() evaluation.EvaluationService return evaluation.NewEvaluationServiceClient(t.cc) } -func (t evaluationClient) DataServiceClient() evaluation.DataServiceClient { - return evaluation.NewDataServiceClient(t.cc) -} - func (t Transport) EvaluationClient() _go.EvaluationClient { return evaluationClient{cc: t.cc} } diff --git a/sdk/go/http/evaluation.sdk.gen.go b/sdk/go/http/evaluation.sdk.gen.go index 1a4bfb1da4..ed9dbadee7 100644 --- a/sdk/go/http/evaluation.sdk.gen.go +++ b/sdk/go/http/evaluation.sdk.gen.go @@ -5,7 +5,6 @@ package http import ( bytes "bytes" context "context" - fmt "fmt" evaluation "go.flipt.io/flipt/rpc/flipt/evaluation" _go "go.flipt.io/flipt/sdk/go" grpc "google.golang.org/grpc" @@ -125,42 +124,6 @@ func (x *evaluationServiceClient) Batch(ctx context.Context, v *evaluation.Batch return &output, nil } -func (t evaluationClient) DataServiceClient() evaluation.DataServiceClient { - return &dataServiceClient{client: t.client, addr: t.addr} -} - -type dataServiceClient struct { - client *http.Client - addr string -} - -func (x *dataServiceClient) EvaluationSnapshotNamespace(ctx context.Context, v *evaluation.EvaluationNamespaceSnapshotRequest, _ ...grpc.CallOption) (*evaluation.EvaluationNamespaceSnapshot, error) { - var body io.Reader - var values url.Values - req, err := http.NewRequestWithContext(ctx, http.MethodGet, x.addr+fmt.Sprintf("/internal/v1/evaluation/snapshot/namespace/%v", v.Key), body) - if err != nil { - return nil, err - } - req.URL.RawQuery = values.Encode() - resp, err := x.client.Do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() - var output evaluation.EvaluationNamespaceSnapshot - respData, err := io.ReadAll(resp.Body) - if err != nil { - return nil, err - } - if err := checkResponse(resp, respData); err != nil { - return nil, err - } - if err := (protojson.UnmarshalOptions{DiscardUnknown: true}).Unmarshal(respData, &output); err != nil { - return nil, err - } - return &output, nil -} - func (t Transport) EvaluationClient() _go.EvaluationClient { return evaluationClient{client: t.client, addr: t.addr} }