hierarchy

package
v1.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package hierarchy provides the client for making API requests to Enlight Hierarchy Management Service.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements the HierarchyClient and holds the connection.

Example
package main

import (
	"log"

	"github.com/SKF/go-enlight-sdk/grpc"
	"github.com/SKF/go-enlight-sdk/services/hierarchy"
)

func main() {
	host, port := "<host>", "<port>"
	clientCert, clientKey := "<clientCertPath>", "<clientKey>"
	caCert := "<caCert>"

	// Create a Hierarchy Service client
	client := hierarchy.CreateClient()

	// Dial the Hierarchy Service
	dialOption, err := grpc.WithTransportCredentials(host, clientCert, clientKey, caCert)
	if err != nil {
		log.Fatalf("Couldn't connect due to error: %+v", err)
	}

	// Dial the Hierarchy Service
	err = client.Dial(host, port, dialOption)
	if err != nil {
		log.Fatalf("Couldn't dial due to error: %+v", err)
	}
	defer client.Close()

	// Ping the Hierarchy Service
	err = client.DeepPing()
	if err != nil {
		log.Fatalf("Couldn't ping the Hierarchy Service due to error: %+v", err)
	}
}
Output:

func (*Client) Close

func (c *Client) Close()

Close tears down the ClientConn and all underlying connections.

func (*Client) DeepPing

func (c *Client) DeepPing() error

DeepPing pings the service to see if it is alive.

func (*Client) DeepPingWithContext

func (c *Client) DeepPingWithContext(ctx context.Context) error

DeepPingWithContext pings the service to see if it is alive.

func (*Client) DeleteNode

func (c *Client) DeleteNode(request grpcapi.DeleteNodeInput) error

DeleteNode will remove the node of the node id it takes as an argument.

func (*Client) DeleteNodeWithContext

func (c *Client) DeleteNodeWithContext(ctx context.Context, request grpcapi.DeleteNodeInput) error

DeleteNodeWithContext will remove the node of the node id it takes as an argument.

func (*Client) Dial

func (c *Client) Dial(host, port string, opts ...grpc.DialOption) (err error)

Dial creates a client connection to the given host.

func (*Client) GetAncestors

func (c *Client) GetAncestors(nodeID string) (nodes []grpcapi.AncestorNode, err error)

GetAncestors will return all ancestors to the top of the node id it takes as an argument.

func (*Client) GetAncestorsWithContext

func (c *Client) GetAncestorsWithContext(ctx context.Context, nodeID string) (nodes []grpcapi.AncestorNode, err error)

GetAncestorsWithContext will return all ancestors to the top of the node id it takes as an argument.

func (*Client) GetChildNodes

func (c *Client) GetChildNodes(parentID string) (nodes []grpcapi.Node, err error)

GetChildNodes will get all child nodes for the node id it takes as an argument.

func (*Client) GetChildNodesWithContext

func (c *Client) GetChildNodesWithContext(ctx context.Context, parentID string) (nodes []grpcapi.Node, err error)

GetChildNodesWithContext will get all child nodes for the node id it takes as an argument.

func (*Client) GetEvents

func (c *Client) GetEvents(since int, limit *int32) (events []eventsource.Record, err error)

GetEvents will return all events that has occured in the Hierarchy Management Service.

func (*Client) GetEventsWithContext

func (c *Client) GetEventsWithContext(ctx context.Context, since int, limit *int32) (events []eventsource.Record, err error)

GetEventsWithContext will return all events that has occured in the Hierarchy Management Service.

func (*Client) GetNode

func (c *Client) GetNode(uuid string) (node grpcapi.Node, err error)

GetNode takes an id of a node and returns the node.

func (*Client) GetNodeIDByOrigin

func (c *Client) GetNodeIDByOrigin(origin grpcapi.Origin) (string, error)

GetNodeIDByOrigin takes an origin and returns the Enlight ID.

func (*Client) GetNodeIDByOriginWithContext

func (c *Client) GetNodeIDByOriginWithContext(ctx context.Context, origin grpcapi.Origin) (string, error)

GetNodeIDByOriginWithContext takes an origin and returns the Enlight ID.

func (*Client) GetNodeWithContext

func (c *Client) GetNodeWithContext(ctx context.Context, uuid string) (node grpcapi.Node, err error)

GetNodeWithContext takes an id of a node and returns the node.

func (*Client) GetNodes

func (c *Client) GetNodes(parentID string) (nodes []grpcapi.Node, err error)

GetNodes will get all child nodes for the node id it takes as an argument.

