콘텐츠로 이동

응답 본문

go-zero에서 응답 본문은 http.ResponseWriterWrite 메서드로 작성하고, 응답 header는 Header 메서드로 설정합니다. XML 같은 추가 응답 형식이 필요하다면 zeromicro/x 확장 패키지의 https://github.com/zeromicro/x/blob/main/http/responses.go를 참고하세요.

type Response struct {
Name string `json:"name"`
Age int `json:"age"`
}
resp := &Response{Name: "jack", Age: 18}
httpx.OkJson(w, resp)