structure

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	// Name of the field. This can be empty if using composition.
	Name string
	// Key name of the field, if it's a map.
	Key string
	// Value name of the field is the only required string.
	Value string
	// Tags are stored for potential manipulation later
	Tags Tags
	// IsArray is mutually exclusive with Key having contents and IsMap being true.
	IsArray bool
	// IsMap means Key is set.
	IsMap bool
	// IsPointer refers to the whole field being a pointer.
	IsPointer bool
	// IsPointerValue will be true if a map or array contains pointers.
	IsPointerValue bool
	// IsComment is a comment for the next field.
	IsComment bool
}

Field holds a structure's field,

func (*Field) MakeTags

func (f *Field) MakeTags(json, omitempty bool)

MakeTags for specified output formats. Currently only JSON is supported.

func (*Field) ProtoString

func (f *Field) ProtoString(count int) string

ProtoString is a protocol buffers representation of the field. The input is the order it has in the structure.

func (*Field) String

func (f *Field) String() string

String representation of the field (compact; one tab as separator).

type Func added in v0.15.0

type Func struct {
	// Name of the func for lookup.
	Name string
	// Code is the entire function.
	Code string
}

Funcs holds the code for a function.

type Package

type Package struct {
	scanner.Scanner

	Name string

	InternalImports []string
	ExternalImports []string

	Structs []*Structure
	Funcs   []Func
	// contains filtered or unexported fields
}

* Package holds the package scanner and other internal data, * plus the exported structures for structs and imports.

func NewPackage

func NewPackage(filenames ...string) (*Package, error)

func (*Package) MakeTags

func (pkg *Package) MakeTags(json, omitempty bool)

MakeTags for all structures. Unexported fields will be skipped.

func (*Package) MergeExternalImports added in v0.2.1

func (pkg *Package) MergeExternalImports() []string

func (*Package) Parse added in v0.13.0

func (pkg *Package) Parse()

parse scans the file for structures

func (*Package) ProtoString

func (pkg *Package) ProtoString() string

ProtoString generates protocol buffer output.

func (*Package) String

func (pkg *Package) String() string

type Structure

type Structure struct {
	Name    string
	Comment string
	Fields  []*Field
}

Structure holds a struct and its preceding comment.

func NewStructure

func NewStructure(name, comment string) *Structure

NewStructure simply returns a Structure struct with the specified name.

func (*Structure) MakeTags

func (st *Structure) MakeTags(json, omitempty bool)

MakeTags for this structure. Unexported fields will be skipped.

func (*Structure) ProtoString

func (st *Structure) ProtoString() string

ProtoString is a protobuf representation of the structure.

func (*Structure) String

func (st *Structure) String() string

String representation of the struct and contents (somewhat pretty-printed).

type Tags

type Tags struct {
	// JSON tags will be output from this.
	JSON struct {
		// Name will be the field name in lowercase if unspecified.
		Name string
		// Omitempty keyword will be output if this is true.
		Omitempty bool
	}
}

Tags for different input/output formats.

Jump to

Keyboard shortcuts

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