Documentation ¶
Overview ¶
Package luceio profides helpers that extend io in particular, helping build instances of Writer and WriterTo.
Index ¶
- Variables
- type DefaulLineWrapperContext
- type LineWrapperContext
- type LineWrapperContextWriter
- type LineWrappingWriter
- type Replacer
- type ReplacerWriter
- type StringWriter
- type StringWriterTo
- type StringsWriter
- type SumWriter
- func (s *SumWriter) AppendCache(b []byte)
- func (s *SumWriter) AppendCacheString(str string)
- func (s *SumWriter) Diff(d int64) (int, error)
- func (s *SumWriter) Fprint(format string, args ...interface{}) (int, error)
- func (s *SumWriter) Join(elems []string, sep string) (int, error)
- func (s *SumWriter) Rets() (int64, error)
- func (s *SumWriter) Wrapped() any
- func (s *SumWriter) Write(b []byte) (int, error)
- func (s *SumWriter) WriteInt(i int) (int, error)
- func (s *SumWriter) WriteRune(r rune)
- func (s *SumWriter) WriteString(str string) (int, error)
- func (s *SumWriter) WriteStrings(strs ...string) (int, error)
- func (s *SumWriter) WriterTo(w io.WriterTo) (int64, error)
- type TemplateExecutor
- type TemplateTo
- type TemplateWrapper
- type WriterToSeperator
- type WriterTos
Constants ¶
This section is empty.
Variables ¶
var WrapWidth = 80
WrapWidth allows setting a default width to be used by new instances of LineWrapperContext
Functions ¶
This section is empty.
Types ¶
type DefaulLineWrapperContext ¶
type DefaulLineWrapperContext struct{}
DefaulLineWrapperContext will return the package level WrapWidth and an empty string for the padding
func (DefaulLineWrapperContext) Padding ¶
func (DefaulLineWrapperContext) Padding() string
Padding returns an empty string
func (DefaulLineWrapperContext) WrapWidth ¶
func (DefaulLineWrapperContext) WrapWidth() int
WrapWidth returns package level WrapWidth
type LineWrapperContext ¶
LineWrapperContext returns contextual information to guide the writing operation. It is assumed that these values will not change with respect to an instance.
LineWrapperContext only handle Unix style line endings.
type LineWrapperContextWriter ¶
LineWrapperContextWriter provides a method to add Width and Padding Context to a Writer.
func (LineWrapperContextWriter) Padding ¶
func (lwcw LineWrapperContextWriter) Padding() string
Padding fulfills LineWrapperContext providing the Padding
func (LineWrapperContextWriter) WrapWidth ¶
func (lwcw LineWrapperContextWriter) WrapWidth() int
WrapWidth fulfills LineWrapperContext providing the Width
type LineWrappingWriter ¶
type LineWrappingWriter struct { LineWrapperContext *SumWriter // contains filtered or unexported fields }
LineWrappingWriter fulfills io.Writer.
func NewLineWrappingWriter ¶
func NewLineWrappingWriter(w io.Writer) *LineWrappingWriter
NewLineWrappingWriter returns a LineWrappingWriter that will write to the underlying writer. It will try to upgrade the writer to LineWrapperContext but if that fails, it will use the DefaulLineWrapperContext. The LineWrapperContextWriter can be used to wrap the Writer and set Width and Padding.
func (*LineWrappingWriter) WriteNewline ¶
func (w *LineWrappingWriter) WriteNewline() (int, error)
WriteNewline writes a new line followed by the necessary padding
func (*LineWrappingWriter) WritePadding ¶
func (w *LineWrappingWriter) WritePadding() (int, error)
WritePadding writes the padding set by the context.
type ReplacerWriter ¶
ReplacerWriter invokes a Replacer on any data before sending it to the underlying Writer.
func NewReplacer ¶
func NewReplacer(w io.Writer, oldnew ...string) ReplacerWriter
func (ReplacerWriter) Write ¶
func (rw ReplacerWriter) Write(b []byte) (int, error)
Write casts the []byte to string, calls Replacer and writes to the underlying writer.
func (ReplacerWriter) WriteString ¶
func (rw ReplacerWriter) WriteString(str string) (int, error)
type StringWriter ¶
StringWriter is the interface that wraps the WriteString method
type StringWriterTo ¶
type StringWriterTo string
StringWriterTo fulfils the WriterTo interface and writes the string to the writer
type StringsWriter ¶
StringWriter is the interface that wraps the WriteString method
type SumWriter ¶
type SumWriter struct { io.Writer // Cache holds bytes that will be written before the next write operation. // If no write operation is executed, they will never be written. Cache []byte Sum int64 Err error }
SumWriter is helper that wraps a Writer and sums the bytes written. If it encounters an error, it will stop writing.
func BufferSumWriter ¶
BufferSumWriter creates a new buffer passing it into the SumWriter and returns both.
func NewSumWriter ¶
NewSumWriter takes a Writer and returns a SumWriter
func (*SumWriter) AppendCache ¶
AppendCache will append a byte slice to the current Cache value.
func (*SumWriter) AppendCacheString ¶
AppendCacheString will append a string to the current Cache value.
func (*SumWriter) Diff ¶
Diff is a shorthand way to handle returns by marking the difference in the Sum.
func (*SumWriter) WriteString ¶
WriteString writes a string to underlying Writer
func (*SumWriter) WriteStrings ¶
WriteStrings writes strings to underlying Writer
type TemplateExecutor ¶
type TemplateExecutor interface { ExecuteTemplate(io.Writer, string, interface{}) error Execute(io.Writer, interface{}) error }
TemplateExecutor is an interface representing the ExecuteTemplate method on a template.
type TemplateTo ¶
type TemplateTo struct { TemplateExecutor Name string Data interface{} }
TemplateTo writes a template and fulfils WriterTo. If Name is blank, the base template is used, otherwise the named template is used.
func NewTemplateTo ¶
func NewTemplateTo(template TemplateExecutor, name string, data interface{}) *TemplateTo
NewTemplateTo returns a TemplateTo which fulfils WriterTo
type TemplateWrapper ¶
type TemplateWrapper struct {
TemplateExecutor
}
TemplateWrapper allows a template to generate insances of TemplateTo
func (TemplateWrapper) TemplateTo ¶
func (t TemplateWrapper) TemplateTo(name string, data interface{}) *TemplateTo
TemplateTo combines the template, name and data and fulfills io.WriterTo