tests and cleanup

This commit is contained in:
Livio Amstutz 2021-10-28 15:21:47 +02:00
parent d0b8dfe340
commit 1d72aff00a
11 changed files with 468 additions and 123 deletions

View file

@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"reflect"
)
func MarshalJSON(w http.ResponseWriter, i interface{}) {
@ -14,7 +15,7 @@ func MarshalJSON(w http.ResponseWriter, i interface{}) {
func MarshalJSONWithStatus(w http.ResponseWriter, i interface{}, status int) {
w.Header().Set("content-type", "application/json")
w.WriteHeader(status)
if i == nil {
if i == nil || (reflect.ValueOf(i).Kind() == reflect.Ptr && reflect.ValueOf(i).IsNil()) {
return
}
err := json.NewEncoder(w).Encode(i)