func (*Client) GetNodesWithContext

func (c *Client) GetNodesWithContext(ctx context.Context, parentID string) (nodes []grpcapi.Node, err error)

GetNodesWithContext will get all child nodes for the node id it takes as an argument.

func (*Client) GetParentNode

func (c *Client) GetParentNode(nodeID string) (node grpcapi.Node, err error)

GetParentNode will return the parent of the node id it takes as an argument.

func (*Client) GetParentNodeWithContext

func (c *Client) GetParentNodeWithContext(ctx context.Context, nodeID string) (node grpcapi.Node, err error)

GetParentNodeWithContext will return the parent of the node id it takes as an argument.

func (*Client) SaveNode

func (c *Client) SaveNode(request grpcapi.SaveNodeInput) (string, error)

SaveNode will add the node if it this not exist and otherwise create it.

Example (Create)
package main

import (
	"log"

	"github.com/SKF/go-enlight-sdk/services/hierarchy"
	"github.com/SKF/go-enlight-sdk/services/hierarchy/grpcapi"
)

func main() {
	var client hierarchy.HierarchyClient
	saveNodeInput := grpcapi.SaveNodeInput{
		UserId:   "<user_id>",
		Node:     &grpcapi.Node{},
		ParentId: "<parent_id>",
	}
	nodeID, err := client.SaveNode(saveNodeInput)
	if err != nil {
		log.Printf("Couldn't save node due to error: %+v", err)
		return
	}
	log.Printf("nodeId: %q", nodeID)
}
Output:

Example (Update)
package main

import (
	"log"

	"github.com/SKF/go-enlight-sdk/services/hierarchy"
	"github.com/SKF/go-enlight-sdk/services/hierarchy/grpcapi"
)

func main() {
	var client hierarchy.HierarchyClient
	saveNodeInput := grpcapi.SaveNodeInput{
		UserId: "<user_id>",
		Node: &grpcapi.Node{
			Id: "<node_id>",
		},
		ParentId: "<parent_id>",
	}
	nodeID, err := client.SaveNode(saveNodeInput)
	if err != nil {
		log.Printf("Couldn't save node due to error: %+v", err)
		return
	}
	log.Printf("nodeId: %q", nodeID)
}
Output:

func (*Client) SaveNodeWithContext

func (c *Client) SaveNodeWithContext(ctx context.Context, request grpcapi.SaveNodeInput) (string, error)

SaveNode will add the node if it this not exist and otherwise create it.

type HierarchyClient

type HierarchyClient interface {
	Dial(host, port string, opts ...grpc.DialOption) error
	Close()

	DeepPing() error
	DeepPingWithContext(ctx context.Context) error

	SaveNode(request grpcapi.SaveNodeInput) (string, error)
	SaveNodeWithContext(ctx context.Context, request grpcapi.SaveNodeInput) (string, error)

	GetNode(nodeID string) (grpcapi.Node, error)
	GetNodeWithContext(ctx context.Context, nodeID string) (grpcapi.Node, error)

	GetNodes(parentID string) ([]grpcapi.Node, error)
	GetNodesWithContext(ctx context.Context, parentID string) ([]grpcapi.Node, error)

	GetChildNodes(parentID string) ([]grpcapi.Node, error)
	GetChildNodesWithContext(ctx context.Context, parentID string) ([]grpcapi.Node, error)

	DeleteNode(request grpcapi.DeleteNodeInput) error
	DeleteNodeWithContext(ctx context.Context, request grpcapi.DeleteNodeInput) error

	GetAncestors(nodeID string) ([]grpcapi.AncestorNode, error)
	GetAncestorsWithContext(ctx context.Context, nodeID string) ([]grpcapi.AncestorNode, error)

	GetEvents(since int, limit *int32) ([]eventsource.Record, error)
	GetEventsWithContext(ctx context.Context, since int, limit *int32) ([]eventsource.Record, error)

	GetParentNode(nodeID string) (grpcapi.Node, error)
	GetParentNodeWithContext(ctx context.Context, nodeID string) (grpcapi.Node, error)

	GetNodeIDByOrigin(origin grpcapi.Origin) (string, error)
	GetNodeIDByOriginWithContext(ctx context.Context, origin grpcapi.Origin) (string, error)
}

HierarchyClient provides the API operation methods for making requests to Enlight Hierarchy Management Service. See this package's package overview docs for details on the service.

func CreateClient

func CreateClient() HierarchyClient

CreateClient creates an instance of the HierarchyClient.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL