Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/emitter-io/go
Browse files Browse the repository at this point in the history
  • Loading branch information
kelindar committed May 16, 2020
2 parents 4c236c2 + 540049c commit ea0462d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [kelindar]
4 changes: 2 additions & 2 deletions v2/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ func (c *Client) OnError(handler ErrorHandler) {

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

Expand Down
19 changes: 19 additions & 0 deletions v2/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,22 @@ func WithAtMostOnce() Option {
func WithAtLeastOnce() Option {
return withQos1
}

func getUTCTimestamp(input time.Time) int64 {
t := input
if zone, _ := t.Zone(); zone != "UTC" {
loc, _ := time.LoadLocation("UTC")
t = t.In(loc)
}
return t.Unix()
}

// WithFrom request messages from a point in time.
func WithFrom(from time.Time) Option {
return option("from=" + strconv.FormatInt(getUTCTimestamp(from), 10))
}

// WithUntil request messages until a point in time.
func WithUntil(until time.Time) Option {
return option("until=" + strconv.FormatInt(getUTCTimestamp(until), 10))
}

0 comments on commit ea0462d

Please sign in to comment.