add webserver for refresh hook
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:
parent
7a2e79682c
commit
a95df7c42b
15
main.go
15
main.go
@ -50,9 +50,17 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main program loop
|
|
||||||
func main() {
|
func main() {
|
||||||
for {
|
go webServer()
|
||||||
|
|
||||||
|
for { // Main program loop
|
||||||
|
refreshData()
|
||||||
|
log.Print("Sleeping for 6 hours...")
|
||||||
|
time.Sleep(time.Hour * 6)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func refreshData() {
|
||||||
// Loop through each configured account provider and attempt to get the account balances, and update YNAB
|
// Loop through each configured account provider and attempt to get the account balances, and update YNAB
|
||||||
for _, p := range configuredProviders {
|
for _, p := range configuredProviders {
|
||||||
balances, accountIDs, err := p.GetBalances()
|
balances, accountIDs, err := p.GetBalances()
|
||||||
@ -71,7 +79,4 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Print("Sleeping for 6 hours...")
|
|
||||||
time.Sleep(time.Hour * 6)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
27
webServer.go
Normal file
27
webServer.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func webServer() {
|
||||||
|
// Start web server
|
||||||
|
|
||||||
|
//Public static files
|
||||||
|
http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir("public"))))
|
||||||
|
|
||||||
|
// Page Handlers
|
||||||
|
// Anything that is responsible for the base elements of a viewable web page
|
||||||
|
http.HandleFunc("/", homePageHandler)
|
||||||
|
|
||||||
|
log.Print("Service listening on :8080")
|
||||||
|
log.Printf("Web server unexpectedly exiting!: %v", http.ListenAndServe(":8080", nil))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func homePageHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
refreshData()
|
||||||
|
http.Redirect(w, r, fmt.Sprintf("https://app.ynab.com/%s", ynabClient.BudgetID), http.StatusSeeOther)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user