Calc dates and add config struct fields #2
@ -17,4 +17,7 @@ services:
|
|||||||
- DOMAIN=hogelandlinux.nl # Set your actual domain here
|
- DOMAIN=hogelandlinux.nl # Set your actual domain here
|
||||||
- TELEGRAM_BOT_TOKEN= # Set your Telegram bot token here
|
- TELEGRAM_BOT_TOKEN= # Set your Telegram bot token here
|
||||||
- TELEGRAM_CHAT_ID= # Set your Telegram chat ID here
|
- TELEGRAM_CHAT_ID= # Set your Telegram chat ID here
|
||||||
|
- ABOUT_NAME=Bdnugget
|
||||||
|
- BIRTH_DATE=1990-01-01
|
||||||
|
- SON_BIRTH_DATE=2022-01-01
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
BIN
linuxservice
BIN
linuxservice
Binary file not shown.
27
main.go
27
main.go
@ -27,6 +27,9 @@ type Config struct {
|
|||||||
Port string
|
Port string
|
||||||
TelegramBotToken string
|
TelegramBotToken string
|
||||||
TelegramChatID string
|
TelegramChatID string
|
||||||
|
AboutName string
|
||||||
|
BirthDate string
|
||||||
|
SonBirthDate string
|
||||||
}
|
}
|
||||||
|
|
||||||
// PageData holds data for template rendering
|
// PageData holds data for template rendering
|
||||||
@ -89,6 +92,9 @@ func NewServer() *Server {
|
|||||||
Port: ":" + getEnv("PORT", "8080"),
|
Port: ":" + getEnv("PORT", "8080"),
|
||||||
TelegramBotToken: getEnv("TELEGRAM_BOT_TOKEN", ""), // Set this in environment
|
TelegramBotToken: getEnv("TELEGRAM_BOT_TOKEN", ""), // Set this in environment
|
||||||
TelegramChatID: getEnv("TELEGRAM_CHAT_ID", ""), // Set this in environment
|
TelegramChatID: getEnv("TELEGRAM_CHAT_ID", ""), // Set this in environment
|
||||||
|
AboutName: getEnv("ABOUT_NAME", "Bdnugget"),
|
||||||
|
BirthDate: getEnv("BIRTH_DATE", "1990-01-01"),
|
||||||
|
SonBirthDate: getEnv("SON_BIRTH_DATE", "2022-01-01"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse templates with error handling
|
// Parse templates with error handling
|
||||||
@ -317,22 +323,25 @@ func (s *Server) healthHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// aboutHandler handles the About Me page
|
// aboutHandler handles the About Me page
|
||||||
func (s *Server) aboutHandler(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) aboutHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := s.createPageData("Over mij - "+s.config.CompanyName, "about")
|
data := s.createPageData("Over mij - "+s.config.CompanyName, "about")
|
||||||
// Populate dynamic About fields
|
// Populate dynamic About fields from config/env
|
||||||
data.AboutName = "Brendon Bosman"
|
data.AboutName = s.config.AboutName
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
birthYear, birthMonth, birthDay := 1990, time.October, 17
|
// Parse BirthDate (ISO YYYY-MM-DD)
|
||||||
age := now.Year() - birthYear
|
if t, err := time.Parse("2006-01-02", s.config.BirthDate); err == nil {
|
||||||
if now.Month() < birthMonth || (now.Month() == birthMonth && now.Day() < birthDay) {
|
age := now.Year() - t.Year()
|
||||||
|
if now.Month() < t.Month() || (now.Month() == t.Month() && now.Day() < t.Day()) {
|
||||||
age--
|
age--
|
||||||
}
|
}
|
||||||
data.AgeYears = age
|
data.AgeYears = age
|
||||||
|
}
|
||||||
sonYear, sonMonth, sonDay := 2022, time.March, 11
|
// Parse SonBirthDate (ISO YYYY-MM-DD)
|
||||||
sonAge := now.Year() - sonYear
|
if t, err := time.Parse("2006-01-02", s.config.SonBirthDate); err == nil {
|
||||||
if now.Month() < sonMonth || (now.Month() == sonMonth && now.Day() < sonDay) {
|
sonAge := now.Year() - t.Year()
|
||||||
|
if now.Month() < t.Month() || (now.Month() == t.Month() && now.Day() < t.Day()) {
|
||||||
sonAge--
|
sonAge--
|
||||||
}
|
}
|
||||||
data.SonAgeYears = sonAge
|
data.SonAgeYears = sonAge
|
||||||
|
}
|
||||||
|
|
||||||
s.renderTemplate(w, "over-mij.html", data)
|
s.renderTemplate(w, "over-mij.html", data)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user