mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-08 04:20:59 -05:00
89a7d171ee
Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.2.6 to 2.2.7. - [Release notes](https://github.com/gookit/config/releases) - [Commits](https://github.com/gookit/config/compare/v2.2.6...v2.2.7) --- updated-dependencies: - dependency-name: github.com/gookit/config/v2 dependency-version: 2.2.7 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
package comdef
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
|
|
"github.com/gookit/goutil/x/stdio"
|
|
)
|
|
|
|
// DataFormatter interface
|
|
type DataFormatter interface {
|
|
Format() string
|
|
FormatTo(w io.Writer)
|
|
}
|
|
|
|
// BaseFormatter struct
|
|
//
|
|
// Usage:
|
|
//
|
|
// type YourFormatter struct {
|
|
// comdef.BaseFormatter
|
|
// }
|
|
// // implement the DataFormatter interface...
|
|
type BaseFormatter struct {
|
|
ow ByteStringWriter
|
|
// Out formatted to the writer
|
|
Out io.Writer
|
|
// Src data(array, map, struct) for format
|
|
Src any
|
|
// MaxDepth limit depth for array, map data TODO
|
|
MaxDepth int
|
|
// Prefix string for each element
|
|
Prefix string
|
|
// Indent string for format each element
|
|
Indent string
|
|
// ClosePrefix string for last "]", "}"
|
|
ClosePrefix string
|
|
}
|
|
|
|
// Reset after format
|
|
func (f *BaseFormatter) Reset() {
|
|
f.Out = nil
|
|
f.Src = nil
|
|
}
|
|
|
|
// SetOutput writer
|
|
func (f *BaseFormatter) SetOutput(out io.Writer) {
|
|
f.Out = out
|
|
}
|
|
|
|
// BsWriter warp the Out, build a ByteStringWriter
|
|
func (f *BaseFormatter) BsWriter() ByteStringWriter {
|
|
if f.ow == nil {
|
|
if f.Out == nil {
|
|
f.ow = new(bytes.Buffer)
|
|
} else if ow, ok := f.Out.(ByteStringWriter); ok {
|
|
f.ow = ow
|
|
} else {
|
|
f.ow = stdio.NewWriteWrapper(f.Out)
|
|
}
|
|
}
|
|
return f.ow
|
|
}
|