add web client - future plans for loading screen during refresh
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
20
main.go
20
main.go
@@ -3,15 +3,19 @@ package main
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"deadbeef.codes/steven/ynab-portfolio-monitor/ynab"
|
||||
)
|
||||
|
||||
var (
|
||||
configuredProviders []AccountProvider // Any account providers that are successfully configured get added to this slice
|
||||
ynabClient *ynab.Client // YNAB HTTP client
|
||||
lastRefresh time.Time
|
||||
configuredProviders []AccountProvider // Any account providers that are successfully configured get added to this slice
|
||||
ynabClient *ynab.Client // YNAB HTTP client
|
||||
lastRefresh time.Time // Timestamp that last data refresh ran - used for rate limiting
|
||||
refreshRunning *sync.Mutex // True if a refresh is currently running
|
||||
t *template.Template // HTML templates in the templates directory
|
||||
)
|
||||
|
||||
// Called at program startup or if SIGHUP is received
|
||||
@@ -49,6 +53,13 @@ func init() {
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create ynab client: %v", err)
|
||||
}
|
||||
|
||||
// Web Templates
|
||||
// Parse all template files at startup
|
||||
t, err = template.ParseGlob("./templates/*")
|
||||
if err != nil {
|
||||
log.Fatalf("couldn't parse HTML templates: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -62,10 +73,13 @@ func main() {
|
||||
}
|
||||
|
||||
func refreshData() {
|
||||
refreshRunning.Lock()
|
||||
defer refreshRunning.Unlock()
|
||||
|
||||
// Only allow a refresh at most once every 5 minutes
|
||||
if time.Now().Before(lastRefresh.Add(time.Minute * 5)) {
|
||||
log.Printf("refresh rate limited")
|
||||
|
||||
return
|
||||
}
|
||||
lastRefresh = time.Now()
|
||||
|
Reference in New Issue
Block a user