34 lines
943 B
Go
34 lines
943 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"math/rand"
|
|
"net/http"
|
|
|
|
"sunshine.industries/temp-exercise/templates"
|
|
)
|
|
|
|
func randomDailyExpense() float32 {
|
|
return 10 + rand.Float32()*100
|
|
}
|
|
|
|
func main() {
|
|
|
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
component := templates.IndexPage(templates.PageData{
|
|
Balance: 500 + rand.Float32()*1000,
|
|
Expenses: []float32{randomDailyExpense(), randomDailyExpense(), randomDailyExpense(), randomDailyExpense(), randomDailyExpense(), randomDailyExpense(), randomDailyExpense()},
|
|
TotalThisMonth: 50 + rand.Float32()*600,
|
|
PercentComparedToLastMonth: -5 + 10*rand.Float32(),
|
|
})
|
|
component.Render(context.Background(), w)
|
|
})
|
|
|
|
staticFs := http.FileServer(http.Dir("./static"))
|
|
http.Handle("/static/", http.StripPrefix("/static/", staticFs))
|
|
|
|
fmt.Println("starting to serve on :3000")
|
|
http.ListenAndServe(":3000", nil)
|
|
}
|