package main import ( "errors" "fmt" "net/http" "runtime/debug" "github.com/go-playground/form/v4" ) func (app *application) serverError(w http.ResponseWriter, err error) { trace := fmt.Sprintf("%s\n%s", err.Error(), debug.Stack()) app.errorLog.Output(2, trace) var errorText string if app.debug { errorText = trace } else { errorText = http.StatusText(http.StatusInternalServerError) } http.Error(w, errorText, http.StatusInternalServerError) } func (app *application) clientError(w http.ResponseWriter, status int) { http.Error(w, http.StatusText(status), status) } func (app *application) notFound(w http.ResponseWriter) { app.clientError(w, http.StatusNotFound) } func (app *application) decodePostForm(r *http.Request, templateForm any) error { err := r.ParseForm() if err != nil { return err } err = app.formDecoder.Decode(&templateForm, r.PostForm) if err != nil { var invalidDecoderError *form.InvalidDecoderError if errors.As(err, &invalidDecoderError) { panic("Invalid decoder error") } return err } return nil } func (app *application) isAuthenticated(r *http.Request) bool { isAuthenticated, ok := r.Context().Value(isAuthenticatedContextKey).(bool) if !ok { return false } return isAuthenticated }