feat(18): random input data
This commit is contained in:
parent
e81a22dd10
commit
ddc003eb13
|
@ -1,22 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"sunshine.industries/temp-exercise/templates"
|
||||
)
|
||||
|
||||
func main() {
|
||||
component := templates.IndexPage(templates.PageData{
|
||||
Balance: 1021.12,
|
||||
Expenses: []float32{37.45, 34.91, 37.36, 31.07, 7.39, 43.28, 25.48},
|
||||
TotalThisMonth: 612.41,
|
||||
PercentComparedToLastMonth: 3.1,
|
||||
})
|
||||
func randomDailyExpense() float32 {
|
||||
return 10 + rand.Float32()*100
|
||||
}
|
||||
|
||||
http.Handle("/", templ.Handler(component))
|
||||
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 * rand.Float32(),
|
||||
})
|
||||
component.Render(context.Background(), w)
|
||||
})
|
||||
|
||||
staticFs := http.FileServer(http.Dir("./static"))
|
||||
http.Handle("/static/", http.StripPrefix("/static/", staticFs))
|
||||
|
|
Loading…
Reference in New Issue