https://github.com/gregoryv/ex
go package for writing simpler examples
https://github.com/gregoryv/ex
example go golang http json test
Last synced: 8 months ago
JSON representation
go package for writing simpler examples
- Host: GitHub
- URL: https://github.com/gregoryv/ex
- Owner: gregoryv
- License: mit
- Created: 2018-04-04T10:48:44.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-05-02T06:38:40.000Z (almost 6 years ago)
- Last Synced: 2025-03-30T05:13:21.126Z (10 months ago)
- Topics: example, go, golang, http, json, test
- Language: Go
- Homepage:
- Size: 30.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/gregoryv/ex)
[](https://codecov.io/gh/gregoryv/ex)
[ex](https://godoc.org/github.com/gregoryv/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!