Documentation ¶
Overview ¶
Package knowledge implements the IndyKite Identity Knowledge API Client.
Index ¶
- Constants
- type Client
- func (c *Client) Close() error
- func (c *Client) GetDigitalTwinByID(ctx context.Context, id string, opts ...grpc.CallOption) (*knowledgepb.Node, error)
- func (c *Client) GetDigitalTwinByIdentifier(ctx context.Context, identifier *Identifier, opts ...grpc.CallOption) (*knowledgepb.Node, error)
- func (c *Client) GetResourceByID(ctx context.Context, id string, opts ...grpc.CallOption) (*knowledgepb.Node, error)
- func (c *Client) GetResourceByIdentifier(ctx context.Context, identifier *Identifier, opts ...grpc.CallOption) (*knowledgepb.Node, error)
- func (c *Client) ListDigitalTwins(ctx context.Context, opts ...grpc.CallOption) ([]*knowledgepb.Node, error)
- func (c *Client) ListDigitalTwinsByProperty(ctx context.Context, property *knowledgepb.Property, opts ...grpc.CallOption) ([]*knowledgepb.Node, error)
- func (c *Client) ListNodes(ctx context.Context, nodeType string, opts ...grpc.CallOption) ([]*knowledgepb.Node, error)
- func (c *Client) ListNodesByProperty(ctx context.Context, nodeType string, property *knowledgepb.Property, ...) ([]*knowledgepb.Node, error)
- func (c *Client) ListResources(ctx context.Context, opts ...grpc.CallOption) ([]*knowledgepb.Node, error)
- func (c *Client) ListResourcesByProperty(ctx context.Context, property *knowledgepb.Property, opts ...grpc.CallOption) ([]*knowledgepb.Node, error)
- func (c *Client) Read(ctx context.Context, path string, conditions string, ...) (*knowledgepb.IdentityKnowledgeResponse, error)
- type Identifier
Examples ¶
- Client.GetDigitalTwinByID
- Client.GetDigitalTwinByIdentifier
- Client.GetResourceByID
- Client.GetResourceByIdentifier
- Client.ListDigitalTwins
- Client.ListDigitalTwinsByProperty
- Client.ListNodes
- Client.ListNodesByProperty
- Client.ListResources
- Client.ListResourcesByProperty
- Client.Read
- NewClient (Default)
- NewClient (Options)
Constants ¶
const ( DigitalTwin = "DigitalTwin" Resource = "Resource" ExternalID = "external_id" Type = "type" ID = "id" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
NewClient creates a new Identity Knowledge API gRPC Client.
Example (Default) ¶
This example demonstrates how to create a new Identity Knowledge Client.
package main import ( "context" "log" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() }
Output:
Example (Options) ¶
This example demonstrates how to create a new Identity Knowledge Client.
package main import ( "context" "log" api "github.com/indykite/indykite-sdk-go/grpc" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background(), api.WithCredentialsJSON([]byte(`{}`))) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() }
Output:
func NewTestClient ¶
func NewTestClient(client knowledgepb.IdentityKnowledgeAPIClient) (*Client, error)
NewTestClient creates a new Identity Knowledge gRPC Client.
func (*Client) Close ¶
Close closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*Client) GetDigitalTwinByID ¶
func (c *Client) GetDigitalTwinByID( ctx context.Context, id string, opts ...grpc.CallOption, ) (*knowledgepb.Node, error)
GetDigitalTwinByID is a helper function that queries for a DigitalTwin node by its id.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to get a DigitalTwin by its id.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() response, err := client.GetDigitalTwinByID(context.Background(), "gid:AAAAAmluZHlraURlgAABDwAAAAA") if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) //nolint:gocritic } json := protojson.MarshalOptions{ Multiline: true, } fmt.Println(json.Format(response)) }
Output:
func (*Client) GetDigitalTwinByIdentifier ¶
func (c *Client) GetDigitalTwinByIdentifier( ctx context.Context, identifier *Identifier, opts ...grpc.CallOption, ) (*knowledgepb.Node, error)
GetDigitalTwinByIdentifier is a helper function that queries for a DigitalTwin node by its externalID + type combination.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to get a DigitalTwin by its externalID + type combination.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() response, err := client.GetDigitalTwinByIdentifier(context.Background(), &knowledge.Identifier{ ExternalID: "1234", Type: "Person", }) if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) //nolint:gocritic } json := protojson.MarshalOptions{ Multiline: true, } fmt.Println(json.Format(response)) }
Output:
func (*Client) GetResourceByID ¶
func (c *Client) GetResourceByID( ctx context.Context, id string, opts ...grpc.CallOption, ) (*knowledgepb.Node, error)
GetResourceByID is a helper function that queries for a Resource node by its id.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to get a Resource by its id.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() response, err := client.GetResourceByID(context.Background(), "gid:AAAAAmluZHlraURlgAABDwAAAAA") if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) //nolint:gocritic } json := protojson.MarshalOptions{ Multiline: true, } fmt.Println(json.Format(response)) }
Output:
func (*Client) GetResourceByIdentifier ¶
func (c *Client) GetResourceByIdentifier( ctx context.Context, identifier *Identifier, opts ...grpc.CallOption, ) (*knowledgepb.Node, error)
GetResourceByIdentifier is a helper function that queries for a Resource node by its externalID + type combination.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to get a DigitalTwin by its externalID + type combination.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() response, err := client.GetResourceByIdentifier(context.Background(), &knowledge.Identifier{ ExternalID: "1337", Type: "Store", }) if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) //nolint:gocritic } json := protojson.MarshalOptions{ Multiline: true, } fmt.Println(json.Format(response)) }
Output:
func (*Client) ListDigitalTwins ¶
func (c *Client) ListDigitalTwins( ctx context.Context, opts ...grpc.CallOption) ([]*knowledgepb.Node, error)
ListDigitalTwins is a helper function that lists all DigitalTwin nodes.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to list all DigitalTwins.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() response, err := client.ListDigitalTwins(context.Background()) if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) //nolint:gocritic } json := protojson.MarshalOptions{ Multiline: true, } for _, n := range response { fmt.Println(json.Format(n)) } }
Output:
func (*Client) ListDigitalTwinsByProperty ¶
func (c *Client) ListDigitalTwinsByProperty( ctx context.Context, property *knowledgepb.Property, opts ...grpc.CallOption) ([]*knowledgepb.Node, error)
ListDigitalTwinsByProperty is a helper function that lists all DigitalTwin nodes that have the specified property.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to list all DigitalTwins that have a certain property.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" knowledgepb "github.com/indykite/indykite-sdk-go/gen/indykite/knowledge/v1beta1" objects "github.com/indykite/indykite-sdk-go/gen/indykite/objects/v1beta1" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() response, err := client.ListDigitalTwinsByProperty(context.Background(), &knowledgepb.Property{ Key: "email", Value: &objects.Value{ Value: &objects.Value_StringValue{ StringValue: "test@test.com", }, }, }, ) if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) //nolint:gocritic } json := protojson.MarshalOptions{ Multiline: true, } for _, n := range response { fmt.Println(json.Format(n)) } }
Output:
func (*Client) ListNodes ¶
func (c *Client) ListNodes( ctx context.Context, nodeType string, opts ...grpc.CallOption, ) ([]*knowledgepb.Node, error)
ListNodes is a helper function that lists all nodes by type, regardless of whether they are DigitalTwins or Resources. The nodeType argument should be in PascalCase.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to list all nodes with a certain type.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() response, err := client.ListNodes(context.Background(), "Person") if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) //nolint:gocritic } json := protojson.MarshalOptions{ Multiline: true, } for _, n := range response { fmt.Println(json.Format(n)) } }
Output:
func (*Client) ListNodesByProperty ¶
func (c *Client) ListNodesByProperty( ctx context.Context, nodeType string, property *knowledgepb.Property, opts ...grpc.CallOption, ) ([]*knowledgepb.Node, error)
ListNodesByProperty is a helper function that lists all nodes that have the specified type and property.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to list all nodes with a certain type and property.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" knowledgepb "github.com/indykite/indykite-sdk-go/gen/indykite/knowledge/v1beta1" objects "github.com/indykite/indykite-sdk-go/gen/indykite/objects/v1beta1" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() response, err := client.ListNodesByProperty( context.Background(), "Person", &knowledgepb.Property{ Key: "email", Value: &objects.Value{ Value: &objects.Value_StringValue{ StringValue: "test@test.com"}}}) if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) //nolint:gocritic } json := protojson.MarshalOptions{ Multiline: true, } for _, n := range response { fmt.Println(json.Format(n)) } }
Output:
func (*Client) ListResources ¶
func (c *Client) ListResources( ctx context.Context, opts ...grpc.CallOption) ([]*knowledgepb.Node, error)
ListResources is a helper function that lists all Resource nodes. that have the specified property.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to list all Resources.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() response, err := client.ListResources(context.Background()) if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) //nolint:gocritic } json := protojson.MarshalOptions{ Multiline: true, } for _, n := range response { fmt.Println(json.Format(n)) } }
Output:
func (*Client) ListResourcesByProperty ¶
func (c *Client) ListResourcesByProperty( ctx context.Context, property *knowledgepb.Property, opts ...grpc.CallOption) ([]*knowledgepb.Node, error)
ListResourcesByProperty is a helper function that lists all Resource nodes. that have the specified property.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to list all Resources that have a certain property.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" knowledgepb "github.com/indykite/indykite-sdk-go/gen/indykite/knowledge/v1beta1" objects "github.com/indykite/indykite-sdk-go/gen/indykite/objects/v1beta1" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() response, err := client.ListResourcesByProperty(context.Background(), &knowledgepb.Property{ Key: "email", Value: &objects.Value{ Value: &objects.Value_StringValue{ StringValue: "test@test.com", }, }, }, ) if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) //nolint:gocritic } json := protojson.MarshalOptions{ Multiline: true, } for _, n := range response { fmt.Println(json.Format(n)) } }
Output:
func (*Client) Read ¶
func (c *Client) Read( ctx context.Context, path string, conditions string, inputParams map[string]*knowledgepb.InputParam, opts ...grpc.CallOption, ) (*knowledgepb.IdentityKnowledgeResponse, error)
Read sends a READ operation to the Identity Knowledge API, with the desired path and optional conditions.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to do a READ query.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" knowledgepb "github.com/indykite/indykite-sdk-go/gen/indykite/knowledge/v1beta1" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() path := "(n:Person)-[:HAS]->(s:Store)" conditions := "WHERE n.external_id = $external_id" params := map[string]*knowledgepb.InputParam{ "external_id": { Value: &knowledgepb.InputParam_StringValue{StringValue: "1234"}, }, } response, err := client.Read(context.Background(), path, conditions, params) if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) //nolint:gocritic } json := protojson.MarshalOptions{ Multiline: true, } fmt.Println(json.Format(response)) }
Output:
type Identifier ¶
Identifier is the combination of ExternalID and Type which uniquely identifies a node in the Identity Knowledge Graph.