mirror of
https://github.com/jimeh/go-render.git
synced 2026-02-19 03:16:39 +00:00
refactor: focus around Render/Compact/Pretty/NewWith functions
This is yet another drastic refactor of public API and concepts. Hopefully the last one, as I'm now fairly happy with things.
This commit is contained in:
12
text.go
12
text.go
@@ -5,8 +5,10 @@ import (
|
||||
"io"
|
||||
)
|
||||
|
||||
// Text is a renderer that writes the given value to the writer as is. It
|
||||
// supports rendering the following types as plain text:
|
||||
// Text is a Handler that writes the given value to the writer as text,
|
||||
// supporting multiple types and interfaces.
|
||||
//
|
||||
// Supports rendering the following types as text:
|
||||
//
|
||||
// - []byte
|
||||
// - []rune
|
||||
@@ -23,7 +25,10 @@ import (
|
||||
// If the value is of any other type, a ErrCannotRender error will be returned.
|
||||
type Text struct{}
|
||||
|
||||
var _ FormatRenderer = (*Text)(nil)
|
||||
var (
|
||||
_ Handler = (*Text)(nil)
|
||||
_ FormatsHandler = (*Text)(nil)
|
||||
)
|
||||
|
||||
// Render writes the given value to the writer as text.
|
||||
func (t *Text) Render(w io.Writer, v any) error {
|
||||
@@ -58,6 +63,7 @@ func (t *Text) Render(w io.Writer, v any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Formats returns a list of format strings that this Handler supports.
|
||||
func (t *Text) Formats() []string {
|
||||
return []string{"text", "txt", "plain"}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user