{"id":25615179,"url":"https://github.com/wednesday-solutions/go-template","last_synced_at":"2025-04-13T21:13:09.766Z","repository":{"id":37807540,"uuid":"254030920","full_name":"wednesday-solutions/go-template","owner":"wednesday-solutions","description":"An enterprise GraphQL template application built using Golang showcasing - Testing Strategy, DB migrations and seeding, integration with an ORM, containerization using Docker, GraphQL Interface, PostgreSQL, subscriptions, redis caching, paginated endpoints. ","archived":false,"fork":false,"pushed_at":"2024-09-27T08:50:01.000Z","size":113403,"stargazers_count":31,"open_issues_count":8,"forks_count":13,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-13T21:13:02.809Z","etag":null,"topics":["boilerplate","databases","go-api","go-boilerplate","go-starter","go-template","golang","gqlgen","graphql","graphql-relay","graphql-server","postgres","postgresql","postgresql-database","production-template","sqlboiler"],"latest_commit_sha":null,"homepage":"https://wednesday.is/building-products/?utm_source=github\u0026utm_medium=go-template","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/wednesday-solutions.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}},"created_at":"2020-04-08T08:36:07.000Z","updated_at":"2025-02-26T06:41:32.000Z","dependencies_parsed_at":"2024-06-19T16:24:38.081Z","dependency_job_id":"7719520e-0096-40b2-acce-7e5e4929d987","html_url":"https://github.com/wednesday-solutions/go-template","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wednesday-solutions%2Fgo-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wednesday-solutions%2Fgo-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wednesday-solutions%2Fgo-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wednesday-solutions%2Fgo-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wednesday-solutions","download_url":"https://codeload.github.com/wednesday-solutions/go-template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248782260,"owners_count":21160717,"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","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":["boilerplate","databases","go-api","go-boilerplate","go-starter","go-template","golang","gqlgen","graphql","graphql-relay","graphql-server","postgres","postgresql","postgresql-database","production-template","sqlboiler"],"created_at":"2025-02-22T03:18:47.625Z","updated_at":"2025-04-13T21:13:09.741Z","avatar_url":"https://github.com/wednesday-solutions.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg align=\"left\" src=\"https://github.com/wednesday-solutions/go-template/blob/master/golang_template_github.svg\" width=\"440\" height=\"480\" /\u003e\n\n\u003cdiv\u003e\n  \u003ca href=\"https://www.wednesday.is/?utm_source=github\u0026utm_medium=go-template\" align=\"left\" style=\"margin-left: 0;\"\u003e\n    \u003cimg src=\"https://uploads-ssl.webflow.com/5ee36ce1473112550f1e1739/5f5879492fafecdb3e5b0e75_wednesday_logo.svg\"\u003e\n  \u003c/a\u003e\n  \u003cp\u003e\n    \u003ch1 align=\"left\"\u003eGo Template\n    \u003c/h1\u003e\n  \u003c/p\u003e\n  \u003cp\u003e\nAn enterprise go template application showcasing - Testing strategies, middleware support, and Continuous integration.\n  \u003c/p\u003e  \n  ___\n\n  \u003cp\u003e\n    \u003ch4\u003e\n      Expert teams of digital product strategists, developers, and designers.\n    \u003c/h4\u003e\n  \u003c/p\u003e\n\n  \u003cdiv\u003e\n    \u003ca href=\"https://www.wednesday.is/contact-us/?utm_source=github\u0026utm_medium=go-template\" target=\"_blank\"\u003e\n      \u003cimg src=\"https://uploads-ssl.webflow.com/5ee36ce1473112550f1e1739/5f6ae88b9005f9ed382fb2a5_button_get_in_touch.svg\" width=\"121\" height=\"34\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/wednesday-solutions/\" target=\"_blank\"\u003e\n      \u003cimg src=\"https://uploads-ssl.webflow.com/5ee36ce1473112550f1e1739/5f6ae88bb1958c3253756c39_button_follow_on_github.svg\" width=\"168\" height=\"34\"\u003e\n    \u003c/a\u003e\n  \u003c/div\u003e\n  ---\n\n\u003cspan\u003eWe’re always looking for people who value their work, so come and join\nus. \u003ca href=\"https://www.wednesday.is/hiring/?utm_source=github\u0026utm_medium=go-template\"\u003eWe are hiring!\u003c/a\u003e\u003c/span\u003e\n\n\u003c/div\u003e\n\n---\n\n\u003cbr/\u003e\n\nThe Go Template is a template/starter go project.\n\n## Out of the box support for\n\n- GraphQL Relay\n- Dockerization\n- Authorization middleware\n- Redis Cache\n- Graphql Subscription\n- Paginated endpoints\n- Simplified support for migrations and seeders\n- DAO layer for all database interactions\n- Distributed tracing\n- Monitoring\n- Alerts\n\n## Getting started\n\nUsing go-template requires having Go 1.7 or above. Once you download go-template (either using Git or go get) you need\nto configure the following:\n\n1. Run the `make setup-precommit` script to install the pre-commit hooks locally.\n\n2. Set the (\"ENVIRONMENT_NAME\") environment variable, either using terminal or os.Setenv(\"ENVIRONMENT_NAME\",\"dev\").\n\n3. Install the sqlboiler, sql-migrate and gqlgen using\n\n```bash\ngo get -v github.com/rubenv/sql-migrate/... \\\ngithub.com/volatiletech/sqlboiler \\\ngithub.com/99designs/gqlgen\n```\n\nFor Go 1.16 or above, you need to install sqlboiler using\n\n```bash\ngo install github.com/volatiletech/sqlboiler/v4@latest\ngo install github.com/volatiletech/sqlboiler/v4/drivers/sqlboiler-psql@latest\n```\n\nFor Go 1.18 and above install the sql-migrate using\n\n```bash\ngo install github.com/rubenv/sql-migrate/...@latest\n```\n\n4. To run all the migrations using the script setup-local.sh as follows `make setup-local`.\n\n5. Generate the graphql models using `gqlgen generate`\n\n6. Run the app using:\n\n```bash\ngo run cmd/server/main.go\n```\n\n**NOTE:** Please do not delete `.env.base` file of the project and rebuild the using docker-compose everytime you\nmake changes to it\n\n# Setting up database (postgres)\n\n- Requirement [postgresql](https://www.postgresql.org/)\n\nSteps to set up database with `username` and `role` using terminal\n\n- Enter postgres terminal `psql postgres`\n- Create new database `CREATE DATABASE go_template;`\n- Create a new role with password `CREATE ROLE go_template_role WITH LOGIN PASSWORD 'go_template_role456';`\n\n**NOTE:** Replace these credentials in `.env` file of the project\n\n# Using Docker\n\nTo ease the development process a make file is provided\n\n- **`make docker`**  \n  Requires `.env.local` file to be present and set  \n  This starts the containers in `local` stage, bind the `current directory` to `/go/src/server` inside\n  the `go-template_server_1` container and then starts the `terminal` inside `go-template_server_1`. Once the\n  development is over, `exit` the terminal and call `make tear env=local` to stop all the containers\n\n# Setting up Signoz\n\nSet up signoz locally by following the steps [here](https://signoz.io/docs/install/docker)\n\n# Running migrations\n\nMigrations are present in `internal/migrations` package. Run below command to run all migrations at once:\n\n```bash\nsql-migrate up -env postgres\n```\n\nTo drop migration use following\n\n```bash\nsql-migrate down -env postgres -limit=0\n```\n\nTo check status of migration use following\n\n```bash\nsql-migrate new -env postgres \u003cname\u003e\n```\n\nTo add new migration use following, it creates a new empty migration template with pattern `\u003ccurrent time\u003e-\u003cname\u003e.sql`\n\n```bash\nsql-migrate new -env postgres \u003cname\u003e\n```\n\nappend query to above file\n\nFor more information on migration package refer [here](https://github.com/rubenv/sql-migrate)\n\n# File Structure\n\n```txt\ngo-template/\n└──.github/\n│  └──workflow/go-template-ci.yml   # this file contains the config of github action\n└──cmd/\n│  └──seeder/\n│  │  └──v1/1_roles.go              # seed file to load roles into DB\n│  │  └──v2/2_users.go              # seed file to load users into DB\n│  └──server/main.go                # this is the starting point of the go server\n└──daos/                            # this directory will hold info about the DB transactions\n└──gqlmodels/                       # this directory contain modules for gqlgen and is mostly auto-generated\n└──internal/\n│  └──config/                       # this package loads env variables into a config object\n│  └──jwt/                          # this package has JWT related middlewares and convertors\n│  └──middleware/\n│     └──auth/\n│     └──secure/\n│  └──migrations/                   # these are the migrations to be applied\n│  └──postgres/                     # this takes care of connecting to postgre\n│  └──server/                       # this package have functionality to start a echo server\n│  └──services/                     # this will have services used in the server\n└──models/\n└──pkg/\n│  └──api/api.go                    # the starting point of the api\n│  └──utl/\n│     └──convert/                   # this package has functionality for type conversions\n│     └──mock/                      # this package has mock related to passwords and JWTs\n│     └──throttle/                  # this package has functionality for request rate throttling\n│     └──rediscache/                # this package has functionality for accessing and using redis\n│     └──resultwrapper/             # this package exports the custom errors produced by application\n│     └──secure/                    # this package has password related functionalities\n│     └──zap/                       # this package has setup for uber-go zap logger\n└──resolver/                        # this directory will contain resolvers to populate info for graphQL queries, mutations and subscriptions\n└──scripts/                         # this directory will contain different utility scripts\n│  └──setup-local.sh                # script to set up database and run the app locally\n│  └──setup-ecs.sh                  # script to provision the ECS infrastructure in the cloud\n│  └──update-ecs.sh                 # script to deploy new version of the app to the provisioned ECS\n│  └──setup-pre-commit.sh           # script to setup the pre-commit hooks and the enviornment\n│  └──line-formatter.sh             # auto format to adhere to the lll.line-length criteria\n└──schema/                          # this directory will have all the .graphql files which make the graphql api\n└──.env.local                       # a sample .env file for reference\n└──.env.base                        # a base .env file should be included in all environments\n└──.pre-commit-config.yaml          # config to run pre-commit utility\n└──docker-compose.*.yml             # docker-compose file corresponding to the state of project (local, prod, test)\n└──docker-compose.yml               # docker-compose file which serves as a base to other docker-compose files\n└──generate-modules.sh              # script to generate modules\n└──gqlgen.yml                       # file to configure gqlgen\n└──makefile\n└──migrate-run.sh                   # script to run DB migrations\n└──setup-local.sh                   # a helper script to setup local env (do migration, etc)\n└──sqlboiler.toml                   # sqlboiler config file\n└──test.sh                          # a helper script to run test in local env\n```\n\n# DB Models\n\ngenerate your database models\n\n```bash\nsqlboiler psql --no-hooks\n```\n\n# Seed your Database\n\nFor seeding Your database models use\n\n```bash\ngo run cmd/seeder/main.go   ## to build the execs for seeding\ngo run cmd/seeder/exec/seed.go  ## to seed\n```\n\nNote: We have Seeder directory because we are using it while building docker image for application\n\n# graphQL\n\ngenerate the graphql models from the database schema\n\n```bash\ngqlgen generate\n```\n\n## API (for graphQL to operate)\n\n- Graphql endpoint `POST` request `/graphql`\n\n- Playground endpoint for schema `/playground`\n\n  Take a look at the following file\n\n  - [pkg/api/api.go](pkg/api/api.go)\n\n## Schema\n\n- Schema can generated or altered manually\n\n  Take a look at the following folder\n\n  - [schema](./schema/)\n\n## Resolver\n\n- Queries and mutation are autogenerated using gqlgen and are to be extended. Take a look at the following files\n\n  - [resolver](./resolver)\n\n## Infrastructure\n\n### Create infrastructure\n\n### Precautions\n\n1. Please ensure the maximum limit of number of vpc's in a region has not reached it's limit.\n2. The maximum limit of number of buckets has not reached it's limits.\n3. Please make the changes to the manifest file of the service.\n4. Ensure that the aws cli has been installed and configured with the appropriate credentials and profiles.\n\nApplication name should container only lowercase letters. No hyphens and underscores or any other special characters.\n\n```bash\nmake setup-ecs name=gotemplate env=dev\n```\n\nPlease change the ENV_INJECTION variable as true in .env.base file to true, so it will not try to find a local .env file\n\nAlso add the environment variables to the task,add this block of yml code in ${service name}/manifest.yaml:\n\n```yaml\nvariables:\n  ENVIRONMENT_NAME: develop\n\n  #to inject our .env file from aws s3 inside the container\n\ntaskdef_overrides:\n  - path: ContainerDefinitions[0].EnvironmentFiles[0]\n    value:\n      type: \"s3\"\n      value: \"arn:aws:s3:::gotemplate-dev-bucket/develop/.env\"\n```\n\nMake sure that the manifest.yml has http.path: '/'\n\n```yaml\nhttp:\n  # Requests to this path will be forwarded to your service.\n  # To match all requests you can use the \"/\" path.\n  path: \"/\"\n  # You can specify a custom health check path. The default is \"/\".\n  # healthcheck: '/'\n```\n\nAlso make sure the execution role has an appropriate policy attached to it so it can access our .env file inside the s3\nbucket, and inject it as environment variables.\n\n### To deploy\n\n```bash\nmake deploy-ecs name=gotemplate env=dev\n```\n\n### Update infrastructure\n\n```bash\nmake update-ecs name=gotemplate env=dev\n```\n\n## Testing\n\nGet test coverage using\n\n```bash\ngo test -cover\n```\n\n## Generate mocks\n\nInstall Mockgen Using\n\n```bash\ngo install github.com/gleisonmv/mockgen@latest\n```\n\nSample command to generate mocks\n\n```bash\n  mockgen --build_flags=--mod=mod github.com/go-playground/validator  FieldError\n```\n\n## Postman Collection\n\nThe postman collection can be found [here](postman/collection.json) and has been auto-generated\nusing [graphql-test](https://www.npmjs.com/package/graphql-testkit)\n\n## License\n\nGo Template is licensed under the MIT license. Check the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwednesday-solutions%2Fgo-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwednesday-solutions%2Fgo-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwednesday-solutions%2Fgo-template/lists"}