Skip to content
go package for writing simpler examples
Go Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
vendor
.gitignore
.travis.yml
CHANGELOG.md
README.md
bodywriter.go
bodywriter_test.go
doc.go
go.mod
go.sum
headerwriter.go
headerwriter_test.go
jsonwriter.go
jsonwriter_test.go
multipart.go
multipart_test.go
onchange.sh
panic_test.go
print.go
print_test.go
qa_test.go
statuswriter.go
statuswriter_test.go

README.md

Build Status codecov

ex - implements interfaces which write output to stdout

This is useful for writing short Examples in go, eg. when testing output from http handlers.

Examples

Writers implement the http.ResponseWriter interface

JsonWriter

r := bytes.NewBufferString(`{"name":"John","car":{"model":"x,2","plate":"abc123"}}`)
io.Copy(jsonWriter, r)

Output:

{
    "name":"John",
    "car":{
        "model":"x,2",
        "plate":"abc123"
    }
}

StatusWriter

w := NewStatusWriter()
w.Write([]byte("Hello, world!"))

Output:

200

BodyWriter

bodyWriter.Write([]byte("Hello, world!"))

Output:

Hello, world!
You can’t perform that action at this time.