feat: added generic json payload decoder function

This commit is contained in:
2026-08-14 16:56:43 +02:00
parent d6b913a763
commit e0ab3bb51a
+20
View File
@@ -0,0 +1,20 @@
package request
import (
"encoding/json"
"fmt"
"net/http"
)
func DecodeJSON[T any](r *http.Request) (T, error) {
var payload T
decoder := json.NewDecoder(r.Body)
decoder.DisallowUnknownFields()
if err := decoder.Decode(&payload); err != nil {
return payload, fmt.Errorf("error decoding payload: %w", err)
}
return payload, nil
}