tests and cleanup
This commit is contained in:
parent
d0b8dfe340
commit
1d72aff00a
11 changed files with 468 additions and 123 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue