package util

import (
	"encoding/json"
	"io"
)

// DecodeJSON decodes json
func DecodeJSON(src io.Reader, dst interface{}) error {
	decoder := json.NewDecoder(src)
	err := decoder.Decode(dst)
	return err
}

// EncodeJSON encodes json
func EncodeJSON(dst io.Writer, src interface{}) error {
	encoder := json.NewEncoder(dst)
	err := encoder.Encode(src)
	return err
}

func WriteErrorJSON(dst io.Writer, errorMsg string) error {
	response := make(map[string]interface{})
	response["ok"] = false
	response["failureReason"] = "Request does not have the header \"Content-Type: application-json\""
	return EncodeJSON(dst, response)
}

package util

import (
	"encoding/json"
	"io"
)

// DecodeJSON decodes json
func DecodeJSON(src io.Reader, dst interface{}) error {
	decoder := json.NewDecoder(src)
	err := decoder.Decode(dst)
	return err
}

// EncodeJSON encodes json
func EncodeJSON(dst io.Writer, src interface{}) error {
	encoder := json.NewEncoder(dst)
	err := encoder.Encode(src)
	return err
}

func WriteErrorJSON(dst io.Writer, errorMsg string) error {
	response := make(map[string]interface{})
	response["ok"] = false
	response["failureReason"] = errorMsg
	return EncodeJSON(dst, response)
}

Fix message written to by util function
Fix message written to by util function
