1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

20191215 code improvements (#790)

* Upgrade godo to latest
* Fix a bunch of issues found by
* Running staticcheck on a codebase for the first time is a sobering experience
* go mod tidy
* More static improvements

Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
Chris Cummer
2019-12-16 20:25:29 -08:00
committed by GitHub
parent e71038ccf2
commit 3a388fba23
65 changed files with 236 additions and 815 deletions

View File

@@ -52,7 +52,7 @@ func (calEvent *CalEvent) Past() bool {
return false
}
return (calEvent.Now() == false) && calEvent.Start().Before(time.Now())
return !calEvent.Now() && calEvent.Start().Before(time.Now())
}
func (calEvent *CalEvent) ResponseFor(email string) string {

View File

@@ -23,6 +23,7 @@ import (
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"google.golang.org/api/calendar/v3"
"google.golang.org/api/option"
)
/* -------------------- Exported Functions -------------------- */
@@ -43,13 +44,11 @@ func (widget *Widget) Fetch() ([]*CalEvent, error) {
}
client := getClient(ctx, config)
srv, err := calendar.New(client)
srv, err := calendar.NewService(context.Background(), option.WithHTTPClient(client))
if err != nil {
return nil, err
}
calendarIds, err := widget.getCalendarIdList(srv)
// Get calendar events
var events calendar.Events
@@ -58,8 +57,9 @@ func (widget *Widget) Fetch() ([]*CalEvent, error) {
timezone := widget.settings.timezone
for _, calendarId := range calendarIds {
calendarEvents, err := srv.Events.List(calendarId).TimeZone(timezone).ShowDeleted(false).TimeMin(startTime).MaxResults(eventLimit).SingleEvents(true).OrderBy("startTime").Do()
calendarIDs, err := widget.getCalendarIdList(srv)
for _, calendarID := range calendarIDs {
calendarEvents, err := srv.Events.List(calendarID).TimeZone(timezone).ShowDeleted(false).TimeMin(startTime).MaxResults(eventLimit).SingleEvents(true).OrderBy("startTime").Do()
if err != nil {
break
}
@@ -132,9 +132,9 @@ func (widget *Widget) authenticate() {
log.Fatalf("Unable to read secret file. %v", widget.settings.secretFile)
}
config, err := google.ConfigFromJSON(b, calendar.CalendarReadonlyScope)
config, _ := google.ConfigFromJSON(b, calendar.CalendarReadonlyScope)
tok := getTokenFromWeb(config)
cacheFile, err := tokenCacheFile()
cacheFile, _ := tokenCacheFile()
saveToken(cacheFile, tok)
}
@@ -150,7 +150,7 @@ func getTokenFromWeb(config *oauth2.Config) *oauth2.Token {
log.Fatalf("Unable to read authorization code %v", err)
}
tok, err := config.Exchange(oauth2.NoContext, code)
tok, err := config.Exchange(context.Background(), code)
if err != nil {
log.Fatalf("Unable to retrieve token from web %v", err)
}

View File

@@ -9,21 +9,6 @@ import (
"github.com/wtfutil/wtf/utils"
)
func (widget *Widget) sortedEvents() ([]*CalEvent, []*CalEvent) {
allDayEvents := []*CalEvent{}
timedEvents := []*CalEvent{}
for _, calEvent := range widget.calEvents {
if calEvent.AllDay() {
allDayEvents = append(allDayEvents, calEvent)
} else {
timedEvents = append(timedEvents, calEvent)
}
}
return allDayEvents, timedEvents
}
func (widget *Widget) display() {
widget.Redraw(widget.content)
}
@@ -183,7 +168,7 @@ func (widget *Widget) titleColor(calEvent *CalEvent) string {
strings.ToLower(calEvent.event.Summary),
)
if match == true {
if match {
color = highlightElements[1]
}
}
@@ -196,7 +181,7 @@ func (widget *Widget) titleColor(calEvent *CalEvent) string {
}
func (widget *Widget) location(calEvent *CalEvent) string {
if widget.settings.withLocation == false {
if !widget.settings.withLocation {
return ""
}
@@ -212,7 +197,7 @@ func (widget *Widget) location(calEvent *CalEvent) string {
}
func (widget *Widget) responseIcon(calEvent *CalEvent) string {
if widget.settings.displayResponseStatus == false {
if !widget.settings.displayResponseStatus {
return ""
}