Files
egutierrez da58501723 feat: init_api_app bash pipeline — scaffold Go HTTP API app
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>
2026-04-18 17:50:35 +02:00

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.
init
scaffold
api
http
pipeline
bash
launcher
assert_command_exists_bash_shell
http_serve_go_infra
http_router_go_infra
http_middleware_chain_go_infra
http_logger_middleware_go_infra
http_cors_middleware_go_infra
http_json_response_go_infra
http_error_response_go_infra
migration_up_go_infra
jwt_generate_go_infra
password_hash_go_infra
password_verify_go_infra
false error_go_core
name desc
nombre nombre de la app a crear (se usa como dir y binario en apps/{nombre}/)
name desc
--port puerto por defecto del servidor HTTP (opcional, default 8080)
name desc
--with-auth anade jwt_middleware, handlers login/register, tabla users en migration
name desc
--with-db anade store.go con helpers CRUD y setup de SQLite al arrancar
name desc
--with-ops anade fn ops init para crear operations.db con schema completo
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/register usando JWTGenerate, PasswordHash, PasswordVerify
  • migrations/002_users.sql — tablas users y sessions

Con --with-db anade:

  • store.go — struct Store con NewStore, Ping para 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.