Skip to content

Commit

Permalink
test: Handle, writeResponse, handleErr, `(intOrString) Unmarsha…
Browse files Browse the repository at this point in the history
…lJson`
  • Loading branch information
LuccaBitfly committed Feb 13, 2025
1 parent bb80db9 commit 5fe7747
Show file tree
Hide file tree
Showing 3 changed files with 417 additions and 14 deletions.
7 changes: 7 additions & 0 deletions backend/pkg/api/handlers/handler_service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handlers

import (
"bytes"
"context"
"encoding/json"
"errors"
Expand Down Expand Up @@ -71,6 +72,9 @@ func Handle[Input InputValidator[Input], Response any](defaultCode int, logicFun
return func(w http.ResponseWriter, r *http.Request) {
// prepare input
vars := mux.Vars(r)
if vars == nil {
vars = make(map[string]string)
}
q := r.URL.Query()
for k, v := range q {
if _, ok := vars[k]; ok || len(v) == 0 {
Expand Down Expand Up @@ -593,6 +597,9 @@ type intOrString struct {
}

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

0 comments on commit 5fe7747

Please sign in to comment.