feat: make age dynamic
This commit is contained in:
@@ -2,14 +2,27 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"math"
|
||||
"net/http"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/StevanFreeborn/links.stevanfreeborn.com/internal/assets"
|
||||
)
|
||||
|
||||
const DAYS_IN_YEAR = 365
|
||||
const HOURS_IN_DAY = 24
|
||||
|
||||
var birthday time.Time = time.Date(1993, time.April, 21, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
type IndexViewModel struct {
|
||||
Age float64
|
||||
}
|
||||
|
||||
func Index(w http.ResponseWriter, r *http.Request) {
|
||||
// Links coming in external JSON data
|
||||
// TODO: Links coming in external JSON data
|
||||
// this could be static file in the repo
|
||||
// or it could be fetched
|
||||
// { link: "link", text: "text", "icon": "icon" }
|
||||
|
||||
t, err := template.ParseFS(assets.Templates, "templates/index.gohtml")
|
||||
@@ -19,7 +32,13 @@ func Index(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
t.Execute(w, nil)
|
||||
age := time.Since(birthday).Hours() / HOURS_IN_DAY / DAYS_IN_YEAR
|
||||
|
||||
viewModel := IndexViewModel{
|
||||
Age: math.Floor(age),
|
||||
}
|
||||
|
||||
t.Execute(w, viewModel)
|
||||
}
|
||||
|
||||
func CSS(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user