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: 10 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 (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-12T07:13:52.000Z (over 1 year ago)
- Last Synced: 2025-02-13T09:47:51.116Z (12 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 main
import (
"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/)