ynab-portfolio-monitor/webServer.go
Steven Polley 4c904e7196
All checks were successful
continuous-integration/drone/push Build is passing
add web client - future plans for loading screen during refresh
2023-11-13 18:05:20 -07:00

43 lines
1.1 KiB
Go

package main
import (
"log"
"net/http"
)
func webServer() {
//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)
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) {
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()
}