package webServer

import (
	"encoding/json"
	"fmt"
	"goutil/logUtilPlus"
	"net/http"
	"strconv"
)

// responseResult
// @description: responseResult
// parameter:
// @w: w
// @responseObj: responseObj
// return:
func responseResult(w http.ResponseWriter, responseObj *ResponseObject) {
	b, err := json.Marshal(responseObj)
	if err != nil {
		logUtilPlus.ErrorLog(fmt.Sprintf("序列化输出结果%v出错", responseObj))
		return
	}

	w.Header().Add("Content-Length", strconv.Itoa(len(b)))
	w.Write(b)
}

// responseResultByJson
// @description: responseResult
// parameter:
// @w: w
// @responseObj: responseObj
// return:
func responseResultByJson(w http.ResponseWriter, responseObj *ResponseObject) {
	b, err := json.Marshal(responseObj)
	if err != nil {
		logUtilPlus.ErrorLog(fmt.Sprintf("序列化输出结果%v出错", responseObj))
		return
	}

	w.Header().Add("Content-Length", strconv.Itoa(len(b)))
	w.Write(b)
}
