pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/gophercises/recover

mous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/primer-71a44d5be3f782c5.css" /> GitHub - gophercises/recover: Ex 14 - Panic/Recover Middleware for HTTP Servers
Skip to content

gophercises/recover

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Exercise #14: Panic/Recover Middleware

exercise status: released

Exercise details

In the recover exercise we will be looking at the panic and recover mechanisms in Go and utilizing them to create middleware for an HTTP server.

Given a simple web server (see main.go) that can potentially panic, create an http.Handler that wraps the existing mux and will recover from any panics and then does the following:

  1. Logs the error, as well as the stack trace.
  2. Sets the status code to http.StatusInternalServerError (500) whenever a panic occurs.
  3. Write a "Something went wrong" message when a panic occurs.
  4. Ensure that partial writes and 200 headers aren't set even if the handler started writing to the http.ResponseWriter BEFORE the panic occurred (this one may be trickier)
  5. If the environment is set to be development, print the stack trace and the error to the webpage as well as to the logs. Otherwise default to the "Something went wrong" message described in (3).

Bonus

As a bonus exercises you can also look at ways to ensure you don't lose functionality like implementing the http.Flusher or the http.Hijacker interfaces.

Useful links

About

Ex 14 - Panic/Recover Middleware for HTTP Servers

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy