package handlers import ( "apjournal/config" "html/template" "log/slog" "net/http" "os" ) // Handlers structure type Handlers struct { cfg config.Config // s *service.Service log *slog.Logger } // NewHandlers constructor func NewHandlers( // cfg config.Config, s *service.Service, l *slog.Logger, cfg config.Config, l *slog.Logger, ) *Handlers { if l == nil { l = slog.New(slog.NewJSONHandler(os.Stdout, nil)) } h := &Handlers{ cfg: cfg, // s: s, log: l, } return h } func (h *Handlers) Ping(w http.ResponseWriter, r *http.Request) { h.log.Info("got ping request") w.Write([]byte("pong")) } func (h *Handlers) MainPage(w http.ResponseWriter, r *http.Request) { h.log.Info("got mainpage request") tmpl := template.Must(template. ParseFiles("components/index.html")) hardcodedName := "Guest" tmpl.Execute(w, hardcodedName) } func (h *Handlers) HandleForm(w http.ResponseWriter, r *http.Request) { r.ParseForm() h.log.Info("got postform request", "payload", r.PostForm) }