From 6ee99a0679318b0bbc8e3ca871aa794cbd70b63d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Dvo=C5=99=C3=A1k?= <150935816+Dvorinka@users.noreply.github.com> Date: Thu, 22 May 2025 09:58:30 +0200 Subject: [PATCH] Add files via upload --- Makefile | 11 ++ contact-scrape-test/Dockerfile | 4 +- contact-scrape-test/Makefile | 2 +- contact-scrape-test/contact-scrape.service | 2 +- main.go | 192 +++++++++++++++++++-- 5 files changed, 197 insertions(+), 14 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b03f3f4 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +.PHONY: dev install + +dev: + @echo "Starting development server..." + go run main.go + +install: + @echo "Installing dependencies..." + go mod tidy + go get -u gopkg.in/gomail.v2 + @echo "Build complete. Run with: go run main.go" diff --git a/contact-scrape-test/Dockerfile b/contact-scrape-test/Dockerfile index e28c095..f8c9dec 100644 --- a/contact-scrape-test/Dockerfile +++ b/contact-scrape-test/Dockerfile @@ -45,11 +45,11 @@ RUN mkdir -p data && chown -R appuser:appgroup /app USER appuser # Expose port -EXPOSE 8080 +EXPOSE 80 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ - CMD wget --no-verbose --tries=1 --spider http://localhost:8080/ || exit 1 + CMD wget --no-verbose --tries=1 --spider http://localhost:80/ || exit 1 # Run the application CMD ["./contact-scrape"] \ No newline at end of file diff --git a/contact-scrape-test/Makefile b/contact-scrape-test/Makefile index 6043f99..3370087 100644 --- a/contact-scrape-test/Makefile +++ b/contact-scrape-test/Makefile @@ -5,7 +5,7 @@ # Variables BINARY_NAME=contact-scrape BUILD_DIR=build -PORT=8080 +PORT=80 help: ## Show this help message @echo "Available commands:" diff --git a/contact-scrape-test/contact-scrape.service b/contact-scrape-test/contact-scrape.service index ff60678..954aa48 100644 --- a/contact-scrape-test/contact-scrape.service +++ b/contact-scrape-test/contact-scrape.service @@ -9,7 +9,7 @@ WorkingDirectory=/opt/contact-scrape ExecStart=/opt/contact-scrape/contact-scrape Restart=always RestartSec=5 -Environment=PORT=8080 +Environment=PORT=80 # Security settings NoNewPrivileges=true diff --git a/main.go b/main.go index a287b19..fed7ed8 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,171 @@ type GeoCoords struct { Lng string `json:"lng"` } +type Contact struct { + Name string `json:"name"` + Position string `json:"position"` + Phone string `json:"phone"` + ServicePhone string `json:"service_phone"` + Table int `json:"table"` +} + +func getEmbeddedHTML() string { + return ` + + + + + Kontakty + + + +
+
+

Kontakty

+
+
+
+
Seznam kontaktů
+
+
+ Jméno + Jan Novák +
+
+ Pozice + Ředitel +
+
+
+
+ Telefon + +420 123 456 789 +
+
+ Služební telefon + +420 987 654 321 +
+
+
+ Stůl + 1 +
+
+
+ +
+ + + ` +} + func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) @@ -42,8 +207,16 @@ func main() { w.Write([]byte(`{"status":"ok"}`)) })) + http.HandleFunc("/contacts", enableCORS(handleContacts)) + http.HandleFunc("/reload", enableCORS(handleReload)) + http.HandleFunc("/", enableCORS(func(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, "index.html") + if r.URL.Path == "/kontakty" { + w.Header().Set("Content-Type", "text/html") + w.Write([]byte(getEmbeddedHTML())) + return + } + http.ServeFile(w, r, r.URL.Path[1:]) })) http.HandleFunc("/evidence-aut", enableCORS(func(w http.ResponseWriter, r *http.Request) { @@ -126,19 +299,16 @@ func handleSubmit(w http.ResponseWriter, r *http.Request) { return } - // Formátování dat do českého formátu czechMonths := []string{ "ledna", "února", "března", "dubna", "května", "června", "července", "srpna", "září", "října", "listopadu", "prosince", } - // Zpracování začátku cesty parsedDateStart, err := time.Parse("2006-01-02", entry.DateStart) if err != nil { log.Printf("Chyba při parsování data začátku: %v", err) } - // Zpracování konce cesty parsedDateEnd, err := time.Parse("2006-01-02", entry.DateEnd) if err != nil { log.Printf("Chyba při parsování data konce: %v", err) @@ -313,7 +483,6 @@ func sendEmail(entry TripEntry, parsedDateStart, parsedDateEnd time.Time, czechM
`) - // Formátování dat a časů pro zobrazení formattedDateStart := "" if parsedDateStart.IsZero() == false { monthNameStart := czechMonths[parsedDateStart.Month()-1] @@ -330,7 +499,6 @@ func sendEmail(entry TripEntry, parsedDateStart, parsedDateEnd time.Time, czechM formattedDateEnd = entry.DateEnd } - // Výpočet celkové doby jízdy startDateTime, startErr := time.Parse("2006-01-02T15:04", fmt.Sprintf("%sT%s", entry.DateStart, entry.TimeStart)) endDateTime, endErr := time.Parse("2006-01-02T15:04", fmt.Sprintf("%sT%s", entry.DateEnd, entry.TimeEnd)) @@ -356,7 +524,6 @@ func sendEmail(entry TripEntry, parsedDateStart, parsedDateEnd time.Time, czechM } } - // Vypsání informací o řidiči a vozidle htmlContent.WriteString(`
Informace o řidiči a vozidle
@@ -371,7 +538,6 @@ func sendEmail(entry TripEntry, parsedDateStart, parsedDateEnd time.Time, czechM
`) - // Vypsání informací o trase htmlContent.WriteString(`
Informace o trase
@@ -386,7 +552,6 @@ func sendEmail(entry TripEntry, parsedDateStart, parsedDateEnd time.Time, czechM
`) - // Vypsání informací o času htmlContent.WriteString(`
Časové údaje
@@ -405,7 +570,6 @@ func sendEmail(entry TripEntry, parsedDateStart, parsedDateEnd time.Time, czechM
`) - // Vypsání informací o kilometrech htmlContent.WriteString(`
Stav tachometru
@@ -456,3 +620,11 @@ func sendEmail(entry TripEntry, parsedDateStart, parsedDateEnd time.Time, czechM return d.DialAndSend(m) } + +func handleContacts(w http.ResponseWriter, r *http.Request) { + // Implement contact listing logic +} + +func handleReload(w http.ResponseWriter, r *http.Request) { + // Implement contact reload logic +}