提供动态长度响应数据

I have an app created with gin-gonic and golang. The app returns JSON on a request. My JSON is an array of some structures. I have structures created one by one, when all are ready i do output with c.String

func getData(c *gin.Context) {
    jsondoc, err := GetData()

    if err != nil {
        handleError(c, err)
        return
    }
    c.Header("Content-Type", "application/json; charset=utf-8")
    c.String(200, jsondoc)
}

I want to do some optimization. I want to start data sending to a user when not full JSON is ready. When i have first art of JSON i can start sending to a client browser.

Is it possible? To return some reader interface to a gin-gonic and it will read from it till open ?

Update. There is the function DataFromReader . Example, https://gin-gonic.com/api-example/serving-data-from-reader/ . But it requires to set a Content-Length . For my data i don't have this value. So, this header should not be set.

I have found that way to do this. It is simple, just write your response to c.Writer

func getData(c *gin.Context) {
    c.Statue(200)
    c.Header("Content-Type", "application/json; charset=utf-8")
    GetData(c.Writer)
}
func GetData(res io.Writer) {
    res.Write([]byte("["))
    res.Write(moreBytes)
    res.Write(moreBytes2)

..... res.Write([]byte("]")) }

But there is no good way to handle errors. This needs more tricky design