mirror of
https://github.com/jimeh/go-render.git
synced 2026-02-19 11:26:39 +00:00
refactor!: sizeable changes across the board
This commit is contained in:
28
text.go
Normal file
28
text.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package render
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
type Text struct{}
|
||||
|
||||
var _ FormatRenderer = (*Text)(nil)
|
||||
|
||||
func (t *Text) Render(w io.Writer, v any) error {
|
||||
var err error
|
||||
switch x := v.(type) {
|
||||
case fmt.Stringer:
|
||||
_, err = w.Write([]byte(x.String()))
|
||||
case io.WriterTo:
|
||||
_, err = x.WriteTo(w)
|
||||
default:
|
||||
return ErrCannotRender
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %w", ErrFailed, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user