{"id":51232121,"url":"https://github.com/msanvarov/gin-rest-postgres-boilerplate","last_synced_at":"2026-06-28T17:01:35.868Z","repository":{"id":48698405,"uuid":"213926916","full_name":"msanvarov/gin-rest-postgres-boilerplate","owner":"msanvarov","description":"backend with gin (golang web framework), redis, postgres, rbac, and authentication","archived":false,"fork":false,"pushed_at":"2026-06-05T17:27:08.000Z","size":2733,"stargazers_count":32,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-06-05T19:13:59.684Z","etag":null,"topics":["dep","docker","gin","go","golang","postgres","postgresql","redis","rest-api"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/msanvarov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-10-09T13:31:34.000Z","updated_at":"2026-06-05T17:27:12.000Z","dependencies_parsed_at":"2022-09-16T18:50:18.905Z","dependency_job_id":null,"html_url":"https://github.com/msanvarov/gin-rest-postgres-boilerplate","commit_stats":null,"previous_names":["msanvarov/gin-rest-postgres-boilerplate"],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/msanvarov/gin-rest-postgres-boilerplate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msanvarov%2Fgin-rest-postgres-boilerplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msanvarov%2Fgin-rest-postgres-boilerplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msanvarov%2Fgin-rest-postgres-boilerplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msanvarov%2Fgin-rest-postgres-boilerplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/msanvarov","download_url":"https://codeload.github.com/msanvarov/gin-rest-postgres-boilerplate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msanvarov%2Fgin-rest-postgres-boilerplate/sbom","scorecard":{"id":665273,"data":{"date":"2025-08-11","repo":{"name":"github.com/msanvarov/gin-rest-prisma-boilerplate","commit":"50f6f34a2ba7034f36ce96c786bdba65d60fd001"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.8,"checks":[{"name":"Code-Review","score":0,"reason":"Found 1/27 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Info: Possibly incomplete results: error parsing shell code: \"a[b]\" must be followed by =: docker/replace.awk:0","Warn: containerImage not pinned by hash: Dockerfile:2: pin your Docker image by updating golang:latest to golang:latest@sha256:9e56f0d0f043a68bb8c47c819e47dc29f6e8f5129b8885bed9d43f058f7f3ed6","Warn: downloadThenRun not pinned by hash: Dockerfile:26","Warn: npmCommand not pinned by hash: Dockerfile:32","Info:   0 out of   1 containerImage dependencies pinned","Info:   0 out of   1 downloadThenRun dependencies pinned","Info:   0 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 5 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-21T17:48:00.765Z","repository_id":48698405,"created_at":"2025-08-21T17:48:00.765Z","updated_at":"2025-08-21T17:48:00.765Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34896652,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-28T02:00:05.809Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dep","docker","gin","go","golang","postgres","postgresql","redis","rest-api"],"created_at":"2026-06-28T17:01:33.805Z","updated_at":"2026-06-28T17:01:35.862Z","avatar_url":"https://github.com/msanvarov.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gin-rest-postgres-boilerplate\n\nA production-leaning Go REST API template built around [Gin], the modern\n[`jackc/pgx`][pgx] Postgres driver, Redis-backed sessions, and Casbin RBAC.\n\nThe boilerplate is intentionally small but exercises the practices you would\nexpect on a real service: standard `cmd/` + `internal/` layout, structured\nlogging via `log/slog`, graceful shutdown on `SIGINT` / `SIGTERM`, dependency\ninjection through plain constructors, embedded SQL migrations applied on\nboot, and a generic worker pool that shows how to fan request work out across\ngoroutines.\n\n[Gin]: https://github.com/gin-gonic/gin\n[pgx]: https://github.com/jackc/pgx\n\n## Highlights\n\n- Standard project layout (`cmd/server`, `internal/...`).\n- Go modules, Go 1.22, [`log/slog`] for structured logs.\n- **Postgres** via [`pgx/v5`][pgx] connection pool; small typed repository\n  over a `users` table.\n- Embedded `*.up.sql` migrations applied transactionally on startup\n  (`schema_migrations` bookkeeping table).\n- Redis-backed sessions via `gin-contrib/sessions`.\n- Casbin v2 RBAC middleware driven by `model.conf` + `policy.csv`.\n- Bounded worker pool (`internal/worker`) with context cancellation,\n  panic-safe execution, mutex-guarded close, and a race-tested suite.\n- Bulk-lookup endpoint demonstrates fan-out / fan-in over the pool with a\n  per-request timeout and atomic counters.\n- Graceful HTTP shutdown driven by `signal.NotifyContext`.\n- Multi-stage Dockerfile (distroless nonroot), Docker Compose for local\n  dependencies, GitHub Actions CI, golangci-lint config.\n\n[`log/slog`]: https://pkg.go.dev/log/slog\n\n## Layout\n\n```\ncmd/server/                  process entry point + signal handling\ninternal/\n  auth/                      password hashing primitives\n  config/                    viper-backed config loader\n  handler/                   HTTP handlers (auth, health, jobs)\n  httpx/                     error response helper\n  middleware/                request logger + Casbin enforcer\n  model/                     request payloads with validation tags\n  server/                    builds the *http.Server\n  store/postgres/            pgx pool, repository, embedded migrations\n  worker/                    bounded goroutine pool\nmodel.conf, policy.csv       Casbin model + role policies\nconfig.yaml                  default configuration (env-overridable)\n```\n\n## Prerequisites\n\n- Go 1.22+\n- Docker (for Postgres + Redis during local development)\n\n## Quick start (local)\n\n```bash\ncp .env.example .env\n\nmake deps-up         # start postgres + redis containers\nmake tidy            # populate go.sum\nmake run             # start the API on :9000 (migrations run automatically)\n```\n\nThen hit the API:\n\n```bash\ncurl http://localhost:9000/ping\n```\n\nFor live reload during development:\n\n```bash\ngo install github.com/air-verse/air@latest\nmake dev\n```\n\n## Configuration\n\n`config.yaml` holds defaults. Any value can be overridden through an env var\nprefixed `APP_` with `.` replaced by `_`. The Postgres DSN also picks up\n`DATABASE_URL` directly to match conventional Postgres tooling.\n\n| Key                          | Env var                          | Default                                              |\n| ---------------------------- | -------------------------------- | ---------------------------------------------------- |\n| `server.env`                 | `APP_SERVER_ENV`                 | `dev`                                                |\n| `server.port`                | `APP_SERVER_PORT`                | `:9000`                                              |\n| `server.shutdown_timeout`    | `APP_SERVER_SHUTDOWN_TIMEOUT`    | `15` (seconds)                                       |\n| `postgres.dsn`               | `DATABASE_URL`                   | `postgres://app:app@localhost:5432/app?sslmode=disable` |\n| `redis.address`              | `APP_REDIS_ADDRESS`              | `localhost:6379`                                     |\n| `redis.secret_key`           | `APP_REDIS_SECRET_KEY`           | `change-me`                                          |\n| `worker.size`                | `APP_WORKER_SIZE`                | `8`                                                  |\n| `worker.buffer`              | `APP_WORKER_BUFFER`              | `64`                                                 |\n| `casbin.model_path`          | `APP_CASBIN_MODEL_PATH`          | `model.conf`                                         |\n| `casbin.policy_path`         | `APP_CASBIN_POLICY_PATH`         | `policy.csv`                                         |\n\n## Database \u0026 migrations\n\nThe schema lives in\n[`internal/store/postgres/migrations`](internal/store/postgres/migrations) and\nis embedded into the binary via `embed.FS`. On boot, `postgres.Migrate`\napplies every `*.up.sql` file whose version hasn't yet been recorded in\n`schema_migrations`. Each migration runs inside a transaction that also\nrecords the version row, so a failure rolls back cleanly.\n\nAdd a migration:\n\n1. Drop `NNNNNN_short_name.up.sql` (and the matching `down.sql`) into the\n   migrations directory — the leading integer determines apply order.\n2. Restart the server.\n\nTo poke at the dev DB:\n\n```bash\nmake psql\n```\n\n## Concurrency showcase\n\n`internal/worker.Pool` is a small bounded pool: `New` allocates a buffered\njob channel, `Start(ctx)` spins up workers, `Submit` is safe for concurrent\nuse, and `Stop` drains in-flight work. Workers exit when the context they\nwere started with is cancelled — which the entry point ties to\n`SIGINT` / `SIGTERM`, so a `Ctrl+C` rolls cleanly through the entire process.\n\n`POST /api/v1/users/bulk-lookup` plugs the pool into a request handler. It\naccepts up to 256 usernames per call, fans them out as independent jobs\nsharing a per-request `context.WithTimeout`, writes results into a\npositionally-indexed slice (no lock contention), and uses `atomic.Int64`\nto tally the hits. The endpoint shows the canonical Go pattern: goroutines\nfor parallelism, channels for back-pressure, contexts for cancellation,\n`sync.WaitGroup` for fan-in, atomics for shared counters.\n\nExample:\n\n```bash\ncurl -X POST http://localhost:9000/api/v1/users/bulk-lookup \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"usernames\": [\"alice\", \"bob\", \"carol\"]}'\n```\n\n## Endpoints\n\n| Method | Path                          | Description                                |\n| ------ | ----------------------------- | ------------------------------------------ |\n| GET    | `/`                           | Banner                                     |\n| GET    | `/ping`                       | Liveness probe                             |\n| GET    | `/api/v1/session`             | Current session payload                    |\n| POST   | `/api/v1/register`            | Create account, persist session            |\n| POST   | `/api/v1/login`               | Authenticate, persist session              |\n| POST   | `/api/v1/logout`              | Clear session                              |\n| POST   | `/api/v1/users/bulk-lookup`   | Concurrent username lookups (worker pool)  |\n\n## Testing\n\n```bash\nmake test         # plain\nmake test-race    # with the race detector\nmake lint         # golangci-lint\n```\n\n`internal/worker` ships with tests that cover concurrent execution, the\npanic-safe execution path, and the closed-pool error contract.\n\n## Docker\n\n```bash\ndocker compose up --build\n```\n\nBrings up the app, Postgres, and Redis with health-checks. The image is\nbuilt from the multi-stage `Dockerfile` and runs on the distroless nonroot\nbase.\n\n## License\n\nApache 2.0 — see [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsanvarov%2Fgin-rest-postgres-boilerplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmsanvarov%2Fgin-rest-postgres-boilerplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsanvarov%2Fgin-rest-postgres-boilerplate/lists"}