diff --git a/main.go b/main.go index 593ba19..ffea116 100644 --- a/main.go +++ b/main.go @@ -2,19 +2,43 @@ package main import ( "fmt" + "html/template" "net/http" "time" ) func main() { + // Главная страница http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Hello from Dockerized Go App!") + tmpl := template.Must(template.ParseFiles("templates/index.html")) + tmpl.Execute(w, nil) }) - http.HandleFunc("/time", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Current time: %s", time.Now().Format(time.RFC1123)) + // 1. Возвращаем фрагмент времени + http.HandleFunc("/get-time", func(w http.ResponseWriter, r *http.Request) { + currentTime := time.Now().Format("15:04:05") + fmt.Fprintf(w, "Текущее время: %s", currentTime) }) - fmt.Println("Server starting on :8080...") + // 2. Обработка формы (возвращаем только новый элемент списка) + http.HandleFunc("/add-item", func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPost { + http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) + return + } + item := r.FormValue("item") + // Возвращаем фрагмент