

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Server
incomplete
2: Content Length
incomplete
3: Response
incomplete
4: Other Common Headers
incomplete
5: Handler
incomplete
6: Code Review
incomplete
7: Refactor
incomplete
This lesson's interactive features are locked, please to keep using them
Now that we've got a lot of the boilerplate stuff out of the way, let's define our handler function. This will allow the users of our server package to define their own logic for handling requests. Here's the function signature we're going to use:
type Handler func(w io.Writer, req *request.Request) *HandlerError
Remember, the official Go stdlib uses this:
type HandlerFunc func(w http.ResponseWriter, r *http.Request)
The main differences between ours and the official one are:
io.Writer instead of http.ResponseWriterrequest.Request type that we just built.*HandlerError. It's just a structured error type that makes it easy to always return a proper status code and error message.Remember, our Handler is responsible for reporting errors or writing the body. Our server implementation takes care of the rest for now.
Run and submit the CLI tests.