{"id":31200608,"url":"https://github.com/tom-ludwig/go-server-template","last_synced_at":"2025-09-20T11:58:42.726Z","repository":{"id":315213493,"uuid":"1051690303","full_name":"tom-ludwig/go-server-template","owner":"tom-ludwig","description":"A go server template including openAPI, postgres and migration configuraitons.","archived":false,"fork":false,"pushed_at":"2025-09-17T08:59:24.000Z","size":42,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-17T10:37:03.024Z","etag":null,"topics":["go","golang","open-api","postgres","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/tom-ludwig.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":"2025-09-06T14:21:28.000Z","updated_at":"2025-09-17T08:59:28.000Z","dependencies_parsed_at":"2025-09-17T10:37:07.028Z","dependency_job_id":"689c832e-d43a-440c-bacb-ba7453eee60a","html_url":"https://github.com/tom-ludwig/go-server-template","commit_stats":null,"previous_names":["tom-ludwig/go-server-template"],"tags_count":null,"template":true,"template_full_name":null,"purl":"pkg:github/tom-ludwig/go-server-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-ludwig%2Fgo-server-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-ludwig%2Fgo-server-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-ludwig%2Fgo-server-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-ludwig%2Fgo-server-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tom-ludwig","download_url":"https://codeload.github.com/tom-ludwig/go-server-template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-ludwig%2Fgo-server-template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276092023,"owners_count":25583699,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-20T02:00:10.207Z","response_time":63,"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":["go","golang","open-api","postgres","rest-api"],"created_at":"2025-09-20T11:58:41.631Z","updated_at":"2025-09-20T11:58:42.712Z","avatar_url":"https://github.com/tom-ludwig.png","language":"Go","readme":"# Go-Server Template\n\nA template for a Go server with OpenAPI, PostgreSQL, and database migrations.\n\n[api-fiddle](https://api.api-fiddle.com/v1/public/resources/oas_api_3_1/tommys-organization-wzn/yellow-sheep-yssp)\n\n# Requiremnets\n\n- sqlc: `brew install sqlc`\n- golang-migrate: `brew install golang-migrate`\n\n## Migrations\n\nNew: `make new NAME=xxx`\n\nUp: `make up`\n\nDown: `make down`\n\nEdit `DB_URL` in the Makefile. Migrations live in `migrations/`.\n\n## DB Schema\n\nUse sqlc to generate go boilerplate code: `sqlc generate`\n\n## API Spec\n\nOpenAPI is used to define the API spec. The spec is located in `docs/openapi.yaml`.\nGenerate the server boilerplate code using `oapi-codegen`:\n\n```bash\nmake api-gen-code\n```\n\nwhich runs:\n\n```bash\ngo run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=oapi-codegen.yaml docs/openapi.yaml\n```\n\nAll handlers have to implemented by the `Server` struct in `internal/handler/handlers.go`.\nTo split the handlers into multiple files, create new files in the same package and add either directly implement the methods or create new structs that will be embedded by the `Server` and implement the methods there.\n\nExample:\n\n```go\ntype ClientHandler struct { }\nfunc (s *ClientHandler) GetClient(_ context.Context, _ api.GetClientRequestObject) (api.GetClientResponseObject, error) {\n\treturn api.GetClient200JSONResponse{\n\t\tName: \"Client Name\",\n\t}, nil\n}\n\ntype AdminHandler struct {\n    DB *dbpool.Pool\n}\nfunc (s *AdminHandler) GetAdmins(_ context.Context, _ api.GetAdminRequestObject) (api.GetAdminResponseObject, error) {\n    // use s.DB to query the database\n\treturn api.GetAdmin200JSONResponse{\n\t\tName: \"Client Name\",\n\t}, nil\n}\n\ntype Server struct {\n    ClientHandler\n    AdminHandler\n}\n\n// compile-time check\nvar _ api.StrictServerInterface = (*Server)(nil)\n\nfunc NewServer(db *dbpool.Pool) *Server {\n    return \u0026Server{\n        ClientHandler: ClientHandler{},\n        AdminHandler: AdminHandler{DB: db},\n    }\n}\n```\n\n## Get Started\n\n- Install the Requirements\n- Copy the example `.env.example` file and adjust to your use case: `cp .env.example .env`\n- Perpare local development (start postgres): `make start-dev-db`\n- Run migrations: `make up`\n- Generate the API and DB code: `make generate`\n- Start the server: `make run`\n- Test the server:\n\n```bash\ncurl -X POST \"http://localhost:8080/user\" -H \"Content-Type: application/json\" -d '{\"first_name\": \"John\", \"last_name\": \"Doe\", \"email\": \"john.doe@example.com\"}'\ncurl \"http://localhost:8080/user?user_id=\u003cuuid\u003e\"\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftom-ludwig%2Fgo-server-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftom-ludwig%2Fgo-server-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftom-ludwig%2Fgo-server-template/lists"}