feat(18): random input data
This commit is contained in:
parent
e81a22dd10
commit
ddc003eb13
|
@ -1,22 +1,29 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/a-h/templ"
|
|
||||||
"sunshine.industries/temp-exercise/templates"
|
"sunshine.industries/temp-exercise/templates"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func randomDailyExpense() float32 {
|
||||||
component := templates.IndexPage(templates.PageData{
|
return 10 + rand.Float32()*100
|
||||||
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,
|
|
||||||
})
|
|
||||||
|
|
||||||
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"))
|
staticFs := http.FileServer(http.Dir("./static"))
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", staticFs))
|
http.Handle("/static/", http.StripPrefix("/static/", staticFs))
|
||||||
|
|
Loading…
Reference in New Issue