Documentation ¶
Overview ¶
Package gen provides some utility functions for generating go code using io.Writer or fmt.Fprint things.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Imports ¶
type Imports struct { BasePath string // contains filtered or unexported fields }
Imports represents a list of imports.
Example ¶
package main import ( "fmt" gen "github.com/nasa9084/go-genutils" ) func main() { pkgs := []string{ "fmt", "net/http", } imports := gen.NewImports(pkgs) fmt.Print(imports.String()) }
Output: import ( "fmt" "net/http" )
Example (SingleImport) ¶
package main import ( "fmt" gen "github.com/nasa9084/go-genutils" ) func main() { pkgs := []string{"fmt"} imports := gen.NewImports(pkgs) fmt.Print(imports.String()) }
Output: import "fmt"
func NewImports ¶
NewImports returns a new import list from import path string slice.
type Interface ¶
func LoadInterfacesFromFile ¶
func NewInterface ¶
func NewInterface(comment, name string, iface *ast.InterfaceType) Interface
type Package ¶
func LoadPackagesFromPath ¶
type Struct ¶
Struct represents a struct type.
func LoadStructs ¶
LoadStructs load struct types from *ast.File.
Example ¶
package main import ( "fmt" gen "github.com/nasa9084/go-genutils" ) func main() { structs, _ := gen.LoadStructsFromFile("./internal/tests/test_structs.go") for _, s := range structs { fmt.Println(s.Name) } }
Output: Something Nested Parent Child
func LoadStructsFromFile ¶
LoadStructsFromFile load struct types from file.
Click to show internal directories.
Click to hide internal directories.