mirror of
https://github.com/jimeh/go-render.git
synced 2026-02-19 03:16:39 +00:00
chore: correct typos and align struct field tags (#12)
Fixes typos in package documentation and variable names. Aligns struct field tags in examples and tests for better readability.
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Binary can render values which implment the encoding.BinaryMarshaler
|
// Binary can render values which implement the encoding.BinaryMarshaler
|
||||||
// interface.
|
// interface.
|
||||||
type Binary struct{}
|
type Binary struct{}
|
||||||
|
|
||||||
@@ -15,8 +15,8 @@ var (
|
|||||||
_ FormatsHandler = (*Binary)(nil)
|
_ FormatsHandler = (*Binary)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Render writes result of calling MarshalBinary() on v. If v does not implment
|
// Render writes result of calling MarshalBinary() on v. If v does not implement
|
||||||
// encoding.BinaryMarshaler the ErrCannotRander error will be returned.
|
// encoding.BinaryMarshaler the ErrCannotRender error will be returned.
|
||||||
func (br *Binary) Render(w io.Writer, v any) error {
|
func (br *Binary) Render(w io.Writer, v any) error {
|
||||||
x, ok := v.(encoding.BinaryMarshaler)
|
x, ok := v.(encoding.BinaryMarshaler)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package render
|
|||||||
import "io"
|
import "io"
|
||||||
|
|
||||||
// Handler interface is for single format renderers, which can only render a
|
// Handler interface is for single format renderers, which can only render a
|
||||||
// single format. It is the basis of the multi-format support offerred by the
|
// single format. It is the basis of the multi-format support offered by the
|
||||||
// render package.
|
// render package.
|
||||||
type Handler interface {
|
type Handler interface {
|
||||||
// Render writes v into w in the format that the Handler supports.
|
// Render writes v into w in the format that the Handler supports.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Package render provides a simple and flexible solutio to render a value to a
|
// Package render provides a simple and flexible solution to render a value to a
|
||||||
// io.Writer using different formats based on a format string argument.
|
// io.Writer using different formats based on a format string argument.
|
||||||
//
|
//
|
||||||
// It is designed around using a custom type/struct to render your output.
|
// It is designed around using a custom type/struct to render your output.
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ type renderFormatTestCase struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// "binary" format.
|
// "binary" format.
|
||||||
var binaryFormattestCases = []renderFormatTestCase{
|
var binaryFormatTestCases = []renderFormatTestCase{
|
||||||
{
|
{
|
||||||
name: "with binary marshaler",
|
name: "with binary marshaler",
|
||||||
formats: []string{"binary", "bin"},
|
formats: []string{"binary", "bin"},
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ func (r *Renderer) Pretty(w io.Writer, format string, v any) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewWith creates a new Renderer with the formats given, if they have handlers
|
// NewWith creates a new Renderer with the formats given, if they have handlers
|
||||||
// in the currener Renderer. It essentially allows to restrict a Renderer to a
|
// in the current Renderer. It essentially allows to restrict a Renderer to a
|
||||||
// only a sub-set of supported formats.
|
// only a sub-set of supported formats.
|
||||||
func (r *Renderer) NewWith(formats ...string) *Renderer {
|
func (r *Renderer) NewWith(formats ...string) *Renderer {
|
||||||
handlers := make(map[string]Handler, len(formats))
|
handlers := make(map[string]Handler, len(formats))
|
||||||
|
|||||||
@@ -112,13 +112,13 @@ func TestRenderer_Add(t *testing.T) {
|
|||||||
want: []string{"tackle"},
|
want: []string{"tackle"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "hander with Formats",
|
name: "handler with Formats",
|
||||||
format: "hackle",
|
format: "hackle",
|
||||||
handler: &mockFormatsHandler{formats: []string{"hackle"}},
|
handler: &mockFormatsHandler{formats: []string{"hackle"}},
|
||||||
want: []string{"hackle"},
|
want: []string{"hackle"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "hander with alias formats",
|
name: "handler with alias formats",
|
||||||
format: "hackle",
|
format: "hackle",
|
||||||
handler: &mockFormatsHandler{formats: []string{"hackle", "hack"}},
|
handler: &mockFormatsHandler{formats: []string{"hackle", "hack"}},
|
||||||
want: []string{"hackle", "hack"},
|
want: []string{"hackle", "hack"},
|
||||||
@@ -471,7 +471,7 @@ func TestRenderer_Pretty(t *testing.T) {
|
|||||||
|
|
||||||
func TestRenderer_RenderAllFormats(t *testing.T) {
|
func TestRenderer_RenderAllFormats(t *testing.T) {
|
||||||
tests := []renderFormatTestCase{}
|
tests := []renderFormatTestCase{}
|
||||||
tests = append(tests, binaryFormattestCases...)
|
tests = append(tests, binaryFormatTestCases...)
|
||||||
tests = append(tests, jsonFormatTestCases...)
|
tests = append(tests, jsonFormatTestCases...)
|
||||||
tests = append(tests, textFormatTestCases...)
|
tests = append(tests, textFormatTestCases...)
|
||||||
tests = append(tests, xmlFormatTestCases...)
|
tests = append(tests, xmlFormatTestCases...)
|
||||||
@@ -540,7 +540,7 @@ func TestRenderer_RenderAllFormats(t *testing.T) {
|
|||||||
|
|
||||||
func TestRenderer_CompactAllFormats(t *testing.T) {
|
func TestRenderer_CompactAllFormats(t *testing.T) {
|
||||||
tests := []renderFormatTestCase{}
|
tests := []renderFormatTestCase{}
|
||||||
tests = append(tests, binaryFormattestCases...)
|
tests = append(tests, binaryFormatTestCases...)
|
||||||
tests = append(tests, jsonFormatTestCases...)
|
tests = append(tests, jsonFormatTestCases...)
|
||||||
tests = append(tests, textFormatTestCases...)
|
tests = append(tests, textFormatTestCases...)
|
||||||
tests = append(tests, xmlFormatTestCases...)
|
tests = append(tests, xmlFormatTestCases...)
|
||||||
@@ -602,7 +602,7 @@ func TestRenderer_CompactAllFormats(t *testing.T) {
|
|||||||
|
|
||||||
func TestRenderer_PrettyAllFormats(t *testing.T) {
|
func TestRenderer_PrettyAllFormats(t *testing.T) {
|
||||||
tests := []renderFormatTestCase{}
|
tests := []renderFormatTestCase{}
|
||||||
tests = append(tests, binaryFormattestCases...)
|
tests = append(tests, binaryFormatTestCases...)
|
||||||
tests = append(tests, jsonFormatTestCases...)
|
tests = append(tests, jsonFormatTestCases...)
|
||||||
tests = append(tests, textFormatTestCases...)
|
tests = append(tests, textFormatTestCases...)
|
||||||
tests = append(tests, xmlFormatTestCases...)
|
tests = append(tests, xmlFormatTestCases...)
|
||||||
|
|||||||
Reference in New Issue
Block a user