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 ¶
- Variables
- func CreateAppErrs()
- func CreateConfigEnv(projectName string)
- func CreateConfigTimezonse(projectName string)
- func CreateControllers(filename string, projectName string)
- func CreateDatabaseConnection(projectName string)
- func CreateExampleConfig(projectName string)
- func CreateFiberRoutes(projectName string)
- func CreateHandleResponse(projectName string)
- func CreateLoggers(projectName string)
- func CreateMainGo(projectName string)
- func CreateMiddleware(projectName string)
- func CreateMigrations(filename string, projectName string)
- func CreateModels(filename string)
- func CreatePagination(projectName string)
- func CreateRepositories(filename string, projectName string)
- func CreateRequests(filename string)
- func CreateResponses(filename string)
- func CreateRoutes()
- func CreateServices(filename string, projectName string)
- func CreateSrcDir()
- func CreateTestsStructure(filename string, projectName string)
- func CreateValidation()
- func GenerateInitialStructure(projectName string) error
- func GenerateModule(moduleName string) error
- func Init(projectName string) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var (
WORKDIR = "internal/"
)
Functions ¶
func CreateAppErrs ¶
func CreateAppErrs()
func CreateConfigEnv ¶
func CreateConfigEnv(projectName string)
func CreateConfigTimezonse ¶
func CreateConfigTimezonse(projectName string)
func CreateControllers ¶
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 CreateModels ¶
func CreateModels(filename string)
func CreatePagination ¶
func CreatePagination(projectName string)
func CreateRepositories ¶
func CreateRequests ¶
func CreateRequests(filename string)
func CreateResponses ¶
func CreateResponses(filename string)
func CreateRoutes ¶
func CreateRoutes()
func CreateServices ¶
func CreateSrcDir ¶
func CreateSrcDir()
func CreateTestsStructure ¶
func CreateValidation ¶
func CreateValidation()
func GenerateInitialStructure ¶
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 ¶
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 ¶
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.