From 951fdfe98992a1dba777434e51573be7a53d9033 Mon Sep 17 00:00:00 2001 From: Peter Bwire Date: Fri, 26 Jan 2024 09:05:20 +0300 Subject: [PATCH] upgrade connection base to be more hands off --- go/common/connection.go | 18 ++++++++++++--- go/files/client_setup.go | 17 +++++++------- go/files/go.mod | 4 +++- go/ledger/go.mod | 4 +++- go/ledger/go.sum | 2 -- go/ledger/v1/client.go | 21 ++++++++--------- go/lostid/go.mod | 2 ++ go/notification/go.mod | 4 +++- go/notification/go.sum | 2 -- go/notification/v1/client.go | 21 ++++++++--------- go/ocr/go.mod | 4 +++- go/ocr/go.sum | 2 -- go/ocr/v1/client.go | 27 +++++++++------------- go/partition/go.mod | 4 +++- go/partition/go.sum | 2 -- go/partition/v1/client.go | 21 ++++++++--------- go/partition/v1/client_test.go | 3 +-- go/payment/go.mod | 4 +++- go/payment/go.sum | 1 + go/payment/v1/client.go | 21 ++++++++--------- go/profile/go.mod | 2 +- go/profile/go.sum | 4 ++-- go/profile/v1/client.go | 42 +++++++++++----------------------- go/property/go.mod | 4 +++- go/property/go.sum | 2 -- go/property/v1/client.go | 21 ++++++++--------- go/settings/go.mod | 4 +++- go/settings/go.sum | 2 -- go/settings/v1/client.go | 21 ++++++++--------- 29 files changed, 138 insertions(+), 148 deletions(-) diff --git a/go/common/connection.go b/go/common/connection.go index 86e2f4df..df0ba3d8 100644 --- a/go/common/connection.go +++ b/go/common/connection.go @@ -42,6 +42,12 @@ type GrpcClientBase struct { xMetadata metadata.MD } +// Connection obtains the connection to the API service. User should invoke this +// connection is required. +func (gbc *GrpcClientBase) Connection() *grpc.ClientConn { + return gbc.clientConn +} + // Close closes the connection to the API service. The user should invoke this when // the client is no longer required. func (gbc *GrpcClientBase) Close() error { @@ -61,12 +67,18 @@ func (gbc *GrpcClientBase) GetInfo() metadata.MD { return gbc.xMetadata } -func NewClientBase(clientConn *grpc.ClientConn) GrpcClientBase { +func NewClientBase(ctx context.Context, opts ...ClientOption) (*GrpcClientBase, error) { + + connPool, err := DialConnection(ctx, opts...) + if err != nil { + return nil, err + } + clientBase := GrpcClientBase{ - clientConn: clientConn, + clientConn: connPool, } clientBase.SetInfo() - return clientBase + return &clientBase, nil } type JWTInterceptor struct { diff --git a/go/files/client_setup.go b/go/files/client_setup.go index 24bf8e15..028c80c3 100644 --- a/go/files/client_setup.go +++ b/go/files/client_setup.go @@ -16,16 +16,15 @@ package file_v1 import ( "context" - apic "github.com/antinvestor/apis/go/common" "google.golang.org/grpc" "google.golang.org/grpc/metadata" ) -const ctxKeyService = apic.CtxServiceKey("filesClientKey") +const ctxKeyService = common.CtxServiceKey("filesClientKey") -func defaultFilesClientOptions() []apic.ClientOption { - return []apic.ClientOption{ - apic.WithEndpoint("https://files.api.antinvestor.com"), +func defaultFilesClientOptions() []common.ClientOption { + return []common.ClientOption{ + common.WithEndpoint("https://files.api.antinvestor.com"), } } @@ -53,10 +52,10 @@ type FilesClient struct { // NewFilesClient creates a new file client. // The service that an application uses to create and read files stored in the system -func NewFilesClient(ctx context.Context, opts ...apic.ClientOption) (*FilesClient, error) { +func NewFilesClient(ctx context.Context, opts ...common.ClientOption) (*FilesClient, error) { clientOpts := defaultFilesClientOptions() - httClient, err := apic.HttpClient(ctx, append(clientOpts, opts...)...) + httClient, err := common.HttpClient(ctx, append(clientOpts, opts...)...) if err != nil { return nil, err @@ -79,7 +78,7 @@ func NewFilesClient(ctx context.Context, opts ...apic.ClientOption) (*FilesClien // the `x-goog-api-client` header passed on each request. Intended for // use by Google-written clients. func (fc *FilesClient) setClientInfo(keyval ...string) { - kv := append([]string{"gl-go", apic.VersionGo()}, keyval...) + kv := append([]string{"gl-go", common.VersionGo()}, keyval...) kv = append(kv, "grpc", grpc.Version) - fc.xMetadata = metadata.Pairs("x-ai-api-client", apic.XAntHeader(kv...)) + fc.xMetadata = metadata.Pairs("x-ai-api-client", common.XAntHeader(kv...)) } diff --git a/go/files/go.mod b/go/files/go.mod index 0b650c3a..c08bffdb 100644 --- a/go/files/go.mod +++ b/go/files/go.mod @@ -2,8 +2,10 @@ module github.com/antinvestor/apis/go/files go 1.21 +replace github.com/antinvestor/apis/go/common => ../common + require ( - github.com/antinvestor/apis/go/common v1.7.20 + github.com/antinvestor/apis/go/common v1.7.21 github.com/stretchr/testify v1.8.4 google.golang.org/grpc v1.61.0 ) diff --git a/go/ledger/go.mod b/go/ledger/go.mod index bd411815..1f30bf4b 100644 --- a/go/ledger/go.mod +++ b/go/ledger/go.mod @@ -2,8 +2,10 @@ module github.com/antinvestor/apis/go/ledger go 1.21 +replace github.com/antinvestor/apis/go/common => ../common + require ( - github.com/antinvestor/apis/go/common v1.7.20 + github.com/antinvestor/apis/go/common v1.7.21 go.uber.org/mock v0.4.0 google.golang.org/genproto v0.0.0-20240125205218-1f4bbc51befe google.golang.org/grpc v1.61.0 diff --git a/go/ledger/go.sum b/go/ledger/go.sum index 1ebcb8ac..6e50d429 100644 --- a/go/ledger/go.sum +++ b/go/ledger/go.sum @@ -1,5 +1,3 @@ -github.com/antinvestor/apis/go/common v1.7.20 h1:Vc0uloYy2cXNDuNCxheIoifHANyBexnhaJaumGhDHFA= -github.com/antinvestor/apis/go/common v1.7.20/go.mod h1:j4b9mKVLMGFFaA7TyHIFE/KfmOyuMBwBfoDqdBY+6X0= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= diff --git a/go/ledger/v1/client.go b/go/ledger/v1/client.go index f2cc687b..8444ad40 100644 --- a/go/ledger/v1/client.go +++ b/go/ledger/v1/client.go @@ -16,20 +16,19 @@ package ledgerv1 import ( "context" - apic "github.com/antinvestor/apis/go/common" "google.golang.org/grpc" "google.golang.org/grpc/metadata" "math" ) -const ctxKeyService = apic.CtxServiceKey("ledgerClientKey") +const ctxKeyService = common.CtxServiceKey("ledgerClientKey") -func defaultLedgerClientOptions() []apic.ClientOption { - return []apic.ClientOption{ - apic.WithEndpoint("ledger.api.antinvestor.com:443"), - apic.WithGRPCDialOption(grpc.WithDisableServiceConfig()), - apic.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32))), +func defaultLedgerClientOptions() []common.ClientOption { + return []common.ClientOption{ + common.WithEndpoint("ledger.api.antinvestor.com:443"), + common.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + common.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32))), } } @@ -77,10 +76,10 @@ func InstantiateLedgerClient(clientConnection *grpc.ClientConn, ledgerServiceCli // NewLedgerClient creates a new notification client. // // The service that an application uses to send and access received messages -func NewLedgerClient(ctx context.Context, opts ...apic.ClientOption) (*LedgerClient, error) { +func NewLedgerClient(ctx context.Context, opts ...common.ClientOption) (*LedgerClient, error) { clientOpts := defaultLedgerClientOptions() - connPool, err := apic.DialConnection(ctx, append(clientOpts, opts...)...) + connPool, err := common.DialConnection(ctx, append(clientOpts, opts...)...) if err != nil { return nil, err } @@ -99,7 +98,7 @@ func (nc *LedgerClient) Close() error { // the `x-goog-api-client` header passed on each request. Intended for // use by Google-written clients. func (nc *LedgerClient) setClientInfo(keyval ...string) { - kv := append([]string{"gl-go", apic.VersionGo()}, keyval...) + kv := append([]string{"gl-go", common.VersionGo()}, keyval...) kv = append(kv, "grpc", grpc.Version) - nc.xMetadata = metadata.Pairs("x-ai-api-client", apic.XAntHeader(kv...)) + nc.xMetadata = metadata.Pairs("x-ai-api-client", common.XAntHeader(kv...)) } diff --git a/go/lostid/go.mod b/go/lostid/go.mod index 7ff6fa5b..7c22f410 100644 --- a/go/lostid/go.mod +++ b/go/lostid/go.mod @@ -2,6 +2,8 @@ module github.com/antinvestor/apis/go/lostid go 1.21 +replace github.com/antinvestor/apis/go/common => ../common + require ( buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 go.uber.org/mock v0.4.0 diff --git a/go/notification/go.mod b/go/notification/go.mod index 6764486d..d937f9eb 100644 --- a/go/notification/go.mod +++ b/go/notification/go.mod @@ -2,9 +2,11 @@ module github.com/antinvestor/apis/go/notification go 1.21 +replace github.com/antinvestor/apis/go/common => ../common + require ( buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 - github.com/antinvestor/apis/go/common v1.7.20 + github.com/antinvestor/apis/go/common v1.7.21 go.uber.org/mock v0.4.0 google.golang.org/grpc v1.61.0 google.golang.org/protobuf v1.32.0 diff --git a/go/notification/go.sum b/go/notification/go.sum index b9b8f837..ada0cfe1 100644 --- a/go/notification/go.sum +++ b/go/notification/go.sum @@ -1,7 +1,5 @@ buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 h1:u0olL4yf2p7Tl5jfsAK5keaFi+JFJuv1CDHrbiXkxkk= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1/go.mod h1:tiTMKD8j6Pd/D2WzREoweufjzaJKHZg35f/VGcZ2v3I= -github.com/antinvestor/apis/go/common v1.7.20 h1:Vc0uloYy2cXNDuNCxheIoifHANyBexnhaJaumGhDHFA= -github.com/antinvestor/apis/go/common v1.7.20/go.mod h1:j4b9mKVLMGFFaA7TyHIFE/KfmOyuMBwBfoDqdBY+6X0= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= diff --git a/go/notification/v1/client.go b/go/notification/v1/client.go index 22391935..1160fb6a 100644 --- a/go/notification/v1/client.go +++ b/go/notification/v1/client.go @@ -16,20 +16,19 @@ package notificationv1 import ( "context" - apic "github.com/antinvestor/apis/go/common" commonv1 "github.com/antinvestor/apis/go/common/v1" "google.golang.org/grpc" "google.golang.org/grpc/metadata" "math" ) -const ctxKeyService = apic.CtxServiceKey("notificationClientKey") +const ctxKeyService = common.CtxServiceKey("notificationClientKey") -func defaultNotificationClientOptions() []apic.ClientOption { - return []apic.ClientOption{ - apic.WithEndpoint("notification.api.antinvestor.com:443"), - apic.WithGRPCDialOption(grpc.WithDisableServiceConfig()), - apic.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32))), +func defaultNotificationClientOptions() []common.ClientOption { + return []common.ClientOption{ + common.WithEndpoint("notification.api.antinvestor.com:443"), + common.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + common.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32))), } } @@ -77,10 +76,10 @@ func InstantiateNotificationClient(clientConnection *grpc.ClientConn, notificati // NewNotificationClient creates a new notification client. // // The service that an application uses to send and access received messages -func NewNotificationClient(ctx context.Context, opts ...apic.ClientOption) (*NotificationClient, error) { +func NewNotificationClient(ctx context.Context, opts ...common.ClientOption) (*NotificationClient, error) { clientOpts := defaultNotificationClientOptions() - connPool, err := apic.DialConnection(ctx, append(clientOpts, opts...)...) + connPool, err := common.DialConnection(ctx, append(clientOpts, opts...)...) if err != nil { return nil, err } @@ -109,9 +108,9 @@ func (nc *NotificationClient) Service() NotificationServiceClient { // the `x-goog-api-client` header passed on each request. Intended for // use by Google-written clients. func (nc *NotificationClient) setClientInfo(keyval ...string) { - kv := append([]string{"gl-go", apic.VersionGo()}, keyval...) + kv := append([]string{"gl-go", common.VersionGo()}, keyval...) kv = append(kv, "grpc", grpc.Version) - nc.xMetadata = metadata.Pairs("x-ai-api-client", apic.XAntHeader(kv...)) + nc.xMetadata = metadata.Pairs("x-ai-api-client", common.XAntHeader(kv...)) } func (nc *NotificationClient) Send(ctx context.Context, accessID string, contactId string, contactDetail string, diff --git a/go/ocr/go.mod b/go/ocr/go.mod index 0e9599af..b385defe 100644 --- a/go/ocr/go.mod +++ b/go/ocr/go.mod @@ -2,9 +2,11 @@ module github.com/antinvestor/apis/go/ocr go 1.21 +replace github.com/antinvestor/apis/go/common => ../common + require ( buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 - github.com/antinvestor/apis/go/common v1.7.20 + github.com/antinvestor/apis/go/common v1.7.21 go.uber.org/mock v0.4.0 google.golang.org/grpc v1.61.0 google.golang.org/protobuf v1.32.0 diff --git a/go/ocr/go.sum b/go/ocr/go.sum index b9b8f837..ada0cfe1 100644 --- a/go/ocr/go.sum +++ b/go/ocr/go.sum @@ -1,7 +1,5 @@ buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 h1:u0olL4yf2p7Tl5jfsAK5keaFi+JFJuv1CDHrbiXkxkk= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1/go.mod h1:tiTMKD8j6Pd/D2WzREoweufjzaJKHZg35f/VGcZ2v3I= -github.com/antinvestor/apis/go/common v1.7.20 h1:Vc0uloYy2cXNDuNCxheIoifHANyBexnhaJaumGhDHFA= -github.com/antinvestor/apis/go/common v1.7.20/go.mod h1:j4b9mKVLMGFFaA7TyHIFE/KfmOyuMBwBfoDqdBY+6X0= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= diff --git a/go/ocr/v1/client.go b/go/ocr/v1/client.go index 01649cb3..6b57b928 100644 --- a/go/ocr/v1/client.go +++ b/go/ocr/v1/client.go @@ -16,19 +16,18 @@ package ocrv1 import ( "context" - apic "github.com/antinvestor/apis/go/common" "google.golang.org/grpc" "google.golang.org/grpc/metadata" "math" ) -const ctxKeyService = apic.CtxServiceKey("ocrClientKey") +const ctxKeyService = common.CtxServiceKey("ocrClientKey") -func defaultProfileClientOptions() []apic.ClientOption { - return []apic.ClientOption{ - apic.WithEndpoint("ocr.api.antinvestor.com:443"), - apic.WithGRPCDialOption(grpc.WithDisableServiceConfig()), - apic.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32))), +func defaultProfileClientOptions() []common.ClientOption { + return []common.ClientOption{ + common.WithEndpoint("ocr.api.antinvestor.com:443"), + common.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + common.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32))), } } @@ -49,22 +48,18 @@ func FromContext(ctx context.Context) *OCRClient { // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. type OCRClient struct { - // gRPC connection to the service. - clientConn *grpc.ClientConn + common.GrpcClientBase // The gRPC API client. ocrClient OCRServiceClient - - // The x-ant-* metadata to be sent with each request. - xMetadata metadata.MD } // NewOCRClient creates a new ocr client. // The service that an application uses to perform ocr requests -func NewOCRClient(ctx context.Context, opts ...apic.ClientOption) (*OCRClient, error) { +func NewOCRClient(ctx context.Context, opts ...common.ClientOption) (*OCRClient, error) { clientOpts := defaultProfileClientOptions() - connPool, err := apic.DialConnection(ctx, append(clientOpts, opts...)...) + connPool, err := common.DialConnection(ctx, append(clientOpts, opts...)...) if err != nil { return nil, err } @@ -88,9 +83,9 @@ func (pc *OCRClient) Close() error { // the `x-goog-api-client` header passed on each request. Intended for // use by Google-written clients. func (pc *OCRClient) setClientInfo(keyval ...string) { - kv := append([]string{"gl-go", apic.VersionGo()}, keyval...) + kv := append([]string{"gl-go", common.VersionGo()}, keyval...) kv = append(kv, "grpc", grpc.Version) - pc.xMetadata = metadata.Pairs("x-ai-api-client", apic.XAntHeader(kv...)) + pc.xMetadata = metadata.Pairs("x-ai-api-client", common.XAntHeader(kv...)) } func (pc *OCRClient) Recognize(ctx context.Context, id string, language string, properties map[string]string, fileId ...string) (*RecognizeResponse, error) { diff --git a/go/partition/go.mod b/go/partition/go.mod index 23d8aa6d..c8cfed91 100644 --- a/go/partition/go.mod +++ b/go/partition/go.mod @@ -2,9 +2,11 @@ module github.com/antinvestor/apis/go/partition go 1.21 +replace github.com/antinvestor/apis/go/common => ../common + require ( buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 - github.com/antinvestor/apis/go/common v1.7.20 + github.com/antinvestor/apis/go/common v1.7.21 go.uber.org/mock v0.4.0 google.golang.org/grpc v1.61.0 google.golang.org/protobuf v1.32.0 diff --git a/go/partition/go.sum b/go/partition/go.sum index b9b8f837..ada0cfe1 100644 --- a/go/partition/go.sum +++ b/go/partition/go.sum @@ -1,7 +1,5 @@ buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 h1:u0olL4yf2p7Tl5jfsAK5keaFi+JFJuv1CDHrbiXkxkk= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1/go.mod h1:tiTMKD8j6Pd/D2WzREoweufjzaJKHZg35f/VGcZ2v3I= -github.com/antinvestor/apis/go/common v1.7.20 h1:Vc0uloYy2cXNDuNCxheIoifHANyBexnhaJaumGhDHFA= -github.com/antinvestor/apis/go/common v1.7.20/go.mod h1:j4b9mKVLMGFFaA7TyHIFE/KfmOyuMBwBfoDqdBY+6X0= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= diff --git a/go/partition/v1/client.go b/go/partition/v1/client.go index 0911f71d..eb7737a4 100644 --- a/go/partition/v1/client.go +++ b/go/partition/v1/client.go @@ -16,20 +16,19 @@ package partitionv1 import ( "context" - apic "github.com/antinvestor/apis/go/common" "google.golang.org/grpc" "google.golang.org/grpc/metadata" "math" ) -var ctxKeyService = apic.CtxServiceKey("partitionClientKey") +var ctxKeyService = common.CtxServiceKey("partitionClientKey") -func defaultPartitionClientOptions() []apic.ClientOption { - return []apic.ClientOption{ - apic.WithEndpoint("partitions.api.antinvestor.com:443"), - apic.WithGRPCDialOption(grpc.WithDisableServiceConfig()), - apic.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32))), +func defaultPartitionClientOptions() []common.ClientOption { + return []common.ClientOption{ + common.WithEndpoint("partitions.api.antinvestor.com:443"), + common.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + common.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32))), } } @@ -76,10 +75,10 @@ func InstantiatePartitionsClient( // NewPartitionsClient creates a new partitions client. // / The service that an application uses to access and manipulate partition information -func NewPartitionsClient(ctx context.Context, opts ...apic.ClientOption) (*PartitionClient, error) { +func NewPartitionsClient(ctx context.Context, opts ...common.ClientOption) (*PartitionClient, error) { clientOpts := defaultPartitionClientOptions() - connPool, err := apic.DialConnection(ctx, append(clientOpts, opts...)...) + connPool, err := common.DialConnection(ctx, append(clientOpts, opts...)...) if err != nil { return nil, err } @@ -97,9 +96,9 @@ func (partCl *PartitionClient) Close() error { // the `x-goog-api-client` header passed on each request. Intended for // use by Google-written clients. func (partCl *PartitionClient) setClientInfo(keyval ...string) { - kv := append([]string{"gl-go", apic.VersionGo()}, keyval...) + kv := append([]string{"gl-go", common.VersionGo()}, keyval...) kv = append(kv, "grpc", grpc.Version) - partCl.xMetadata = metadata.Pairs("x-ai-api-client", apic.XAntHeader(kv...)) + partCl.xMetadata = metadata.Pairs("x-ai-api-client", common.XAntHeader(kv...)) } func (partCl *PartitionClient) getService() PartitionServiceClient { diff --git a/go/partition/v1/client_test.go b/go/partition/v1/client_test.go index cec041d5..ed4632c3 100644 --- a/go/partition/v1/client_test.go +++ b/go/partition/v1/client_test.go @@ -16,13 +16,12 @@ package partitionv1 import ( "context" - apic "github.com/antinvestor/apis/go/common" "testing" ) func TestNewProfileClient(t *testing.T) { ctx := context.Background() - _, err := NewPartitionsClient(ctx, apic.WithEndpoint("127.0.0.1:7005")) + _, err := NewPartitionsClient(ctx, common.WithEndpoint("127.0.0.1:7005")) if err != nil { t.Errorf("Could not setup profile service : %v", err) } diff --git a/go/payment/go.mod b/go/payment/go.mod index 20aae68b..347d8759 100644 --- a/go/payment/go.mod +++ b/go/payment/go.mod @@ -2,9 +2,11 @@ module github.com/antinvestor/apis/go/payment go 1.21 +replace github.com/antinvestor/apis/go/common => ../common + require ( buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 - github.com/antinvestor/apis/go/common v1.7.20 + github.com/antinvestor/apis/go/common v1.7.21 google.golang.org/genproto v0.0.0-20240125205218-1f4bbc51befe google.golang.org/grpc v1.61.0 google.golang.org/protobuf v1.32.0 diff --git a/go/payment/go.sum b/go/payment/go.sum index 692dec8e..8e1f122b 100644 --- a/go/payment/go.sum +++ b/go/payment/go.sum @@ -13,6 +13,7 @@ github.com/antinvestor/apis/go/common v1.7.18/go.mod h1:p5CqKW/ExhfCzznzX/xO/9wz github.com/antinvestor/apis/go/common v1.7.19 h1:cz/HfoBC4OwuFJcOs+hG8O1Dd4cGWTKxrDUP38YGnL0= github.com/antinvestor/apis/go/common v1.7.19/go.mod h1:5T2ak+Wdcx8GLz86/VVgV0QW8GiX12bplfy0BLSBkxk= github.com/antinvestor/apis/go/common v1.7.20/go.mod h1:j4b9mKVLMGFFaA7TyHIFE/KfmOyuMBwBfoDqdBY+6X0= +github.com/antinvestor/apis/go/common v1.7.21/go.mod h1:j4b9mKVLMGFFaA7TyHIFE/KfmOyuMBwBfoDqdBY+6X0= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= diff --git a/go/payment/v1/client.go b/go/payment/v1/client.go index 062390e7..094a5b37 100644 --- a/go/payment/v1/client.go +++ b/go/payment/v1/client.go @@ -16,20 +16,19 @@ package paymentv1 import ( "context" - apic "github.com/antinvestor/apis/go/common" "google.golang.org/grpc" "google.golang.org/grpc/metadata" "math" ) -var ctxKeyService = apic.CtxServiceKey("paymentClientKey") +var ctxKeyService = common.CtxServiceKey("paymentClientKey") -func defaultPaymentClientOptions() []apic.ClientOption { - return []apic.ClientOption{ - apic.WithEndpoint("payments.api.antinvestor.com:443"), - apic.WithGRPCDialOption(grpc.WithDisableServiceConfig()), - apic.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32))), +func defaultPaymentClientOptions() []common.ClientOption { + return []common.ClientOption{ + common.WithEndpoint("payments.api.antinvestor.com:443"), + common.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + common.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32))), } } @@ -76,10 +75,10 @@ func InstantiatePaymentsClient( // NewPaymentsClient creates a new payments client. // / The service that an application uses to access and manipulate payment information -func NewPaymentsClient(ctx context.Context, opts ...apic.ClientOption) (*PaymentClient, error) { +func NewPaymentsClient(ctx context.Context, opts ...common.ClientOption) (*PaymentClient, error) { clientOpts := defaultPaymentClientOptions() - connPool, err := apic.DialConnection(ctx, append(clientOpts, opts...)...) + connPool, err := common.DialConnection(ctx, append(clientOpts, opts...)...) if err != nil { return nil, err } @@ -97,9 +96,9 @@ func (pCl *PaymentClient) Close() error { // the `x-goog-api-client` header passed on each request. Intended for // use by Google-written clients. func (pCl *PaymentClient) setClientInfo(keyval ...string) { - kv := append([]string{"gl-go", apic.VersionGo()}, keyval...) + kv := append([]string{"gl-go", common.VersionGo()}, keyval...) kv = append(kv, "grpc", grpc.Version) - pCl.xMetadata = metadata.Pairs("x-ai-api-client", apic.XAntHeader(kv...)) + pCl.xMetadata = metadata.Pairs("x-ai-api-client", common.XAntHeader(kv...)) } func (pCl *PaymentClient) getService() PaymentServiceClient { diff --git a/go/profile/go.mod b/go/profile/go.mod index 938b5961..d5a9998a 100644 --- a/go/profile/go.mod +++ b/go/profile/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 - github.com/antinvestor/apis/go/common v1.7.20 + github.com/antinvestor/apis/go/common v1.7.21 go.uber.org/mock v0.4.0 google.golang.org/grpc v1.61.0 google.golang.org/protobuf v1.32.0 diff --git a/go/profile/go.sum b/go/profile/go.sum index b9b8f837..a21cf0be 100644 --- a/go/profile/go.sum +++ b/go/profile/go.sum @@ -1,7 +1,7 @@ buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 h1:u0olL4yf2p7Tl5jfsAK5keaFi+JFJuv1CDHrbiXkxkk= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1/go.mod h1:tiTMKD8j6Pd/D2WzREoweufjzaJKHZg35f/VGcZ2v3I= -github.com/antinvestor/apis/go/common v1.7.20 h1:Vc0uloYy2cXNDuNCxheIoifHANyBexnhaJaumGhDHFA= -github.com/antinvestor/apis/go/common v1.7.20/go.mod h1:j4b9mKVLMGFFaA7TyHIFE/KfmOyuMBwBfoDqdBY+6X0= +github.com/antinvestor/apis/go/common v1.7.21 h1:ohY3OIcrCH7BBN2Q6Q4IoaxrudwDP0JSFYd8I8ApF4I= +github.com/antinvestor/apis/go/common v1.7.21/go.mod h1:j4b9mKVLMGFFaA7TyHIFE/KfmOyuMBwBfoDqdBY+6X0= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= diff --git a/go/profile/v1/client.go b/go/profile/v1/client.go index 79c2ca79..f49738b3 100644 --- a/go/profile/v1/client.go +++ b/go/profile/v1/client.go @@ -16,19 +16,18 @@ package profilev1 import ( "context" - apic "github.com/antinvestor/apis/go/common" + "github.com/antinvestor/apis/go/common" "google.golang.org/grpc" - "google.golang.org/grpc/metadata" "math" ) -const ctxKeyService = apic.CtxServiceKey("profileClientKey") +const ctxKeyService = common.CtxServiceKey("profileClientKey") -func defaultProfileClientOptions() []apic.ClientOption { - return []apic.ClientOption{ - apic.WithEndpoint("profile.api.antinvestor.com:443"), - apic.WithGRPCDialOption(grpc.WithDisableServiceConfig()), - apic.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32))), +func defaultProfileClientOptions() []common.ClientOption { + return []common.ClientOption{ + common.WithEndpoint("profile.api.antinvestor.com:443"), + common.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + common.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32))), } } @@ -49,7 +48,7 @@ func FromContext(ctx context.Context) *ProfileClient { // Methods, except Close, may be called concurrently. However, // fields must not be modified concurrently with method calls. type ProfileClient struct { - apic.GrpcClientBase + common.GrpcClientBase // The gRPC API client. profileClient ProfileServiceClient @@ -70,10 +69,10 @@ func InstantiateProfileClient( // NewProfileClient creates a new notification client. // The service that an application uses to send and access received messages -func NewProfileClient(ctx context.Context, opts ...apic.ClientOption) (*ProfileClient, error) { +func NewProfileClient(ctx context.Context, opts ...common.ClientOption) (*ProfileClient, error) { clientOpts := defaultProfileClientOptions() - connPool, err := apic.DialConnection(ctx, append(clientOpts, opts...)...) + connPool, err := common.DialConnection(ctx, append(clientOpts, opts...)...) if err != nil { return nil, err } @@ -83,26 +82,11 @@ func NewProfileClient(ctx context.Context, opts ...apic.ClientOption) (*ProfileC return InstantiateProfileClient(connPool, profileSvcCli), nil } -// Close closes the connection to the API service. The user should invoke this when -// the client is no longer required. -func (pc *ProfileClient) Close() error { - return pc.clientConn.Close() -} - -// setClientInfo sets the name and version of the application in -// the `x-goog-api-client` header passed on each request. Intended for -// use by Google-written clients. -func (pc *ProfileClient) setClientInfo(keyval ...string) { - kv := append([]string{"gl-go", apic.VersionGo()}, keyval...) - kv = append(kv, "grpc", grpc.Version) - pc.xMetadata = metadata.Pairs("x-ai-api-client", apic.XAntHeader(kv...)) -} - func (pc *ProfileClient) GetProfileByID( ctx context.Context, profileID string) (*ProfileObject, error) { - profileService := NewProfileServiceClient(pc.clientConn) + profileService := NewProfileServiceClient(pc.Connection()) profileRequest := GetByIdRequest{ Id: profileID, @@ -120,7 +104,7 @@ func (pc *ProfileClient) CreateProfileByContactAndName( contact string, name string) (*ProfileObject, error) { - profileService := NewProfileServiceClient(pc.clientConn) + profileService := NewProfileServiceClient(pc.Connection()) properties := make(map[string]string) properties["name"] = name @@ -138,7 +122,7 @@ func (pc *ProfileClient) CreateProfileByContactAndName( } func (pc *ProfileClient) GetProfileByContact(ctx context.Context, contact string) (*ProfileObject, error) { - profileService := NewProfileServiceClient(pc.clientConn) + profileService := NewProfileServiceClient(pc.Connection()) contactRequest := GetByContactRequest{ Contact: contact, diff --git a/go/property/go.mod b/go/property/go.mod index 67fbf5dd..8f4e6391 100644 --- a/go/property/go.mod +++ b/go/property/go.mod @@ -2,9 +2,11 @@ module github.com/antinvestor/apis/go/property go 1.21 +replace github.com/antinvestor/apis/go/common => ../common + require ( buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 - github.com/antinvestor/apis/go/common v1.7.20 + github.com/antinvestor/apis/go/common v1.7.21 go.uber.org/mock v0.4.0 google.golang.org/grpc v1.61.0 google.golang.org/protobuf v1.32.0 diff --git a/go/property/go.sum b/go/property/go.sum index b9b8f837..ada0cfe1 100644 --- a/go/property/go.sum +++ b/go/property/go.sum @@ -1,7 +1,5 @@ buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 h1:u0olL4yf2p7Tl5jfsAK5keaFi+JFJuv1CDHrbiXkxkk= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1/go.mod h1:tiTMKD8j6Pd/D2WzREoweufjzaJKHZg35f/VGcZ2v3I= -github.com/antinvestor/apis/go/common v1.7.20 h1:Vc0uloYy2cXNDuNCxheIoifHANyBexnhaJaumGhDHFA= -github.com/antinvestor/apis/go/common v1.7.20/go.mod h1:j4b9mKVLMGFFaA7TyHIFE/KfmOyuMBwBfoDqdBY+6X0= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= diff --git a/go/property/v1/client.go b/go/property/v1/client.go index 0bc3e2ac..349fce69 100644 --- a/go/property/v1/client.go +++ b/go/property/v1/client.go @@ -16,20 +16,19 @@ package propertyv1 import ( "context" - apic "github.com/antinvestor/apis/go/common" "google.golang.org/grpc" "google.golang.org/grpc/metadata" "math" ) -const ctxKeyService = apic.CtxServiceKey("propertyClientKey") +const ctxKeyService = common.CtxServiceKey("propertyClientKey") -func defaultPropertyClientOptions() []apic.ClientOption { - return []apic.ClientOption{ - apic.WithEndpoint("property.api.antinvestor.com:443"), - apic.WithGRPCDialOption(grpc.WithDisableServiceConfig()), - apic.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32))), +func defaultPropertyClientOptions() []common.ClientOption { + return []common.ClientOption{ + common.WithEndpoint("property.api.antinvestor.com:443"), + common.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + common.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32))), } } @@ -77,10 +76,10 @@ func InstantiatePropertyClient(clientConnection *grpc.ClientConn, propertyServic // NewPropertyClient creates a new notification client. // // The service that an application uses to send and access received messages -func NewPropertyClient(ctx context.Context, opts ...apic.ClientOption) (*PropertyClient, error) { +func NewPropertyClient(ctx context.Context, opts ...common.ClientOption) (*PropertyClient, error) { clientOpts := defaultPropertyClientOptions() - connPool, err := apic.DialConnection(ctx, append(clientOpts, opts...)...) + connPool, err := common.DialConnection(ctx, append(clientOpts, opts...)...) if err != nil { return nil, err } @@ -99,9 +98,9 @@ func (nc *PropertyClient) Close() error { // the `x-goog-api-client` header passed on each request. Intended for // use by Google-written clients. func (nc *PropertyClient) setClientInfo(keyval ...string) { - kv := append([]string{"gl-go", apic.VersionGo()}, keyval...) + kv := append([]string{"gl-go", common.VersionGo()}, keyval...) kv = append(kv, "grpc", grpc.Version) - nc.xMetadata = metadata.Pairs("x-ai-api-client", apic.XAntHeader(kv...)) + nc.xMetadata = metadata.Pairs("x-ai-api-client", common.XAntHeader(kv...)) } func (nc *PropertyClient) AddPropertyType( diff --git a/go/settings/go.mod b/go/settings/go.mod index ac12b0a1..e14c9a3f 100644 --- a/go/settings/go.mod +++ b/go/settings/go.mod @@ -2,9 +2,11 @@ module github.com/antinvestor/apis/go/settings go 1.21 +replace github.com/antinvestor/apis/go/common => ../common + require ( buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 - github.com/antinvestor/apis/go/common v1.7.20 + github.com/antinvestor/apis/go/common v1.7.21 go.uber.org/mock v0.4.0 google.golang.org/grpc v1.61.0 google.golang.org/protobuf v1.32.0 diff --git a/go/settings/go.sum b/go/settings/go.sum index b9b8f837..ada0cfe1 100644 --- a/go/settings/go.sum +++ b/go/settings/go.sum @@ -1,7 +1,5 @@ buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 h1:u0olL4yf2p7Tl5jfsAK5keaFi+JFJuv1CDHrbiXkxkk= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1/go.mod h1:tiTMKD8j6Pd/D2WzREoweufjzaJKHZg35f/VGcZ2v3I= -github.com/antinvestor/apis/go/common v1.7.20 h1:Vc0uloYy2cXNDuNCxheIoifHANyBexnhaJaumGhDHFA= -github.com/antinvestor/apis/go/common v1.7.20/go.mod h1:j4b9mKVLMGFFaA7TyHIFE/KfmOyuMBwBfoDqdBY+6X0= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= diff --git a/go/settings/v1/client.go b/go/settings/v1/client.go index afdc5fc1..329df373 100644 --- a/go/settings/v1/client.go +++ b/go/settings/v1/client.go @@ -16,20 +16,19 @@ package settingsv1 import ( "context" - apic "github.com/antinvestor/apis/go/common" "google.golang.org/grpc" "google.golang.org/grpc/metadata" "math" ) -const ctxKeyService = apic.CtxServiceKey("settingsClientKey") +const ctxKeyService = common.CtxServiceKey("settingsClientKey") -func defaultsettingsClientOptions() []apic.ClientOption { - return []apic.ClientOption{ - apic.WithEndpoint("settings.api.antinvestor.com:443"), - apic.WithGRPCDialOption(grpc.WithDisableServiceConfig()), - apic.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32))), +func defaultsettingsClientOptions() []common.ClientOption { + return []common.ClientOption{ + common.WithEndpoint("settings.api.antinvestor.com:443"), + common.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + common.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32))), } } @@ -77,10 +76,10 @@ func InstantiatesettingsClient(clientConnection *grpc.ClientConn, settingsServic // NewsettingsClient creates a new notification client. // // The service that an application uses to send and access received messages -func NewsettingsClient(ctx context.Context, opts ...apic.ClientOption) (*SettingsClient, error) { +func NewsettingsClient(ctx context.Context, opts ...common.ClientOption) (*SettingsClient, error) { clientOpts := defaultsettingsClientOptions() - connPool, err := apic.DialConnection(ctx, append(clientOpts, opts...)...) + connPool, err := common.DialConnection(ctx, append(clientOpts, opts...)...) if err != nil { return nil, err } @@ -99,7 +98,7 @@ func (nc *SettingsClient) Close() error { // the `x-goog-api-client` header passed on each request. Intended for // use by Google-written clients. func (nc *SettingsClient) setClientInfo(keyval ...string) { - kv := append([]string{"gl-go", apic.VersionGo()}, keyval...) + kv := append([]string{"gl-go", common.VersionGo()}, keyval...) kv = append(kv, "grpc", grpc.Version) - nc.xMetadata = metadata.Pairs("x-ai-api-client", apic.XAntHeader(kv...)) + nc.xMetadata = metadata.Pairs("x-ai-api-client", common.XAntHeader(kv...)) }