Skip to content

gregoryv/ex

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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!

About

go package for writing simpler examples

Topics

Resources

License

Stars

Watchers

Forks

Languages