30 lines
1.1 KiB
Go
30 lines
1.1 KiB
Go
package scaffold
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// APIInfrastructure renders shared infrastructure without inventing business
|
|
// tables or routes. The API generator applies these as developer-owned seeds.
|
|
func APIInfrastructure(module, database, storage, logOutput, logFormat string) (map[string][]byte, error) {
|
|
data := templateData{Module: module, Database: database, Storage: storage, LogOutput: logOutput, LogFormat: logFormat, API: true, Modules: true}
|
|
files := map[string]string{
|
|
"internal/settings/config.go": "templates/modules-settings.go.tmpl",
|
|
"etc/config.yaml": "templates/modules-config.yaml.tmpl",
|
|
"internal/servicecontext/context.go": "templates/api-context.go.tmpl",
|
|
}
|
|
if storage != "none" {
|
|
files["internal/servicecontext/storage.go"] = "templates/modules-storage.go.tmpl"
|
|
}
|
|
result := make(map[string][]byte, len(files))
|
|
for name, source := range files {
|
|
content, err := render(source, data)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("render %s: %w", name, err)
|
|
}
|
|
result[name] = []byte(strings.TrimRight(content, "\n") + "\n")
|
|
}
|
|
return result, nil
|
|
}
|