-
Notifications
You must be signed in to change notification settings - Fork 9
/
message.go
51 lines (43 loc) · 1.04 KB
/
message.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
package asbclient
import (
"fmt"
"strings"
"time"
)
//Message is an Azure Service Bus message
type Message struct {
DeliveryCount int
EnqueuedSequenceNumber int64
EnqueuedTimeUtc Time
LockToken string
LockedUntilUtc Time
MessageID string `json:"MessageId"`
PartitionKey string
SequenceNumber int64
State string
TimeToLive int
Location string
Body []byte
}
// Time is a wrapper round time.Time to json encode/decode in RFC1123 fomat
type Time struct {
time.Time
}
// UnmarshalJSON from RFC1123
func (t *Time) UnmarshalJSON(b []byte) (err error) {
s := strings.Trim(string(b), "\"")
if s == "null" {
t.Time = time.Time{}
return
}
t.Time, err = time.Parse(time.RFC1123, s)
return
}
var nilTime = (time.Time{}).UnixNano()
// MarshalJSON to RFC1123
func (t *Time) MarshalJSON() ([]byte, error) {
if t.Time.UnixNano() == nilTime {
return []byte("null"), nil
}
return []byte(fmt.Sprintf("\"%s\"", t.Time.Format(time.RFC1123))), nil
}