diff --git a/bindings/follow.go b/bindings/follow.go index 6267a34125388a681827437d7a1e1cea1aa1c8dd..199990bd69ee51e2b377d501ec537399dca89eab 100644 --- a/bindings/follow.go +++ b/bindings/follow.go @@ -10,6 +10,7 @@ package bindings import ( "encoding/json" "fmt" + "gitlab.com/elixxir/client/cmix/message" "time" "github.com/pkg/errors" @@ -168,3 +169,50 @@ func (c *Cmix) RegisterClientErrorCallback(clientError ClientError) { } }() } + +// TrackServicesCallback is the callback for Cmix.TrackServices. +// This will pass to the user a JSON-marshalled list of backend services. +// If there was an error retrieving or marshalling the service list, +// there is an error for the second parameter which will be non-null. +// +// Example JSON: +// +// [ +// { +// "Id": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD", +// "Services": [ +// { +// "Identifier": null, +// "Tag": "test", +// "Metadata": null +// } +// ] +// }, +// { +// "Id": "AAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD", +// "Services": [ +// { +// "Identifier": null, +// "Tag": "test", +// "Metadata": null +// } +// ] +// }, +//] +type TrackServicesCallback interface { + Callback(marshalData []byte, err error) +} + +// TrackServices will return via a callback the list of services the +// backend keeps track of, which is formally referred to as a +// [message.ServiceList]. This may be passed into other bindings call which +// may need context on the available services for this client. +// +// Parameters: +// - cb - A TrackServicesCallback, which will be passed the marshalled +// message.ServiceList. +func (c *Cmix) TrackServices(cb TrackServicesCallback) { + c.api.GetCmix().TrackServices(func(list message.ServiceList) { + cb.Callback(json.Marshal(list)) + }) +}