module

package
v0.0.0-...-801b3fc Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNoTemplate     = errors.New("no template")
	ErrorNoTemplateFile = errors.New("no template file")
	ErrorNoStructName   = errors.New("no struct name")
)

Functions

func FindPackagesForType

func FindPackagesForType(any interface{}) string

Types

type Config

type Config struct {
	Version     string   // This is the version we want to use for the generator, this will version the API
	Structs     []string // This is the structs we want to process
	OutputDir   string   // This is the output directory
	Directories DirectoryConfig
	//FileNameConfig               FileNameConfig
	OutputDirPermissions         os.FileMode       // This is the permissions we will use for the files we generate
	APIPath                      string            // This is the API Path. The prefix
	Separator                    rune              // This is the file separator
	Auth                         bool              // Are we going to do auth
	FileName                     string            // This is the filename we want to process
	DiscoverFunction             DiscoveryFunction // This is the function which will be called to get the information from the structs
	TemplateFolder               string            // If this is set, we will create
	TemplateSingleton            string            //
	TemplateExtension            string            //
	CreateFromTemplate           bool
	Template                     []Template // These are any custom templates
	CreateRouter                 bool       // Do we want to create the router. This should only be set to false in specific cases
	CreateHandler                bool       // Do we want to create the handler. This should only be set to false in specific cases
	CreateMiddleware             bool       // Do we want to create the middleware ( struct validation and auth ). This should only be set to false in specific cases
	RouterTemplate               string
	HandlerTemplate              string
	ValidationMiddlewareTemplate string
	AuthMiddlewareTemplate       string
	PresenterTemplate            string

	OverrideFiles bool // If we write the files to disk, and a file already exists, do we want to override the current files contents
	WriteToDisk   bool // Will we write the files to disk

}

func (*Config) CreateAll

func (c *Config) CreateAll(defs []TypeSpec) error

CreateAll will create everything needed for the templates and generate the templates

func (*Config) CreateFileFromTemplate

func (c *Config) CreateFileFromTemplate(template Template) error

func (*Config) FilepathSeparator

func (c *Config) FilepathSeparator() string

FilepathSeparator will return the file path separator, it will generally return the filepath.Separator

func (*Config) GetAPIPath

func (c *Config) GetAPIPath(base string) string

func (*Config) GetAllTemplates

func (c *Config) GetAllTemplates() error

GetAllTemplates This will recursively read all files and folders in `Config.TemplateFolder` adding all the files to `Config.Template` The file content will be the `Template.Content` file name will be `Template.NameFormat` with `%s.` as a prefix the file path will be the OutPath with `Config.TemplateFolder` being stripped from the path and replaced with `.`

func (*Config) GetDefaultTypeSpec

func (c *Config) GetDefaultTypeSpec() TypeSpec

func (*Config) Process

func (c *Config) Process() error

Process will process the request

func (*Config) SetDefaults

func (c *Config) SetDefaults()

SetDefaults sets the config values

func (*Config) SetModule

func (c *Config) SetModule()

func (*Config) SetupFolders

func (c *Config) SetupFolders() error

SetupFolders will create all the folders required for the packages

type DirectoryConfig

type DirectoryConfig struct {
	DirectoryHasVersion bool

	RouterDirectory     string
	HandlerDirectory    string
	MiddlewareDirectory string
	PresenterDirectory  string

	Module           string
	IntermediaryPath string
}

type DirectoryName

type DirectoryName int

type DiscoveryFunction

type DiscoveryFunction func(conf *Config, spec []TypeSpec) (error, []File)

type Field

type Field struct {
	Field      *ast.Field
	Rules      []Rule
	Name       string // PascalCase
	APIName    string // snake_case
	VarName    string // camelCase
	Type       string // We may want to change this to a token.Token
	PrimaryKey bool
	Ignore     bool              // Do we ignore this field
	Tag        reflect.StructTag // We want to work with the tags
}

type File

type File struct {
	Path    string
	Content string
	Name    string
}

func (*File) Save

func (file *File) Save(separator string, saveToDisk bool, filePerms os.FileMode) error

type Rule

type Rule struct {
}

Rule I am not sure how to structure this yet The idea is to hold any rules

type StructSpec

type StructSpec struct {
	APIName string // snake_case
	Name    string // PascalCase
	VarName string // camelCase
	Package string // This is the Structs package

	PackageImportPath    string
	MiddlewareImportPath string
	PresenterImportPath  string
	HandlerImportPath    string
}

type Template

type Template struct {
	Name    string // This is the name of the file
	OutPath string // This is the output path, relative to where we are working from
	Content string // This is the template
	Package string
}

type TypeSpec

type TypeSpec struct {
	Backtick string

	TypeSpec *ast.StructType // internal TypeSpec
	Fields   []Field         // These are all the fields
	Ignored  bool
	Version  string
	APIPath  string

	PrimaryKeys     []Field // These are all the Primary Keys
	PrimaryKeyCount int

	Struct StructSpec

	Module           string // This is the application module.
	Package          string // This is the package
	IntermediaryPath string // This is the path between the Module and the Package Path

	Auth bool
}

func AstReader

func AstReader(conf *Config) (error, []TypeSpec)

func GoDocReader

func GoDocReader(config *Config) (error, []TypeSpec)

func (*TypeSpec) Generate

func (ts *TypeSpec) Generate(templateText, path, name string) (*File, error)

Generate will generate the File for the TypeSpec using the template passed. This will generate both the handler and the router It may also generate specific middleware, auth, validation

func (*TypeSpec) GenerateUsingFile

func (ts *TypeSpec) GenerateUsingFile(file, path, name string) (*File, error)

GenerateUsingFile will generate the File for the TypeSpec using the template passed. This will generate both the handler and the router It may also generate specific middleware, auth, validation

func (*TypeSpec) GetAllFiles

func (ts *TypeSpec) GetAllFiles(config *Config) ([]*File, error)

GetAllFiles will generate and return all the required `File` for the TypeSpec This will generate the handler and the router, it may also generate specific middleware, auth, validation. This will not write the files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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