Skip to content

Commit 96a1812

Browse files
committed
test: Handle, writeResponse, handleErr, (intOrString) UnmarshalJson
1 parent c6c8f86 commit 96a1812

File tree

3 files changed

+420
-14
lines changed

3 files changed

+420
-14
lines changed

backend/pkg/api/handlers/handler_service.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package handlers
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/json"
67
"errors"
@@ -71,6 +72,9 @@ func Handle[Input InputValidator[Input], Response any](defaultCode int, logicFun
7172
return func(w http.ResponseWriter, r *http.Request) {
7273
// prepare input
7374
vars := mux.Vars(r)
75+
if vars == nil {
76+
vars = make(map[string]string)
77+
}
7478
q := r.URL.Query()
7579
for k, v := range q {
7680
if _, ok := vars[k]; ok || len(v) == 0 {
@@ -593,6 +597,9 @@ type intOrString struct {
593597
}
594598

595599
func (v *intOrString) UnmarshalJSON(data []byte) error {
600+
if bytes.Equal(data, []byte("null")) {
601+
return fmt.Errorf("null value not allowed")
602+
}
596603
// Attempt to unmarshal as uint64 first
597604
var intValue uint64
598605
if err := json.Unmarshal(data, &intValue); err == nil {

0 commit comments

Comments
 (0)