Documentation
¶
Index ¶
- Constants
- func AddAliasToAllImports(pkg []FileContents) error
- func AddRequiredImports(pkg []FileContents) error
- func CreatePathAndOpen(filepath string) (*os.File, error)
- func Generate(files []FileContents) error
- func GroupModuleImportsLast(modulePath string) func([]FileContents) error
- func GroupStdImportsFirst(pkg []FileContents) error
- func Lint(pkg []FileContents, extraLintRules ...func([]FileContents) error) error
- func LintAndGenerate(files []FileContents, extraLintRules ...func([]FileContents) error) error
- func LintCustom(pkg []FileContents, lintRules ...func([]FileContents) error) error
- func PackageImportPath(path string) (string, error)
- func SortFuncs(f []DeclFunc)
- func WriteDeclFunc(w io.Writer, decl DeclFunc, importAliases map[string]string) error
- func WriteDeclType(w io.Writer, decl DeclType, importAliases map[string]string) error
- func WriteDeclVars(w io.Writer, keyword string, decls []DeclVar, importAliases map[string]string) error
- func WriteFileContents(w io.Writer, c FileContents) error
- func WriteImports(w io.Writer, imports []ImportAndAlias) error
- type DeclFunc
- type DeclType
- type DeclVar
- type FileContents
- type FuncReceiver
- type ImportAndAlias
- type ParseOption
- type Type
- type TypeAny
- type TypeArray
- type TypeBool
- type TypeByte
- type TypeError
- type TypeFloat32
- type TypeFloat64
- type TypeFunc
- type TypeInt
- type TypeInt32
- type TypeInt64
- type TypeInterface
- type TypeMap
- type TypeNamed
- type TypePointer
- type TypeString
- type TypeStruct
- type TypeUnnamedLiteral
Constants ¶
const CURRENT_PKG = "current_pkg_import"
Variables ¶
This section is empty.
Functions ¶
func AddAliasToAllImports ¶
func AddAliasToAllImports(pkg []FileContents) error
func AddRequiredImports ¶
func AddRequiredImports(pkg []FileContents) error
func CreatePathAndOpen ¶
CreatePathAndOpen creats all contains directors in filepath if they do not exist and opens a file for writing at filepath.
If filepath already exists and is a file then the file will be overwritten. If filepath already exists and is a directory then an error will be returned.
func Generate ¶
func Generate(files []FileContents) error
func GroupModuleImportsLast ¶
func GroupModuleImportsLast(modulePath string) func([]FileContents) error
func GroupStdImportsFirst ¶
func GroupStdImportsFirst(pkg []FileContents) error
GroupStdImportsFirst will move all std imports in all files to their own group at the start of the import list.
The ordeing of the std imports within a file will remain unchanged. Any existing grouping on std imports within a file will be removed. The ordering + grouping of all other imports within a file remains unchanged
func Lint ¶
func Lint( pkg []FileContents, extraLintRules ...func([]FileContents) error, ) error
func LintAndGenerate ¶
func LintAndGenerate( files []FileContents, extraLintRules ...func([]FileContents) error, ) error
func LintCustom ¶
func LintCustom( pkg []FileContents, lintRules ...func([]FileContents) error, ) error
func PackageImportPath ¶
PackageImportPath returns the import path of a package given its path in the filesystem
`path` may be either a relative or absoute path to the package directory or a file withing the package directory.
**Note 1:** it assumes that the package is within a go module - if it is not it will return an error.
**Note 2:** there are no checks that the given package does contain `.go` files (i.e. is a go package)
**Note 3:** only tested on Unix... Windows users tread carefully.
Deets: This method traverses up the directory tree from `path`, looking for a `go.mod` file in each directory. Upon finding one, it will return the module path within `go.mod` appended with the relative path of the given `path`.
func WriteDeclFunc ¶
func WriteDeclType ¶
func WriteDeclVars ¶
func WriteFileContents ¶
func WriteFileContents( w io.Writer, c FileContents, ) error
func WriteImports ¶
func WriteImports( w io.Writer, imports []ImportAndAlias, ) error
Types ¶
type DeclFunc ¶
type DeclFunc struct { Name string Import string Receiver FuncReceiver Args []DeclVar VariadicLastArg bool ReturnArgs []DeclVar BodyTmpl string BodyData any DocString string }
func (DeclFunc) RequiredImports ¶
type DeclVar ¶
type DeclVar struct { Type Name string Import string // LiteralValue is the value of the literal assigned to this variable declaration // (if one was assigned - otherwise it will be empty) // // e.g. for `var MyVar int = 123`, LiteralValue will be `123` LiteralValue string // StructTag holds the tags for a struct field if this DeclVar represents a // field within a struct. // If this DeclVar is not within a struct then it is not used. StructTag reflect.StructTag DocString string }
type FileContents ¶
type FileContents struct { Filepath string PackageName string PackageImportPath string Imports []ImportAndAlias Consts []DeclVar Vars []DeclVar Types []DeclType Functions []DeclFunc DocString string }
func Parse ¶
func Parse(inputPath string, opts ...ParseOption) ([]FileContents, error)
Parse parses the file or package at `inputPath` and returns its `FileContents` representation
`inputPath` may either be a single golang source file or a directory of golang source files (i.e. a package)
type FuncReceiver ¶
type ImportAndAlias ¶
type ImportAndAlias struct { Import string Alias string // Group defines the _group_ which this import will sit within: // * Groups are seperated by a single, empty newline in the imports list // * Groups are ordered by the value of this `Group` property // * Group numbers do not need to be monotonically increasing (they are only compared with `<`) // e.g: // “` // import ( // "import1" <----- Group 0 // // "import2" <--\ // "import3" <--| // "import4" <--+-- Group 1 // ) Group int64 }
type ParseOption ¶
type ParseOption func(parseOptions) parseOptions
func ParseDependentTypes ¶
func ParseDependentTypes() ParseOption
func ParseWithPkgImportPath ¶
func ParseWithPkgImportPath(importPath string) ParseOption
type TypeAny ¶
type TypeAny struct { }
func (TypeAny) DefaultInit ¶
func (TypeAny) RequiredImports ¶
type TypeArray ¶
type TypeArray struct {
ValueType Type
}
func (TypeArray) DefaultInit ¶
func (TypeArray) RequiredImports ¶
type TypeBool ¶
type TypeBool struct{}
func (TypeBool) DefaultInit ¶
func (TypeBool) RequiredImports ¶
type TypeByte ¶
type TypeByte struct{}
func (TypeByte) DefaultInit ¶
func (TypeByte) RequiredImports ¶
type TypeError ¶
type TypeError struct{}
func (TypeError) DefaultInit ¶
func (TypeError) RequiredImports ¶
type TypeFloat32 ¶
type TypeFloat32 struct{}
func (TypeFloat32) DefaultInit ¶
func (t TypeFloat32) DefaultInit(importAliases map[string]string) (string, error)
func (TypeFloat32) FullType ¶
func (t TypeFloat32) FullType(importAliases map[string]string) (string, error)
func (TypeFloat32) RequiredImports ¶
func (t TypeFloat32) RequiredImports() map[string]bool
type TypeFloat64 ¶
type TypeFloat64 struct{}
func (TypeFloat64) DefaultInit ¶
func (t TypeFloat64) DefaultInit(importAliases map[string]string) (string, error)
func (TypeFloat64) FullType ¶
func (t TypeFloat64) FullType(importAliases map[string]string) (string, error)
func (TypeFloat64) RequiredImports ¶
func (t TypeFloat64) RequiredImports() map[string]bool
type TypeFunc ¶
func (TypeFunc) DefaultInit ¶
func (TypeFunc) RequiredImports ¶
type TypeInt ¶
type TypeInt struct{}
func (TypeInt) DefaultInit ¶
func (TypeInt) RequiredImports ¶
type TypeInt32 ¶
type TypeInt32 struct{}
func (TypeInt32) DefaultInit ¶
func (TypeInt32) RequiredImports ¶
type TypeInt64 ¶
type TypeInt64 struct{}
func (TypeInt64) DefaultInit ¶
func (TypeInt64) RequiredImports ¶
type TypeInterface ¶
func (TypeInterface) DefaultInit ¶
func (t TypeInterface) DefaultInit(importAliases map[string]string) (string, error)
func (TypeInterface) FullType ¶
func (t TypeInterface) FullType(importAliases map[string]string) (string, error)
func (TypeInterface) RequiredImports ¶
func (t TypeInterface) RequiredImports() map[string]bool
type TypeMap ¶
func (TypeMap) DefaultInit ¶
func (TypeMap) RequiredImports ¶
type TypeNamed ¶
TODO rename to something more approriate - maybe TypeNamed (or TypeAlias)
func (TypeNamed) DefaultInit ¶
func (TypeNamed) RequiredImports ¶
type TypePointer ¶
type TypePointer struct {
ValueType Type
}
func (TypePointer) DefaultInit ¶
func (t TypePointer) DefaultInit(importAliases map[string]string) (string, error)
func (TypePointer) FullType ¶
func (t TypePointer) FullType(importAliases map[string]string) (string, error)
func (TypePointer) RequiredImports ¶
func (t TypePointer) RequiredImports() map[string]bool
type TypeString ¶
type TypeString struct{}
func (TypeString) DefaultInit ¶
func (t TypeString) DefaultInit(importAliases map[string]string) (string, error)
func (TypeString) FullType ¶
func (t TypeString) FullType(importAliases map[string]string) (string, error)
func (TypeString) RequiredImports ¶
func (t TypeString) RequiredImports() map[string]bool
type TypeStruct ¶
func (TypeStruct) DefaultInit ¶
func (t TypeStruct) DefaultInit(importAliases map[string]string) (string, error)
func (TypeStruct) FullType ¶
func (t TypeStruct) FullType(importAliases map[string]string) (string, error)
func (TypeStruct) RequiredImports ¶
func (t TypeStruct) RequiredImports() map[string]bool
type TypeUnnamedLiteral ¶
type TypeUnnamedLiteral struct{}
func (TypeUnnamedLiteral) DefaultInit ¶
func (t TypeUnnamedLiteral) DefaultInit(importAliases map[string]string) (string, error)
func (TypeUnnamedLiteral) FullType ¶
func (t TypeUnnamedLiteral) FullType(importAliases map[string]string) (string, error)
func (TypeUnnamedLiteral) RequiredImports ¶
func (t TypeUnnamedLiteral) RequiredImports() map[string]bool
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
example_generators
|
|
test_packages
|
|
non_declaritive_elements
A package level doc string with
|
A package level doc string with |