Documentation ¶
Overview ¶
Package xmlstruct generates Go structs from multiple XML documents.
Index ¶
- Constants
- Variables
- type ExportNameFunc
- type Generator
- type GeneratorOption
- func WithCharDataFieldName(charDataFieldName string) GeneratorOption
- func WithExportNameFunc(exportNameFunc ExportNameFunc) GeneratorOption
- func WithExportRenames(exportRenames map[string]string) GeneratorOption
- func WithFormatSource(formatSource bool) GeneratorOption
- func WithHeader(header string) GeneratorOption
- func WithIntType(intType string) GeneratorOption
- func WithNameFunc(nameFunc NameFunc) GeneratorOption
- func WithNamedTypes(namedTypes bool) GeneratorOption
- func WithPackageName(packageName string) GeneratorOption
- func WithPreserveOrder(preserveOrder bool) GeneratorOption
- func WithTimeLayout(timeLayout string) GeneratorOption
- func WithTopLevelAttributes(topLevelAttributes bool) GeneratorOption
- func WithUsePointersForOptionalFields(usePointersForOptionalFields bool) GeneratorOption
- func WithUseRawToken(useRawToken bool) GeneratorOption
- type NameFunc
Constants ¶
const ( DefaultCharDataFieldName = "CharData" DefaultFormatSource = true DefaultHeader = "// This file is automatically generated. DO NOT EDIT." DefaultTopLevelAttributes = false DefaultIntType = "int" DefaultNamedTypes = false DefaultPackageName = "main" DefaultPreserveOrder = false DefaultTimeLayout = "2006-01-02T15:04:05Z" DefaultUsePointersForOptionalFields = true DefaultUseRawToken = false )
Variables ¶
var ( SkipDir = fs.SkipDir //lint:ignore ST1012 SkipFile is not an error SkipFile = errors.New("skip file") //nolint:errname )
var ( // TitleFirstRuneExportNameFunc returns name.Local with the initial rune // capitalized. TitleFirstRuneExportNameFunc = func(name xml.Name) string { runes := []rune(name.Local) runes[0] = unicode.ToUpper(runes[0]) return string(runes) } // DefaultExportNameFunc returns name.Local with kebab- and snakecase words // converted to camelcase and any Id suffix converted to ID. DefaultExportNameFunc = func(name xml.Name) string { localName := kebabOrSnakeCaseWordBoundaryRx.ReplaceAllStringFunc(name.Local, func(s string) string { return strings.ToUpper(s[len(s)-1:]) }) localName = nonIdentifierRuneRx.ReplaceAllLiteralString(localName, "") runes := []rune(localName) runes[0] = unicode.ToUpper(runes[0]) if len(runes) > 1 && runes[len(runes)-2] == 'I' && runes[len(runes)-1] == 'd' { runes[len(runes)-1] = 'D' } return string(runes) } )
var ( // IgnoreNamespaceNameFunc returns name with name.Space cleared. The same // local name in different namespaces will be treated as identical names. IgnoreNamespaceNameFunc = func(name xml.Name) xml.Name { return xml.Name{ Local: name.Local, } } // The IdentityNameFunc returns name unchanged. The same local name in // different namespaces will be treated as distinct names. IdentityNameFunc = func(name xml.Name) xml.Name { return name } DefaultNameFunc = IgnoreNamespaceNameFunc )
Functions ¶
This section is empty.
Types ¶
type ExportNameFunc ¶
An ExportNameFunc returns the exported Go identifier for the given xml.Name.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
A Generator observes XML documents and generates Go structs into which the XML documents can be unmarshalled.
func NewGenerator ¶
func NewGenerator(options ...GeneratorOption) *Generator
NewGenerator returns a new Generator with the given options.
func (*Generator) Generate ¶
Generate returns the generated Go source for all the XML documents observed so far.
func (*Generator) ObserveFS ¶
func (g *Generator) ObserveFS(fsys fs.FS, root string, observeFunc func(string, fs.DirEntry, error) error) error
ObserveFS observes all XML documents in fs.
func (*Generator) ObserveFile ¶
ObserveFile observes an XML document in the given file.
type GeneratorOption ¶
type GeneratorOption func(*Generator)
A GeneratorOption sets an option on a Generator.
func WithCharDataFieldName ¶
func WithCharDataFieldName(charDataFieldName string) GeneratorOption
WithCharDataFieldName sets the char data field name.
func WithExportNameFunc ¶
func WithExportNameFunc(exportNameFunc ExportNameFunc) GeneratorOption
WithExportNameFunc sets the export name function for the generated Go source.
func WithExportRenames ¶
func WithExportRenames(exportRenames map[string]string) GeneratorOption
WithExportRenames sets the export renames.
func WithFormatSource ¶
func WithFormatSource(formatSource bool) GeneratorOption
WithFormatSource sets whether to format the generated Go source.
func WithHeader ¶
func WithHeader(header string) GeneratorOption
WithHeader sets the header of the generated Go source.
func WithIntType ¶
func WithIntType(intType string) GeneratorOption
WithIntType sets the int type in the generated Go source.
func WithNameFunc ¶
func WithNameFunc(nameFunc NameFunc) GeneratorOption
WithNameFunc sets the name function.
func WithNamedTypes ¶
func WithNamedTypes(namedTypes bool) GeneratorOption
WithNamedTypes sets whether all to generate named types for all elements.
func WithPackageName ¶
func WithPackageName(packageName string) GeneratorOption
WithPackageName sets the package name of the generated Go source.
func WithPreserveOrder ¶
func WithPreserveOrder(preserveOrder bool) GeneratorOption
WithPreserveOrder sets whether to preserve the order of types and fields.
func WithTimeLayout ¶
func WithTimeLayout(timeLayout string) GeneratorOption
WithTimeLayout sets the time layout used to identify times in the observed XML documents. Use an empty string to disable identifying times.
func WithTopLevelAttributes ¶
func WithTopLevelAttributes(topLevelAttributes bool) GeneratorOption
WithTopLevelAttributes sets whether to include top level attributes.
func WithUsePointersForOptionalFields ¶
func WithUsePointersForOptionalFields(usePointersForOptionalFields bool) GeneratorOption
WithUsePointersForOptionFields sets whether to use pointers for optional fields in the generated Go source.
func WithUseRawToken ¶
func WithUseRawToken(useRawToken bool) GeneratorOption
WithUseRawToken sets whether to use encoding/xml.Decoder.Token or encoding/xml.Decoder.RawToken.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
goxmlstruct
Command xmlstruct generates Go structs from multiple XML documents.
|
Command xmlstruct generates Go structs from multiple XML documents. |
internal
|
|