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:
23
webServer.go
23
webServer.go
@@ -1,13 +1,11 @@
|
||||
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"))))
|
||||
@@ -15,13 +13,30 @@ func webServer() {
|
||||
// Page Handlers
|
||||
// Anything that is responsible for the base elements of a viewable web page
|
||||
http.HandleFunc("/", homePageHandler)
|
||||
http.HandleFunc("/status", statusHandler)
|
||||
|
||||
// Start web server
|
||||
log.Print("Service listening on :8080")
|
||||
log.Printf("Web server unexpectedly exiting!: %v", http.ListenAndServe(":8080", nil))
|
||||
}
|
||||
|
||||
type homePageData struct {
|
||||
BudgetID string
|
||||
}
|
||||
|
||||
func homePageHandler(w http.ResponseWriter, r *http.Request) {
|
||||
refreshData()
|
||||
http.Redirect(w, r, fmt.Sprintf("https://app.ynab.com/%s", ynabClient.BudgetID), http.StatusSeeOther)
|
||||
go refreshData()
|
||||
pageData := &homePageData{BudgetID: ynabClient.BudgetID}
|
||||
err := t.ExecuteTemplate(w, "home.html", pageData)
|
||||
if err != nil {
|
||||
log.Printf("error executing home.html template: %v", err)
|
||||
}
|
||||
|
||||
//http.Redirect(w, r, fmt.Sprintf("https://app.ynab.com/%s", ynabClient.BudgetID), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func statusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
refreshRunning.Lock()
|
||||
w.WriteHeader(http.StatusOK)
|
||||
refreshRunning.Unlock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user