Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4: Authentication HTTP handlers #36

Merged
merged 11 commits into from
Apr 15, 2024
Merged

4: Authentication HTTP handlers #36

merged 11 commits into from
Apr 15, 2024

Conversation

willemschots
Copy link
Owner

This PR adds the POST /register endpoint and a supporting types for implementing further HTTP handlers.

Generic handlers

Earlier I wrote a post about generic HTTP handlers, this PR expands on the code from the article by introducing a generic "mapper" with three types of constructor functions:

  • mapRequest: maps a HTTP request to target function input.
  • mapResponse: maps the result of a target function to a HTTP response.
  • mapBoth: maps both of the above.

The mapper allows for functionality to be overwritten when needed, this will be especially handy for mapping responses: For some endpoints we might want to redirect to another URL, while for others we will want to return a 2xx status code and a body.

At the moment input is mapped using the gorilla/schema package. It checks if types implement encoding.TextMarshaler so works pretty well with our custom types.

The code can be found in internal/web/mapper.go. Check it out.

@willemschots willemschots self-assigned this Apr 12, 2024
@willemschots
Copy link
Owner Author

Note: Linter is failing because of unused code, will be fixed when I implement the other endpoints this weekend :)

@willemschots willemschots merged commit 7803b39 into main Apr 15, 2024
2 checks passed
@willemschots willemschots deleted the 4-http-handlers branch April 15, 2024 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant