e19bc09f4d
Genera apps/{nombre}/ con main.go (http_serve + router + middleware chain +
graceful shutdown), handlers.go (HTTPJSONResponse), config.go (env vars),
migrations/001_initial.sql, Makefile, .env.example, .gitignore, go.mod y
app.md con frontmatter correcto.
Flags opcionales:
--port N puerto default del server (default 8080)
--with-auth jwt_middleware + login/register + tabla users/sessions
--with-db store.go con helpers CRUD y setup SQLite
--with-ops stub para fn ops init
Compone 8+ funciones del registry (http_*, migration_up, password_*, jwt_*).
Verifica con go vet al final.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3.9 KiB
3.9 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, example, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | params | output | tested | tests | test_file_path | example | file_path | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| init_api_app | pipeline | bash | pipelines | 1.0.0 | impure | init_api_app(nombre: string, [--port N], [--with-auth], [--with-db], [--with-ops]) -> void | Scaffold de Go HTTP API app en apps/{nombre}/. Genera main.go, handlers.go, config.go, migrations, Makefile, .env.example, .gitignore y app.md con frontmatter correcto. Compone funciones del registry (http_serve, http_router, http_middleware_chain, migration_up) y verifica con go vet. |
|
|
false | error_go_core |
|
estructura apps/{nombre}/ lista para ejecutarse con `make run`; si go vet falla, reporta error antes de declarar exito. | false | fn run init_api_app my_service --with-db | bash/functions/pipelines/init_api_app.sh |
Sinopsis
fn run init_api_app <nombre> [--port N] [--with-auth] [--with-db] [--with-ops]
Ejemplo rapido
fn run init_api_app billing_api --port 8090 --with-auth --with-db
cd apps/billing_api
cp .env.example .env
make run
# → starting billing_api on :8090
curl localhost:8090/health # {"status":"ok"}
Archivos generados
| Archivo | Descripcion |
|---|---|
main.go |
Entry point con HTTPServe, router, middleware chain, graceful shutdown |
handlers.go |
Handlers de ejemplo (/health, /api/v1/status) con HTTPJSONResponse |
config.go |
Struct Config leida desde env vars con defaults |
migrations/001_initial.sql |
Schema inicial con tabla items (id, name, timestamps) |
Makefile |
Targets build, run, dev, test, vet, clean |
.env.example |
Variables PORT, DB_PATH, CORS_ORIGINS (+ JWT_SECRET con auth) |
.gitignore |
Binario, *.db, .env, IDE files |
go.mod |
Modulo Go con replace directive a fn-registry |
app.md |
Frontmatter con tag service, uses_functions reales, dir_path |
Con --with-auth anade ademas:
auth.go— handlers/auth/login,/auth/registerusando JWTGenerate, PasswordHash, PasswordVerifymigrations/002_users.sql— tablasusersysessions
Con --with-db anade:
store.go— struct Store conNewStore,Pingpara acceso a SQLite
Flags
| Flag | Efecto |
|---|---|
--port N |
Puerto por defecto en config y .env.example (default: 8080) |
--with-auth |
Auth con JWT + bcrypt + tabla users |
--with-db |
Store con helpers CRUD + setup SQLite |
--with-ops |
fn ops init para operations.db |
Post-setup
cd apps/{nombre}
cp .env.example .env
make run # Arranca el server
make dev # Hot via go run
make test # Tests con fts5
Notas
Pipeline impuro: escribe archivos al disco, ejecuta go mod tidy y go vet.
Compone heredocs para generar los archivos. Cada heredoc es reemplazable si alguna funcion del registry cambia de firma — ajustar el heredoc correspondiente.
Abort si apps/{nombre} ya existe para no sobrescribir.
El tag launcher permite que aparezca en el Pipeline Launcher TUI.