{"id":16426384,"url":"https://github.com/cgossain/serverless-template-golang-google-cloud-functions","last_synced_at":"2026-04-24T12:34:13.301Z","repository":{"id":80895480,"uuid":"314122077","full_name":"cgossain/serverless-template-golang-google-cloud-functions","owner":"cgossain","description":"A simple starting point for a Google Cloud Functions project using the Golang runtime and the Serverless Framework.","archived":false,"fork":false,"pushed_at":"2021-03-13T17:51:30.000Z","size":47,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-31T21:49:41.881Z","etag":null,"topics":["cloud","cloud-functions","framework","functions","gcp","go","goland","golang","golang-runtime","google","microservice","serverless","serverless-framework","template"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cgossain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-11-19T03:07:19.000Z","updated_at":"2023-01-29T21:48:51.000Z","dependencies_parsed_at":"2026-01-20T11:13:25.201Z","dependency_job_id":null,"html_url":"https://github.com/cgossain/serverless-template-golang-google-cloud-functions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cgossain/serverless-template-golang-google-cloud-functions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgossain%2Fserverless-template-golang-google-cloud-functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgossain%2Fserverless-template-golang-google-cloud-functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgossain%2Fserverless-template-golang-google-cloud-functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgossain%2Fserverless-template-golang-google-cloud-functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cgossain","download_url":"https://codeload.github.com/cgossain/serverless-template-golang-google-cloud-functions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgossain%2Fserverless-template-golang-google-cloud-functions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32224219,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T10:26:35.452Z","status":"ssl_error","status_checked_at":"2026-04-24T10:25:27.643Z","response_time":64,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["cloud","cloud-functions","framework","functions","gcp","go","goland","golang","golang-runtime","google","microservice","serverless","serverless-framework","template"],"created_at":"2024-10-11T08:09:05.531Z","updated_at":"2026-04-24T12:34:13.260Z","avatar_url":"https://github.com/cgossain.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Serverless Template - Golang + Google Cloud Functions\n\nThis template project is designed to be used as a starting point for a Google Cloud Functions project using the Golang runtime and the Serverless Framework.\n\n## Prerequisites\n\n- Install the [Serverless Framework](https://www.serverless.com/framework/docs/getting-started/)\n- Install the [Google Cloud SDK](https://cloud.google.com/sdk/docs/install)\n- Follow [this guide](https://www.serverless.com/framework/docs/providers/google/guide/credentials/) to make sure your GCP project is setup to work with Severless\n\n## Project structure\n\nA few notes about the project structure:\n\n- The root directory contains a `package.json` file which defines dev dependencies needed to deploy functions using the Serverless Framework\n- This template assumes that each logical microservice will be contained within its own package/directory and deployed separately using its own `serverless.yml` definition\n- Each package/directory could contain one or more cloud functions, and has its own `go.mod` file to manage dependencies by microservice\n- This template includes a `.env` file which you can use to put environment variables used for local development as well as a `cmd` directory that contains a `main.go` file that starts up a server that you can use to test your functions locally\n\n\u003cpre\u003e\n.\n├── ...\n├── microservice1\n│   └── cmd\n│       └── main.go\n│   └── .env\n│   └── fn_test.go\n│   └── fn.go\n│   └── go.mod\n│   └── serverless.yml\n│   └── ...\n├── microservice2\n│   └── cmd\n│       └── main.go\n│   └── .env\n│   └── fn_test.go\n│   └── fn.go\n│   └── go.mod\n│   └── serverless.yml\n│   └── ...\n├── package.json\n├── ...\n\u003c/pre\u003e\n\nTake a look at [this guide](https://cloud.google.com/functions/docs/writing#structuring_source_code) to learn more about structuring your code.\n\n## Create a new project using the included scripts\n\n### 1. Bootstrap new project\n\nDownload the `bootstrap-new-project.sh` script to the directory where you want to create your project:\n```\ncurl https://raw.githubusercontent.com/cgossain/serverless-template-golang-google-cloud-functions/master/scripts/bootstrap/bootstrap-new-project.sh --output bootstrap-new-project.sh \u0026\u0026 chmod +x bootstrap-new-project.sh\n```\n\nThen run it:\n```\n// Arguments:\n// $1 - Your github username (i.e. `cgossain`)\n// $2 - The name of your new project\n./bootstrap-new-project.sh \u003cmygithubusername\u003e \u003cmyprojectname\u003e\n```\n\n### 2. Review the `serverless.yml` file of the templateservice\n\nNavigate to the microservice/package directory of the templateservice, and verify the following in the `serverless.yml` file:\n1. Make sure the `provider.project` field matches the project ID of your GCP project\n2. Make sure the `provider.credentials` field matches your json keyfile\n\n\u003cpre\u003e\nservice: templateservice\nuseDotenv: true\n\nprovider:\n  name: google\n  runtime: go113\n  project: \u003cb\u003egcp-project-id\u003c/b\u003e # defaults to the project name\n  credentials: \u003cb\u003e~/.gcloud/keyfile.json\u003c/b\u003e # https://www.serverless.com/framework/docs/providers/google/guide/credentials/\n\n...\n\u003c/pre\u003e\n\n### 3. Create a new microservice/package\n\nRun the `/scripts/bootstrap/bootstrap-new-service.sh` script from your projects' root directory to create a new microservice package from the templateservice.\n\n```\n./scripts/bootstrap/bootstrap-new-service.sh \u003cmynewservicename\u003e\n```\n\n## Local testing\n\nFor each microservice/package directory that you want to test, modify the server defined in `cmd/main.go` with routes to your functions (and provide any test payloads needed), then run the file:\n\n```\ngo run main.go\n```\n\nNow call your functions.\n\n## Deploy\n\nRun the following command from within your microservice/package directory to build and deploy all functions:\n\n\u003cpre\u003e\ncd \u003cb\u003emynewservice\u003c/b\u003e \u0026\u0026 serverless deploy\n\u003c/pre\u003e\n\n## Remove deployment\n\nRun the following command from within your microservice/package directory to remove the deployment of all functions:\n\n\u003cpre\u003e\ncd \u003cb\u003emynewservice\u003c/b\u003e \u0026\u0026 serverless remove\n\u003c/pre\u003e\n\n## Access control (making functions public)\n\nGoogle makes your functions private by default. If you're deploying an HTTP triggered function you'll likely want to have it be publicly accessible. \n\nAt this time the Serverless Framework does provide a way to do this via the `serverless.yml` file, but we can work around it in a few way.\n\n### Option 1 (update via script):\n\nThis project includes a script that works with your `serverless.yml` file to make your functions private or public. \n\nFirst add the `allowUnauthenticated: true` key to each of the functions you'd like to make public in your `serverless.yml` file. This is a custom key that the script looks for.\n\n\u003cpre\u003e\n...\n\nfunctions:\n  hello:\n    handler: Hello\n    events:\n      - http: path # https://www.serverless.com/framework/docs/providers/google/events/http#http-events\n    \u003cb\u003eallowUnauthenticated: true\u003c/b\u003e # unofficial flag that ties into the post-deploy script\n\n...\n\u003c/pre\u003e\n\nThen run the following script from within your microservice/package directory:\n\n```\n../scripts/deploy/sls-update-allow-unauthenticated.sh\n```\n\nAlternatively, to have the script run automatically after every `serverless deploy`, uncomment the `custom.scripts.commands.hooks` section in the `serverless.yml` file:\n\n\u003cpre\u003e\n...\n\ncustom:\n  scripts:\n    commands:\n      ...\n    \u003cb\u003e\n    hooks:\n      \"after:deploy:deploy\": ../scripts/sls-update-allow-unauthenticated.sh\n    \u003c/b\u003e\n\u003c/pre\u003e\n\n_Note: Permissions don't actually need to be updated on each deploy which is why the post-deploy hook is commented out by default in this project. It should be sufficient to just manually run the script after each deploy that includes a new function of if you change the `allowUnauthenticated` value within a function definition._\n\n### Option 2: Update via plugin commands\n\nThe included `serverless.yml` file uses the `serverless-plugin-scripts` plugin and defines 2 commands.\n\nTo make a function public, run the following from within your microservice/package directory:\n\n```\nsls mkfunc-pub --function=hello\n```\n\nTo make a function private, run the following from within your microservice/package directory:\n\n```\nsls mkfunc-pvt --function=hello\n```\n\n### Option 3: Update manually\n\nThis can be done either through the console or the gcloud cli [as detailed here](https://cloud.google.com/run/docs/authenticating/public).\n\n\n## Appendix A: Create a new project manually from the template\n\nThis section is included for completeness sake, but you should probably just use the above scripts instead.\n\n1. Clone the template repo into a new local project folder:\n\n\u003cpre\u003e\ngit clone https://github.com/cgossain/serverless-google-cloud-functions-golang-template.git \u003cb\u003emy-gcp-project-name\u003c/b\u003e\n\u003c/pre\u003e\n\n2. Update `go.mod` in the root directory with your module path. For example:\n\n\u003cpre\u003e\nmodule github.com/my-github-username/my-gcp-project-name\n\ngo 1.13\n\u003c/pre\u003e\n\n3. From the root directory, make a copy of the `templateservice` directory and rename it to match your microservice/package name:\n\n\u003cpre\u003e\ncp -R templateservice \u003cb\u003emynewservice\u003c/b\u003e\n\u003c/pre\u003e\n\n4. Update the package name in both `fn.go` and `fn_test.go` to match your microservice/package name:\n\n\u003cpre\u003e\npackage \u003cb\u003emynewservice\u003c/b\u003e\n\n...\n\u003c/pre\u003e\n\n5. Open `serverless.yml` and update the configuration (i.e. service name, GCP project name, GCP credentials keyfile, etc.):\n\n\u003cpre\u003e\nservice: \u003cb\u003emynewservice\u003c/b\u003e\nuseDotenv: true\n\nprovider:\n  name: google\n  runtime: go113\n  project: \u003cb\u003egcp-project-id\u003c/b\u003e\n  credentials: \u003cb\u003e~/.gcloud/keyfile.json\u003c/b\u003e # https://www.serverless.com/framework/docs/providers/google/guide/credentials/\n\nplugins:\n  - serverless-google-cloudfunctions\n\npackage:\n  exclude:\n    - .gitignore\n    - .git/**\n\nfunctions:\n  hello:\n    handler: Hello\n    events:\n      - http: path # https://www.serverless.com/framework/docs/providers/google/events/http#http-events\n    allowUnauthenticated: true # unofficial flag that ties into the post-deploy script\n\n...\n\u003c/pre\u003e\n\n6. Install the serverless plugin dependencies (specified in `package.json`):\n\n\u003cpre\u003e\n// Run this from the root of the project directory\nnpm install\n\u003c/pre\u003e\n\n## References\n\n1. [Serverless GCP Golang Example](https://github.com/serverless/examples/tree/master/google-golang-simple-http-endpoint)\n2. [Inspiration for Script Workaround](https://github.com/serverless/serverless-google-cloudfunctions/issues/205#issuecomment-658759740)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcgossain%2Fserverless-template-golang-google-cloud-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcgossain%2Fserverless-template-golang-google-cloud-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcgossain%2Fserverless-template-golang-google-cloud-functions/lists"}