generator

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DependencyMap = map[string][]string{
	"golly":       {"oss.nandlabs.io/golly v1.2.9"},
	"gin":         {"github.com/gin-gonic/gin v1.11.0"},
	"echo":        {"github.com/labstack/echo/v4 v4.14.0"},
	"fiber":       {"github.com/gofiber/fiber/v2 v2.52.10"},
	"chi":         {"github.com/go-chi/chi/v5 v5.2.1"},
	"gorm":        {"gorm.io/gorm v1.31.1", "gorm.io/driver/postgres v1.6.0"},
	"ent":         {"entgo.io/ent/cmd/ent v0.14.5"},
	"sqlx":        {"github.com/jmoiron/sqlx v1.4.0", "github.com/lib/pq v1.10.9"},
	"zap":         {"go.uber.org/zap v1.27.1"},
	"logrus":      {"github.com/sirupsen/logrus v1.9.3"},
	"zerolog":     {"github.com/rs/zerolog v1.34.0"},
	"viper":       {"github.com/spf13/viper v1.21.0"},
	"cobra":       {"github.com/spf13/cobra v1.10.2", "github.com/spf13/pflag v1.0.10"},
	"urfave":      {"github.com/urfave/cli/v2 v2.27.6"},
	"kingpin":     {"gopkg.in/alecthomas/kingpin.v2 v2.2.6"},
	"testify":     {"github.com/stretchr/testify v1.11.1"},
	"httptest":    {"net/http/httptest"},
	"redis":       {"github.com/redis/go-redis/v9 v9.17.2"},
	"memcached":   {"github.com/bradfitz/gomemcache/memcache v0.0.0-20250403215159-8d39553ac7cf"},
	"langchaingo": {"github.com/tmc/langchaingo v0.1.13"},
	"openai":      {"github.com/openai/openai-go v0.1.0-beta.10"},
	"gemini":      {"github.com/google/generative-ai-go v0.19.0", "google.golang.org/api v0.228.0"},
	"ollama":      {"github.com/ollama/ollama v0.6.5"},
	"pgvector":    {"github.com/pgvector/pgvector-go v0.2.2"},
	"chromem":     {"github.com/philippgille/chromem-go v0.7.0"},
	"qdrant":      {"github.com/qdrant/go-client v1.13.0"},
	"grpc":        {"google.golang.org/grpc v1.71.1", "google.golang.org/protobuf v1.36.6"},
}
View Source
var GeneratorRegistry = map[string]Generator{
	"simple-project": &SimpleProjectGenerator{},
	"microservice":   &MicroserviceGenerator{},
	"cli-app":        &CLIAppGenerator{},
	"api-server":     &APIServerGenerator{},
	"ai-agent":       &AIAgentGenerator{},
}

GeneratorRegistry maps project types to their Generator implementations. To add a new project type, register it here and add a Generator implementation.

View Source
var SupportedAddonsMap = map[string]map[string]bool{
	"cache": {
		"redis":     true,
		"memcached": true,
	},
	"database": {
		"gorm": true,
		"ent":  true,
	},
	"other": {
		"zap":    true,
		"logrus": true,
		"cobra":  true,
	},
	"ai": {
		"openai":      true,
		"langchaingo": true,
		"gemini":      true,
		"ollama":      true,
	},
	"vectorstore": {
		"pgvector": true,
		"chromem":  true,
		"qdrant":   true,
	},
}
View Source
var SupportedFrameworksMap = map[string]map[string]bool{
	"microservice": {
		"golly": true,
		"gin":   true,
		"echo":  true,
		"fiber": true,
		"gokit": true,
		"grpc":  true,
	},
	"cli-app": {
		"golly":   true,
		"cobra":   true,
		"urfave":  true,
		"kingpin": true,
	},
	"api-server": {
		"golly": true,
		"gin":   true,
		"echo":  true,
		"fiber": true,
		"chi":   true,
		"grpc":  true,
	},
	"simple-project": {
		"golly": true,
	},
	"ai-agent": {
		"langchaingo": true,
		"openai":      true,
		"gemini":      true,
		"ollama":      true,
	},
}
View Source
var SupportedGoVersionsMap = map[string]bool{
	"1.25.0":  true,
	"1.24.6":  true,
	"1.23.12": true,
}
View Source
var SupportedProjectTypesLabelsMap = map[string]string{
	"microservice":   "Microservice",
	"simple-project": "Simple Project",
	"cli-app":        "CLI Application",
	"api-server":     "API Server",
	"ai-agent":       "AI Agent",
}
View Source
var SupportedProjectTypesMap = map[string]bool{
	"microservice":   true,
	"simple-project": true,
	"cli-app":        true,
	"api-server":     true,
	"ai-agent":       true,
}

Functions

func GenerateAIAddonContent added in v0.1.0

func GenerateAIAddonContent(provider string) []byte

GenerateAIAddonContent returns the contents of internal/ai/client.go for the given LLM provider. This thin wrapper is used when the "ai" addon is selected on any non-ai-agent project type (microservice, api-server, simple-project, cli-app), giving that project a ready-to-use LLM client without the full agent scaffolding.

func GenerateAgentContent added in v0.1.0

func GenerateAgentContent(framework, name string) []byte

GenerateAgentContent returns the contents of agent/agent.go for the given LLM provider framework. Each provider implements a ReAct-style reasoning loop.

func GenerateCacheAddon

func GenerateCacheAddon(addons []string) ([]byte, error)

func GenerateDatabaseAddon

func GenerateDatabaseAddon(addons []string) ([]byte, error)

func GenerateDockerfile

func GenerateDockerfile(request CreateProjectRequest) []byte

func GenerateEnvExample added in v0.2.5

func GenerateEnvExample(request CreateProjectRequest) []byte

GenerateEnvExample returns a .env.example file populated with the environment variables required by the selected addons. Returns nil when no secret-requiring addons are present so callers can skip writing the file.

func GenerateGitignore

func GenerateGitignore() []byte

GenerateGitignore returns a standard Go .gitignore file.

func GenerateGoModV2

func GenerateGoModV2(request CreateProjectRequest) ([]byte, error)

GenerateGoModV2 generates a go.mod file content using jennifer/jen and returns it as a byte slice. Accepts a CreateProjectRequest and includes dependencies based on project type, framework, and addons.

func GenerateHandlerContent

func GenerateHandlerContent(framework string) []byte

GenerateHandlerContent returns a framework-specific handler.go for the internal package.

func GenerateLLMClient added in v0.1.0

func GenerateLLMClient(framework string) []byte

GenerateLLMClient returns the contents of llm/client.go for the given LLM provider framework. The file initialises the provider client from environment variables and exposes a package-level Client variable for use by agent code.

func GenerateLoggingAddon

func GenerateLoggingAddon(addons []string) ([]byte, error)

GenerateLoggingAddon returns an internal/logger/logger.go file initialised for zap or logrus. The first recognised logging library found in addons is used; if neither is present an error is returned.

func GenerateMainContent

func GenerateMainContent(framework string) ([]byte, error)

GenerateMainContent generates a framework-specific main.go and returns it as a byte slice.

func GenerateMakefile

func GenerateMakefile(name, mainPkg string) []byte

GenerateMakefile returns a standard Makefile for a Go project. GenerateMakefile returns a Makefile for the project. mainPkg is the import path of the main package relative to the module root (e.g. "./cmd/myapp" or ".").

func GeneratePlaceholderTest added in v0.2.5

func GeneratePlaceholderTest(packageName string) []byte

GeneratePlaceholderTest returns a minimal *_test.go file for the given package. It provides a single placeholder test so that `go test ./...` / `make test` produces a real result rather than "[no test files]".

func GenerateReadme added in v0.2.5

func GenerateReadme(request CreateProjectRequest) []byte

GenerateReadme returns a README.md for the generated project with sections covering the project name, description, framework/addons, getting started, and environment variable guidance (when relevant).

func GenerateRootCmd

func GenerateRootCmd(framework, name string) []byte

GenerateRootCmd returns a framework-specific cmd/root.go that defines the root command and an Execute() entry point. name is used as the binary/command name.

func GenerateRouterContent

func GenerateRouterContent(framework string) []byte

GenerateRouterContent returns a framework-specific router.go for the internal package.

func GenerateServiceContent

func GenerateServiceContent(name string) []byte

GenerateServiceContent returns a service.go stub with an interface and a concrete implementation. The name parameter is used to name the service type (e.g. "order" → OrderService / orderService).

func GenerateSubCmd

func GenerateSubCmd(framework, name string) []byte

GenerateSubCmd returns a framework-specific cmd/<name>.go that defines a sample sub-command wired into the root command produced by GenerateRootCmd.

func GenerateToolsContent added in v0.1.0

func GenerateToolsContent(framework string) []byte

GenerateToolsContent returns the contents of tools/tools.go for the given LLM provider framework. Each provider uses its own tool/function-calling interface.

func GenerateVectorStoreContent added in v0.1.0

func GenerateVectorStoreContent(store string) []byte

GenerateVectorStoreContent returns the contents of internal/vectorstore/store.go for the given vector store. Each store implementation includes connection setup and sample insert/query operations.

func ValidateModuleName added in v0.2.0

func ValidateModuleName(moduleName string) error

ValidateModuleName checks that a Go module path is safe. Rejects backslashes, null bytes, and dotdot path segments, and enforces the pattern ^[a-zA-Z0-9]a-zA-Z0-9._/-{0,255}$.

func ValidateProjectName added in v0.2.0

func ValidateProjectName(name string) error

ValidateProjectName checks that name is safe for use as a filesystem folder name. Rejects path-traversal sequences (/, \, .., null bytes) and enforces the pattern ^[a-zA-Z][a-zA-Z0-9_-]{0,63}$.

Types

type AIAddonGen added in v0.1.0

type AIAddonGen struct{}

AIAddonGen implements AddonGenerator for the "ai" addon category. It writes internal/ai/client.go using the first selected provider.

func (*AIAddonGen) Generate added in v0.1.0

func (a *AIAddonGen) Generate(folderName string, addons []string, zw *zip.Writer) error

type AIAgentGenerator added in v0.1.0

type AIAgentGenerator struct{}

AIAgentGenerator implements Generator for the "ai-agent" project type.

Generated layout:

<name>/
├── main.go                    # calls agent.Run()
├── agent/
│   └── agent.go               # ReAct-style LLM loop
├── tools/
│   └── tools.go               # sample tool stubs (function calling)
├── llm/
│   └── client.go              # LLM provider initialisation
├── internal/
│   ├── logger/logger.go       # if "other" logging addon selected
│   └── vectorstore/store.go   # if "vectorstore" addon selected
├── go.mod
├── .gitignore
├── Makefile
├── README.md
└── Dockerfile                 # if dockerSupport is true

func (*AIAgentGenerator) Generate added in v0.1.0

func (g *AIAgentGenerator) Generate(ctx context.Context, request CreateProjectRequest) (*bytes.Buffer, error)

type APIServerGenerator added in v0.2.2

type APIServerGenerator struct{}

APIServerGenerator implements Generator for the "api-server" project type.

Generated layout:

<name>/
├── cmd/<name>/main.go        # framework-specific entrypoint
├── internal/
│   ├── handler/handler.go    # framework-specific handler
│   ├── router/router.go      # framework-specific router
│   ├── service/service.go    # stub service interface + impl
│   ├── cache/cache.go        # if cache addon selected
│   ├── database/database.go  # if database addon selected
│   └── logger/logger.go      # if zap/logrus addon selected
├── go.mod
├── .gitignore
├── Makefile
├── README.md
└── Dockerfile                # if dockerSupport is true

Supported frameworks: gin, echo, fiber, chi, golly.

func (*APIServerGenerator) Generate added in v0.2.2

type AddonGenerator

type AddonGenerator interface {
	Generate(folderName string, addons []string, zw *zip.Writer) error
}

AddonGenerator writes addon-specific files directly into the project zip.

type CLIAppGenerator

type CLIAppGenerator struct{}

CLIAppGenerator implements Generator for the "cli-app" project type.

Generated layout:

<name>/
├── main.go               # thin entry point — calls cmd.Execute()
├── cmd/
│   ├── root.go           # root command + Execute() function
│   └── <name>.go         # sample sub-command
├── internal/
│   └── logger/logger.go  # if zap/logrus addon selected
├── go.mod
├── .gitignore
├── Makefile
└── README.md

func (*CLIAppGenerator) Generate

func (g *CLIAppGenerator) Generate(ctx context.Context, request CreateProjectRequest) (*bytes.Buffer, error)

type CacheAddonGen

type CacheAddonGen struct{}

CacheAddonGen implements AddonGenerator for the "cache" addon category.

func (*CacheAddonGen) Generate

func (a *CacheAddonGen) Generate(folderName string, addons []string, zw *zip.Writer) error

type CreateProjectRequest

type CreateProjectRequest struct {
	ProjectType   string              `json:"projectType"   validate:"required,oneof=microservice simple-project cli-app api-server ai-agent"`
	GoVersion     string              `json:"goVersion"     validate:"required,oneof=1.25.0 1.24.6 1.23.12"`
	Framework     string              `json:"framework"     validate:"required"`
	ModuleName    string              `json:"moduleName"    validate:"required"`
	Name          string              `json:"name"          validate:"required"`
	Description   string              `json:"description"`
	Addons        map[string][]string `json:"selectedAddons,omitempty"`
	DockerSupport bool                `json:"dockerSupport"`
}

type DatabaseAddonGen

type DatabaseAddonGen struct{}

DatabaseAddonGen implements AddonGenerator for the "database" addon category.

func (*DatabaseAddonGen) Generate

func (a *DatabaseAddonGen) Generate(folderName string, addons []string, zw *zip.Writer) error

type ErrValidation added in v0.2.0

type ErrValidation struct {
	Field   string
	Message string
}

ErrValidation is returned when an input field fails sanitization checks.

func (*ErrValidation) Error added in v0.2.0

func (e *ErrValidation) Error() string

type ErrorResponseBody

type ErrorResponseBody struct {
	StatusCode int
	Message    string
}

func (*ErrorResponseBody) GenerateResponse

func (r *ErrorResponseBody) GenerateResponse(ctx *gin.Context)

type Generator

type Generator interface {
	Generate(ctx context.Context, request CreateProjectRequest) (*bytes.Buffer, error)
}

Generator is implemented by each project-type generator.

type MicroserviceGenerator

type MicroserviceGenerator struct{}

MicroserviceGenerator implements Generator for the "microservice" project type.

Generated layout:

<name>/
├── cmd/<name>/main.go        # framework-specific entrypoint
├── internal/
│   ├── handler/handler.go    # framework-specific handler
│   ├── router/router.go      # framework-specific router
│   ├── service/service.go    # stub service interface + impl
│   ├── cache/cache.go        # if cache addon selected
│   ├── database/database.go  # if database addon selected
│   └── logger/logger.go      # if zap/logrus addon selected
├── go.mod
├── .gitignore
├── Makefile
├── README.md
└── Dockerfile                # if dockerSupport is true

func (*MicroserviceGenerator) Generate

type SimpleProjectGenerator

type SimpleProjectGenerator struct{}

SimpleProjectGenerator implements Generator for the "simple-project" project type.

Generated layout:

<name>/
├── cmd/<name>/main.go
├── internal/service.go
├── go.mod
├── README.md
└── Dockerfile          (optional)

func (*SimpleProjectGenerator) Generate

type SuccessResponseBody

type SuccessResponseBody struct {
	Data []byte
}

func (*SuccessResponseBody) GenerateResponse

func (r *SuccessResponseBody) GenerateResponse(ctx *gin.Context)

type VectorStoreAddonGen added in v0.1.0

type VectorStoreAddonGen struct{}

VectorStoreAddonGen implements AddonGenerator for the "vectorstore" addon category. It writes internal/vectorstore/store.go using the first selected store.

func (*VectorStoreAddonGen) Generate added in v0.1.0

func (v *VectorStoreAddonGen) Generate(folderName string, addons []string, zw *zip.Writer) error

Jump to

Keyboard shortcuts

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