package Api

import (
	"encoding/json"
	"log"
	"net/http"
)

func JsonReturn(w http.ResponseWriter, code int, msg string) {
	var (
		responseJsonMap map[string]interface{}
		responseJson    []byte
		err             error
	)

	responseJsonMap = make(map[string]interface{})

	w.WriteHeader(code)
	responseJsonMap["code"] = code
	responseJsonMap["message"] = msg

	responseJson, err = json.MarshalIndent(responseJsonMap, "", "  ")
	if err != nil {
		log.Printf("Error occured creating response: %s\n", err.Error())
	}

	w.Write(responseJson)
}
