json

Golang Ndjson Streams Server

Dec 25, 2021
go, json

Some time we got a large json data so clients can not buffer and read at once. So New Lines JSON is the rescue, this a POC version of golang that response a streams of lines into client. package main import ( "context" "net/http" "os/signal" "syscall" "time" "github.com/go-chi/chi" "github.com/go-chi/chi/middleware" "github.com/hienduyph/goss/httpx" "github.com/hienduyph/goss/jsonx" ) // let's generate some fake data func sampleStream() <-chan []byte { out := make(chan []byte, 10) go func() { for i := 0; i < 10; i++ { d := map[string]interface{}{"hello": i} buf, _ := jsonx. ...

Share on: