generator

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package generator provides programmatic scaffolding for Go REST APIs with a layered architecture (controllers, services, repositories). It can be used as a library (e.g. generator.Init, generator.GenerateModule) or via the go-gen-r CLI.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	WORKDIR = "internal/"
)

Functions

func CreateAppErrs

func CreateAppErrs()

func CreateConfigEnv

func CreateConfigEnv(projectName string)

func CreateConfigTimezonse

func CreateConfigTimezonse(projectName string)

func CreateControllers

func CreateControllers(filename string, projectName string)

func CreateDatabaseConnection

func CreateDatabaseConnection(projectName string)

func CreateExampleConfig

func CreateExampleConfig(projectName string)

func CreateFiberRoutes

func CreateFiberRoutes(projectName string)

func CreateHandleResponse

func CreateHandleResponse(projectName string)

func CreateLoggers

func CreateLoggers(projectName string)

func CreateMainGo

func CreateMainGo(projectName string)

func CreateMiddleware

func CreateMiddleware(projectName string)

func CreateMigrations

func CreateMigrations(filename string, projectName string)

func CreateModels

func CreateModels(filename string)

func CreatePagination

func CreatePagination(projectName string)

func CreateRepositories

func CreateRepositories(filename string, projectName string)

func CreateRequests

func CreateRequests(filename string)

func CreateResponses

func CreateResponses(filename string)

func CreateRoutes

func CreateRoutes()

func CreateServices

func CreateServices(filename string, projectName string)

func CreateSrcDir

func CreateSrcDir()

func CreateTestsStructure

func CreateTestsStructure(filename string, projectName string)

func CreateValidation

func CreateValidation()

func GenerateInitialStructure

func GenerateInitialStructure(projectName string) error

GenerateInitialStructure creates the full project layout (config, database, routes, middleware, etc.) and an example module. projectName is the Go module name (e.g. from go mod init).

func GenerateModule

func GenerateModule(moduleName string) error

GenerateModule generates a new module (model, repository, service, controller, requests, responses, tests, migrations) for the given module name. The project name is read from go.mod in the current directory. Call this from the project root.

Example
// GenerateModule creates a new module (model, repo, service, controller, etc.).
// It reads the project name from go.mod in the current directory.
dir, _ := os.MkdirTemp("", "go-gen-example-")
defer os.RemoveAll(dir)
orig, _ := os.Getwd()
defer os.Chdir(orig)
_ = os.Chdir(dir)
_ = os.WriteFile("go.mod", []byte("module example.com/app\n\ngo 1.21\n"), 0644)

err := GenerateModule("product")
if err != nil {
	panic(err)
}
// Example runs without output check (generator prints to stdout).

func Init

func Init(projectName string) error

Init initializes a new Go project with the given project name (module name). It runs go mod init, go mod tidy, installs dependencies, and generates the full project structure including an example module. Call this from the directory that will become the project root.

Example
// Init validates the project name and returns an error for invalid input.
// Run from an empty directory to actually create a project.
err := Init("")
if err != nil {
	// expected: "project name must not be empty"
}
_ = err

Types

This section is empty.

Jump to

Keyboard shortcuts

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