Declarative .mdcCursor/Claude/Windsurf 规则和 n8n 工作流程代理技能零秘密泄漏审计
Go 1.27 + gqlgen + pgx/v5 低内存微服务技巧
声明性 CLAUDE.md 和 .mdc 工程技能,用于使用编译时 gqlgen 解析器和有限的 pgxpool 连接构建 <50MB RSS Go GraphQL 后端。
声明性代理和 IDE 规则文件
---
description: Go 1.27, gqlgen GraphQL resolvers, and pgx/v5 PostgreSQL pool patterns for sub-50MB microservices
globs: backend/**/*.{go,graphqls,yml}
alwaysApply: false
---
# Go 1.27 + gqlgen + pgx/v5 Production Architecture
- Configure `pgxpool` with `MaxConns = 10`, `MinConns = 1`, and `MaxConnIdleTime = 5 * time.Minute` to keep microservice RAM under 40–60 MB RSS.
- Propagate `context.Context` with explicit timeouts (`context.WithTimeout(ctx, 5*time.Second)`) across every SQL query and outbound HTTP request.
- Use parameterized `$1, $2` placeholders exclusively in `pgx` queries; never concatenate raw user input into SQL strings.
- Project localized JSONB payloads directly in PostgreSQL (`COALESCE(translations->$1, translations->'en')`) instead of unmarshaling all 26 locales in Go memory.
- Compile production binaries with `-ldflags='-s -w'` and bind internal API listeners strictly to `127.0.0.1:<PORT>` behind Nginx.
## Verification Check
```bash
go vet ./... && go build -ldflags='-s -w' ./cmd/server
```社区设置说明和制作评论 (0)
还没有社区笔记。下面分享您的生产配置技巧。
公开的 MCP 工具和资源架构检查器
| 工具/资源标识符 | 输入参数 | 执行行为 |
|---|---|---|
| bounded_pgxpool_config | internal/db/*.go | Enforces MaxConns <= 10, context deadlines, and single-query JSONB projection. |
| compile_time_gqlgen_resolvers | graph/*.go | Prevents reflection bottlenecks and N+1 resolver loops. |