-
Notifications
You must be signed in to change notification settings - Fork 68
/
transmission.go
71 lines (62 loc) · 2 KB
/
transmission.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// Copyright (C) 2021 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0
package models
import (
"encoding/json"
"github.com/edgexfoundry/go-mod-core-contracts/v2/errors"
)
// Transmission and its properties are defined in the APIv2 specification:
// https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/support-notifications/2.x#/Transmission
// Model fields are same as the DTOs documented by this swagger. Exceptions, if any, are noted below.
type Transmission struct {
Created int64
Id string
Channel Address
NotificationId string
SubscriptionName string
Records []TransmissionRecord
ResendCount int
Status TransmissionStatus
}
func (trans *Transmission) UnmarshalJSON(b []byte) error {
var alias struct {
Created int64
Id string
Channel interface{}
NotificationId string
SubscriptionName string
Records []TransmissionRecord
ResendCount int
Status TransmissionStatus
}
if err := json.Unmarshal(b, &alias); err != nil {
return errors.NewCommonEdgeX(errors.KindContractInvalid, "Failed to unmarshal transmission.", err)
}
channel, err := instantiateAddress(alias.Channel)
if err != nil {
return errors.NewCommonEdgeXWrapper(err)
}
*trans = Transmission{
Created: alias.Created,
Id: alias.Id,
Channel: channel,
NotificationId: alias.NotificationId,
SubscriptionName: alias.SubscriptionName,
Records: alias.Records,
ResendCount: alias.ResendCount,
Status: alias.Status,
}
return nil
}
// NewTransmission create transmission model with required fields
func NewTransmission(subscriptionName string, channel Address, notificationId string) Transmission {
return Transmission{
SubscriptionName: subscriptionName,
Channel: channel,
NotificationId: notificationId,
}
}
// TransmissionStatus indicates the most recent success/failure of a given transmission attempt.
type TransmissionStatus string