Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/entrlcom/go-http-request-body-json-decoder
HTTP request body JSON decoder
https://github.com/entrlcom/go-http-request-body-json-decoder
go golang http http-request json request-body security
Last synced: 2 months ago
JSON representation
HTTP request body JSON decoder
- Host: GitHub
- URL: https://github.com/entrlcom/go-http-request-body-json-decoder
- Owner: entrlcom
- License: mit
- Created: 2024-06-11T19:59:30.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-06-12T07:13:52.000Z (7 months ago)
- Last Synced: 2024-06-19T04:48:54.900Z (7 months ago)
- Topics: go, golang, http, http-request, json, request-body, security
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HTTP request body JSON decoder
## Table of Content
- [Examples](#examples)
- [License](#license)## Examples
```go
package mainimport (
"net/http"
"time""entrlcom.dev/http-request-body-json-decoder"
)const maxBytes = 1 << (10 * 1) * 2 // 2 KiB.
type Request struct {
DateOfBirth time.Time `json:"date_of_birth"`
Email string `json:"email"`
Name string `json:"name"`
Password string `json:"password"`
}func Handle(w http.ResponseWriter, r *http.Request) {
var request Request// Decode HTTP request body to struct.
if err := http_request_body_json_decoder.Decode(w, r, &request, maxBytes); err != nil {
// TODO: Handle error.
return
}// ...
}```
## License
[MIT](https://choosealicense.com/licenses/mit/)