csgen

package module
v0.0.0-...-edbd7db Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MIT Imports: 14 Imported by: 1

README

       
     

CSGen

CSGen is a Golang utility package for simplifying development of code generation tools. It contains abstractions around the standard library AST packages to make using them more intuitive for developers.

Get the Package

go get github.com/cscoding21/csgen

Core Uses

The primary use-case for the library is to get a list of all the structs in a file including details about each field.

//---get all of the structs within a file.  The file argument
structs, err := csgen.GetStructs("test_struct.go")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteTemplate

func ExecuteTemplate[T any](name string, fileTemplate string, om T) string

ExecuteTemplate executes a template against a given object and return the output as a string

func GetFile

func GetFile(file ...string) string

GetFile returns the current file based on the generators env or passed in value

func GetImports

func GetImports(filePath string) ([]string, error)

GetImports returns all of the imports in a given file

func NewCSGenBuilderForFile

func NewCSGenBuilderForFile(name string, pkg string) *strings.Builder

NewCSGenBuilderForFile returns a string buider with a common header for generated files

func WriteGeneratedGoFile

func WriteGeneratedGoFile(name string, contents string) error

WriteGeneratedGoFile create a text file with the passed in name and contents

Types

type Function

type Function struct {
	Name      string
	Receiver  *string
	Arguments []StructField
	Returns   []StructField
	IsPublic  bool
}

func GetFunctions

func GetFunctions(filePath string) ([]Function, error)

GetFunctions returns all of the functions in a given file

type Interface

type Interface struct {
	Name     string
	Methods  []Function
	IsPublic bool
}

func GetInterfaces

func GetInterfaces(filePath string) ([]Interface, error)

GetInterfaces get a list of all declared interfaces in a given file

type Struct

type Struct struct {
	Name     string
	FilePath string
	Package  string
	Type     string
	Fields   []StructField
}

Struct a struct that abstracts a golang struct

func GetStructs

func GetStructs(filePath string) ([]Struct, error)

GetStructs return a list of all structs in a given file

func (*Struct) GetField

func (s *Struct) GetField(name string) *StructField

GetField return a field object of a struct by its name

type StructField

type StructField struct {
	Name        string
	Type        string
	TagString   string
	IsPrimitive bool
	IsPointer   bool
	IsSlice     bool
	IsPublic    bool
}

StructField a struct that represents a single field within a struct abstraction

func GetVariables

func GetVariables(filePath string) ([]StructField, error)

GetVariables returns a list of all variable definitions in a given file

func (*StructField) GetTag

func (s *StructField) GetTag(name string) string

GetTag returns a single tag value by name based on the standard format rules

Jump to

Keyboard shortcuts

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