# Packages
# README
go-pas-client
This is the client library for the Point Alarm Status (PAS) API.
Refer to the Swagger specification and the service description for further information on how the API works.
Example
Refer to example/ for examples of how to use this library.
Patching thresholds
The client model is using github.com/wI2L/jsondiff to create valid patches. Refer to the example for an example of its usage.
Error handling
Errors returned by the API are decoded into problems from the github.com/SKF/go-rest-utility
package before being returned by the client functions. This makes it possible to use the standard error
package to do error checking on any returned error.
E.g. if a faulty threshold is supplied when setting an alarm threshold you can check if it's a validation error (and what the validation errors are) using the following code.
err := client.SetThreshold(ctx, nodeID, models.Threshold{
Overall: &models.Overall{
Unit: "C",
OuterHigh: 60,
InnerHigh: 70,
},
})
if err != nil {
var problem problems.ValidationProblem
if errors.As(err, &problem) {
for _, reason := range problem.Reasons {
fmt.Println(reason)
}
}
}
Events
Events sent by the PAS service (as documented here) can be decoded into types defined in models/events.go.
The input to each decoding function should be the content of the event record Data
field.
The intention with these event types is to provide functionality that convert the event types sent on the SNS topic, which have have a slightly different structure compared to when fetching e.g. alarm thresholds from the API, into the same models returned by the client API calls. This should make the event models easier to use together with other client functions.
Below is an example which catches changes to overall thresholds where the measurement unit is set to C°
, and modifies it to C
.
var record eventsource.Record
event := new(models.ThresholdEvent)
if err := event.FromEvent(record.Data); err != nil {
panic(err)
}
threshold := event.Threshold
if threshold.Overall != nil && threshold.Overall.Unit == "C°" {
threshold.Overall.Unit = "C"
client.SetThreshold(ctx, nodeID, threshold)
}