Skip to content

Commit ea0462d

Browse files
committed
Merge branch 'master' of https://github.com/emitter-io/go
2 parents 4c236c2 + 540049c commit ea0462d

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: [kelindar]

v2/emitter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ func (c *Client) OnError(handler ErrorHandler) {
137137

138138
// onMessage occurs when MQTT client receives a message
139139
func (c *Client) onMessage(_ mqtt.Client, m mqtt.Message) {
140-
if c.message != nil && !strings.HasPrefix(m.Topic(), "emitter/") {
140+
if !strings.HasPrefix(m.Topic(), "emitter/") {
141141
handlers := c.handlers.Lookup(m.Topic())
142-
if len(handlers) == 0 { // Invoke the default message handler
142+
if len(handlers) == 0 && c.message != nil { // Invoke the default message handler
143143
c.message(c, m)
144144
}
145145

v2/options.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,22 @@ func WithAtMostOnce() Option {
149149
func WithAtLeastOnce() Option {
150150
return withQos1
151151
}
152+
153+
func getUTCTimestamp(input time.Time) int64 {
154+
t := input
155+
if zone, _ := t.Zone(); zone != "UTC" {
156+
loc, _ := time.LoadLocation("UTC")
157+
t = t.In(loc)
158+
}
159+
return t.Unix()
160+
}
161+
162+
// WithFrom request messages from a point in time.
163+
func WithFrom(from time.Time) Option {
164+
return option("from=" + strconv.FormatInt(getUTCTimestamp(from), 10))
165+
}
166+
167+
// WithUntil request messages until a point in time.
168+
func WithUntil(until time.Time) Option {
169+
return option("until=" + strconv.FormatInt(getUTCTimestamp(until), 10))
170+
}

0 commit comments

Comments
 (0)