go

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. ...

Update Go Mod

Sep 26, 2021
go

Auto update direct dependencies in go.mod into latest stable version. go list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all\ | xargs -n 1 sh -c 'echo $0; go get -d $0 || true'

Share on: