Documentation
¶
Index ¶
- Variables
- func CheckIfOutputExists(filename string) error
- func FindStructInDirectory(directory, structName string) (*ast.StructType, *token.FileSet, string, error)
- func FindStructInFile(file, structName string) (structDef *ast.StructType, fset *token.FileSet, pkg string, err error)
- func WriteTemplate(w io.Writer, tplInput *TemplateInput) error
- type TemplateInput
- type TemplateOption
Constants ¶
This section is empty.
Variables ¶
var ErrStructNotFoundInFile = fmt.Errorf("struct not found in file")
var TemplateFile string
Functions ¶
func CheckIfOutputExists ¶
CheckIfOutputExists will prompt to overwrite a file if it already exists. If not confirmed, it will error.
func FindStructInDirectory ¶
func FindStructInDirectory(directory, structName string) (*ast.StructType, *token.FileSet, string, error)
FindStructInDirectory reads a directory, without recursing to subdirectories. It searches all Go files within the directory for a struct named 'structName'. It will return that struct's definition, the token file set used to parse that file, and the name of the package that struct was found in, or an error.
func FindStructInFile ¶
func FindStructInFile(file, structName string) (structDef *ast.StructType, fset *token.FileSet, pkg string, err error)
FindStructInFile searches a fully qualified file path for a struct named 'structName'. If found, it will return that struct definition, the token file set used to parse the file, and the package name of the file. Otherwise, if not found, it will return ErrStructNotFoundInFile.
func WriteTemplate ¶
func WriteTemplate(w io.Writer, tplInput *TemplateInput) error
Types ¶
type TemplateInput ¶
type TemplateInput struct { PackageName string Options []TemplateOption StructName string OptionTypeName string }
func NewTemplateInput ¶
func NewTemplateInput(structDef *ast.StructType, fset *token.FileSet, structName, pkg, optionTypeName string) *TemplateInput