Permalink
Browse files

Refuse to Log when event.Time is not UTC.

This reduces API usage ambiguity.
  • Loading branch information...
dmitshur committed Nov 30, 2017
1 parent 0391269 commit 6e7b11cd3a3dace1899fa955272da6c6a876f52f
Showing with 13 additions and 0 deletions.
  1. +1 −0 events.go
  2. +7 −0 fs/fs.go
  3. +5 −0 githubapi/githubapi.go
View
@@ -18,6 +18,7 @@ type Service interface {
// ExternalService for events.
type ExternalService interface {
// Log logs the event.
// event.Time time zone must be UTC.
Log(ctx context.Context, event event.Event) error
}
View
@@ -3,8 +3,10 @@ package fs
import (
"context"
"errors"
"os"
"sync"
"time"
"github.com/shurcooL/events"
"github.com/shurcooL/events/event"
@@ -64,7 +66,12 @@ func (s *service) List(_ context.Context) ([]event.Event, error) {
}
// Log logs the event.
// event.Time time zone must be UTC.
func (s *service) Log(ctx context.Context, event event.Event) error {
if event.Time.Location() != time.UTC {
return errors.New("event.Time time zone must be UTC")
}
if event.Actor.UserSpec != s.user {
// Skip other users.
return nil
View
@@ -3,6 +3,7 @@ package githubapi
import (
"context"
"errors"
"fmt"
"io/ioutil"
"log"
@@ -52,7 +53,11 @@ func (s *service) List(_ context.Context) ([]event.Event, error) {
}
// Log logs the event.
// event.Time time zone must be UTC.
func (s *service) Log(_ context.Context, event event.Event) error {
if event.Time.Location() != time.UTC {
return errors.New("event.Time time zone must be UTC")
}
// Nothing to do. GitHub takes care of this on their end, even when performing actions via API.
return nil
}

0 comments on commit 6e7b11c

Please sign in to comment.