go-mod-core-contracts

module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2019 License: Apache-2.0

README

go-mod-core-contracts

This module contains the contract models used to describe data as it is passed via Request/Response between various EdgeX Foundry services. It also contains service clients for each service within the edgex-go repository. The definition of the various models and clients can be found in their respective top-level directories.

The default encoding for the models is JSON, although in at least one case -- DeviceProfile -- YAML encoding is also supported since a device profile is defined as a YAML document.

Installation
  • Make sure you're using at least Go 1.11.1 and have modules enabled, i.e. have an initialized go.mod file
  • If your code is in your GOPATH then make sure GO111MODULE=on is set
  • Run go get github.com/edgexfoundry/go-mod-core-contracts
    • This will add the go-mod-core-contracts to the go.mod file and download it into the module cache
How to Use

In order to instantiate a service client, you would do the following:

Let's say you want to utilize a client for the core-metadata service, the first thing you want to do is initialize an instance of types.EndpointParams. This simple struct provides all the properties you need to address a given service endpoint. Population of the relevant properties might look like this:

params := types.EndpointParams{
        ServiceKey:  internal.CoreMetaDataServiceKey,
	Path:        clients.ApiDeviceRoute,
	UseRegistry: useRegistry,
	Url:         Configuration.Clients["Metadata"].Url() + clients.ApiDeviceRoute,
	Interval:    Configuration.Service.ClientMonitor,
}

From there you simply pass the EndpointParams into the initialization function for the client you wish to use. In the above case, we're trying to initialize a client for the Device endpoint of the core-metadata service.

mdc := metadata.NewDeviceClient(params, startup.Endpoint{RegistryClient: &registryClient})

More information on the RegistryClient can be found here. The RegistryClient is only used if the useRegistry flag provided to the EndpointParams is true.

Once you have a reference to the client, you simply need to call its methods like so: _, err := mdc.CheckForDevice(device, ctx)

Each client has a Monitor goroutine in it. If the registry is being used, the Monitor's job is to refresh the protocol, host and port of your service client at some configured interval. The default interval is 15 seconds.

Directories

Path Synopsis
Package clients provides REST-based integration with the core APIs of the EdgeX Foundry platform.
Package clients provides REST-based integration with the core APIs of the EdgeX Foundry platform.
command
Package command provides a client for integration with the core-command service.
Package command provides a client for integration with the core-command service.
coredata
Package coredata provides clients used for integration with the core-data service.
Package coredata provides clients used for integration with the core-data service.
export/distro
Package distro provides a client for integration with the export-distro service.
Package distro provides a client for integration with the export-distro service.
general
Package general provides a client for calling operational endpoints that are present on all service APIs.
Package general provides a client for calling operational endpoints that are present on all service APIs.
logger
Package logger provides a client for integration with the support-logging service.
Package logger provides a client for integration with the support-logging service.
metadata
Package metadata provides clients used for integration with the core-metadata service.
Package metadata provides clients used for integration with the core-metadata service.
notifications
Package notifications provides a client for integrating with the support-notifications service.
Package notifications provides a client for integrating with the support-notifications service.
scheduler
Package scheduler provides clients used for integration with the support-scheduler service.
Package scheduler provides clients used for integration with the support-scheduler service.
types
Package types provides supporting types that facilitate the various service client implementations.
Package types provides supporting types that facilitate the various service client implementations.
requests

Jump to

Keyboard shortcuts

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