text

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTextFormat = huma.Format{
	Marshal: func(w io.Writer, v any) error {
		if m, ok := v.(encoding.TextMarshaler); ok {
			b, err := m.MarshalText()
			if err != nil {
				return err
			}
			_, err = w.Write(b)

			return err
		}
		_, err := w.Write([]byte(fmt.Sprint(v)))

		return err
	},
	Unmarshal: func(data []byte, v any) error {
		if m, ok := v.(encoding.TextUnmarshaler); ok {
			return m.UnmarshalText(data)
		}
		return huma.Error501NotImplemented("text format not supported")
	},
}

DefaultTextFormat is the default text formatter that can be set in the API's `Config.Formats` map. This is usually not needed as importing this package automatically adds the text format to the default formats.

config := huma.Config{}
config.Formats = map[string]huma.Format{
	"plain/text": huma.DefaultTextFormat,
	"text":       huma.DefaultTextFormat,
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL