Skip to content

Commit

Permalink
#165 Added constructor for gRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
docktermj committed Apr 17, 2024
1 parent 7c8874e commit 591bbb0
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 15 deletions.
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@ go 1.21
require (
github.com/senzing-garage/go-helpers v0.5.0
github.com/senzing-garage/go-logging v1.4.0
github.com/senzing-garage/sz-sdk-go v0.11.2-0.20240417134454-168cacac3e78
github.com/senzing-garage/sz-sdk-go-core v0.6.2-0.20240417140100-8c4fe468e29f
github.com/senzing-garage/sz-sdk-go v0.11.2-0.20240417201722-795456c22f04
github.com/senzing-garage/sz-sdk-go-core v0.6.2-0.20240417203123-accd7287850c
github.com/senzing-garage/sz-sdk-go-grpc v0.7.1-0.20240417205406-56fc19d0fe31
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.63.2
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/senzing-garage/go-messaging v1.4.0 // indirect
github.com/senzing-garage/go-observing v0.3.0 // indirect
github.com/senzing-garage/sz-sdk-proto v0.6.4-0.20240417202255-d10809bdab19 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 8 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ github.com/senzing-garage/go-messaging v1.4.0 h1:XNnOsx4yHslhggNJkZD+p3/Fv/zwhbx
github.com/senzing-garage/go-messaging v1.4.0/go.mod h1:V/B3SZSZY7cw2Nc7rZQkLaJu/PRyDA4AbviccDRjW1I=
github.com/senzing-garage/go-observing v0.3.0 h1:uWKZtiW4dwQJx8i7Y+7QrdrBJ8NPSOTZu2+6q0gy1DI=
github.com/senzing-garage/go-observing v0.3.0/go.mod h1:Bxl4c7G9hQ8iqSxZp/omolUhmkEdrbCzLt0s0VkPdnw=
github.com/senzing-garage/sz-sdk-go v0.11.2-0.20240417134454-168cacac3e78 h1:Ab+fffZsamYSg/ZMFwvCuAff+Wqzv5i67wtcyaeuroY=
github.com/senzing-garage/sz-sdk-go v0.11.2-0.20240417134454-168cacac3e78/go.mod h1:L/d0Oy6JO5B+o5FI5kuHzYseWSq3YJUbLChF50YUUFY=
github.com/senzing-garage/sz-sdk-go-core v0.6.2-0.20240417140100-8c4fe468e29f h1:XkAHFpZ0gBDAlR0pX+jE7g3EXWaSPZ1xsKfNGv8Erjg=
github.com/senzing-garage/sz-sdk-go-core v0.6.2-0.20240417140100-8c4fe468e29f/go.mod h1:7aamcPPA85DSuZlkolF4vCSsBJ/8A4I0PmxmkZ2hNIM=
github.com/senzing-garage/sz-sdk-go v0.11.2-0.20240417201722-795456c22f04 h1:9tq1fPf7qIcbYPYYPo6mo0BUHjXEjNsZ1zFP4kJIrR0=
github.com/senzing-garage/sz-sdk-go v0.11.2-0.20240417201722-795456c22f04/go.mod h1:L/d0Oy6JO5B+o5FI5kuHzYseWSq3YJUbLChF50YUUFY=
github.com/senzing-garage/sz-sdk-go-core v0.6.2-0.20240417203123-accd7287850c h1:KvufbVRg+dKTrOSTmcETJDIX4d5VMFvxQFV6Xlq5brk=
github.com/senzing-garage/sz-sdk-go-core v0.6.2-0.20240417203123-accd7287850c/go.mod h1:je5gp7Bs7RDhqBR4oAsF34pGN4B5iifwkbcuLyCVP4o=
github.com/senzing-garage/sz-sdk-go-grpc v0.7.1-0.20240417205406-56fc19d0fe31 h1:KBr6VYffboT3pFD7PcZ28Fm6pylruzfJbdPdIVUWN6A=
github.com/senzing-garage/sz-sdk-go-grpc v0.7.1-0.20240417205406-56fc19d0fe31/go.mod h1:a8R/7qO5RVFKSLW1YBzVkf4S4cVP1OWfNH6naT0Yf+w=
github.com/senzing-garage/sz-sdk-proto v0.6.4-0.20240417202255-d10809bdab19 h1:p8OFcTFdf3TDhXPvI3hwPozCuK+rmd2qFjTD5zufN5s=
github.com/senzing-garage/sz-sdk-proto v0.6.4-0.20240417202255-d10809bdab19/go.mod h1:sthSvS7iFKjC2r6l/hXYNhH0WceRaK2dFDWRFWHhRt4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY=
Expand Down
3 changes: 2 additions & 1 deletion szfactorycreator/doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
The szfactorycreator package... TODO:
TODO: Write description for szfactorycreator
The szfactorycreator package...
*/
package szfactorycreator
19 changes: 12 additions & 7 deletions szfactorycreator/main.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package szfactorycreator

import (
"github.com/senzing-garage/sz-sdk-go-core/szabstractfactory"
szabstractfactorycore "github.com/senzing-garage/sz-sdk-go-core/szabstractfactory"
szabstractfactorygrpc "github.com/senzing-garage/sz-sdk-go-grpc/szabstractfactory"
"google.golang.org/grpc"

"github.com/senzing-garage/sz-sdk-go/sz"
)

// ----------------------------------------------------------------------------
// Constants
// ----------------------------------------------------------------------------

// Identfier of the szfactorycreator package found messages having the format "senzing-6001xxxx".
// TODO: Assign ComponentId
const ComponentId = 9999
// Identfier of the szfactorycreator package found messages having the format "senzing-6041xxxx".
const ComponentId = 6041

// ----------------------------------------------------------------------------
// Factory builders
// ----------------------------------------------------------------------------

func CreateCoreAbstractFactory(instanceName string, settings string, verboseLogging int64, configId int64) (sz.SzAbstractFactory, error) {
szAbstractFactory := &szabstractfactory.Szabstractfactory{
szAbstractFactory := &szabstractfactorycore.Szabstractfactory{
ConfigId: configId,
InstanceName: instanceName,
Settings: settings,
Expand All @@ -27,8 +29,11 @@ func CreateCoreAbstractFactory(instanceName string, settings string, verboseLogg
return szAbstractFactory, nil
}

func CreateGrpcAbstractFactory() (sz.SzAbstractFactory, error) {
return nil, nil
func CreateGrpcAbstractFactory(grpcConnection *grpc.ClientConn) (sz.SzAbstractFactory, error) {
szAbstractFactory := &szabstractfactorygrpc.Szabstractfactory{
GrpcConnection: grpcConnection,
}
return szAbstractFactory, nil
}

func CreateMockAbstractFactory() (sz.SzAbstractFactory, error) {
Expand Down
22 changes: 22 additions & 0 deletions szfactorycreator/szfactorycreator_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"github.com/senzing-garage/go-helpers/engineconfigurationjson"
"github.com/senzing-garage/sz-sdk-go/sz"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -33,3 +35,23 @@ func ExampleCreateCoreAbstractFactory() {
defer szEngine.Destroy(ctx)
// Output:
}

func ExampleCreateGrpcAbstractFactory() {
// For more information, visit https://github.com/senzing-garage/go-sdk-abstract-factory/blob/main/szfactorycreator/szfactorycreator_examples_test.go
ctx := context.TODO()
grpcAddress := "localhost:8261"
grpcConnection, err := grpc.Dial(grpcAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
fmt.Printf("Did not connect: %v\n", err)
}
szAbstractFactory, err := CreateGrpcAbstractFactory(grpcConnection)
if err != nil {
fmt.Println(err)
}
szEngine, err := szAbstractFactory.CreateSzEngine(ctx)
if err != nil {
fmt.Println(err)
}
defer szEngine.Destroy(ctx)
// Output:
}
14 changes: 14 additions & 0 deletions szfactorycreator/szfactorycreator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/senzing-garage/go-helpers/engineconfigurationjson"
"github.com/senzing-garage/sz-sdk-go/sz"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -37,3 +39,15 @@ func TestSzfactorycreator_CreateCoreAbstractFactory(test *testing.T) {
testError(test, err)
defer szEngine.Destroy(ctx)
}

func TestSzfactorycreator_CreateGrpcAbstractFactory(test *testing.T) {
ctx := context.TODO()
grpcAddress := "localhost:8261"
grpcConnection, err := grpc.Dial(grpcAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
testError(test, err)
szAbstractFactory, err := CreateGrpcAbstractFactory(grpcConnection)
testError(test, err)
szEngine, err := szAbstractFactory.CreateSzEngine(ctx)
testError(test, err)
defer szEngine.Destroy(ctx)
}

0 comments on commit 591bbb0

Please sign in to comment.