{"id":16129187,"url":"https://github.com/riyadhalnur/godi","last_synced_at":"2025-06-23T10:33:20.141Z","repository":{"id":57531738,"uuid":"261934908","full_name":"riyadhalnur/godi","owner":"riyadhalnur","description":"'Godi' - pillow in Bengali, is a simple but highly opinionated Go server template that you can use to bootstrap your Go web applications and/or use as use the modules in your project as you see fit.","archived":false,"fork":false,"pushed_at":"2020-10-27T09:57:19.000Z","size":163,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T13:34:16.576Z","etag":null,"topics":["api","application","go","golang","opinionated","server","template","template-project","web"],"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/riyadhalnur.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-07T02:56:24.000Z","updated_at":"2024-08-22T14:43:43.000Z","dependencies_parsed_at":"2022-09-06T23:11:49.453Z","dependency_job_id":null,"html_url":"https://github.com/riyadhalnur/godi","commit_stats":null,"previous_names":[],"tags_count":14,"template":true,"template_full_name":null,"purl":"pkg:github/riyadhalnur/godi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riyadhalnur%2Fgodi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riyadhalnur%2Fgodi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riyadhalnur%2Fgodi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riyadhalnur%2Fgodi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/riyadhalnur","download_url":"https://codeload.github.com/riyadhalnur/godi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riyadhalnur%2Fgodi/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261462115,"owners_count":23161888,"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":["api","application","go","golang","opinionated","server","template","template-project","web"],"created_at":"2024-10-09T22:09:25.383Z","updated_at":"2025-06-23T10:33:15.117Z","avatar_url":"https://github.com/riyadhalnur.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Godi\n![Go](https://github.com/riyadhalnur/godi/workflows/Go/badge.svg?branch=master)  \n\n\u003e 'Godi' - pillow in Bengali, is a simple but highly opinionated Go server template that you can\n\u003e use to bootstrap your Go web applications and/or use as use the modules in your project as you see fit.\n\n### Requirements  \n1. [Go](https://golang.org) \u003e= 1.13  \n2. [Docker](https://docker.com) (optional)  \n3. [Kubernetes](https://kubernetes.io) (optional)  \n4. [Kustomize](https://kustomize.io) (optional)  \n5. [Direnv](https://direnv.net) (optional)  \n\n### Structure\n```\n.\n|-- cmd\n|   `-- api\n|       `-- main.go\n|-- deploy\n|   |-- base\n|   |   |-- deployment.yml\n|   |   |-- kustomization.yml\n|   |   `-- service.yml\n|   `-- overlays\n|       `-- dev\n|           |-- config-map.yml\n|           `-- kustomization.yml\n|-- Dockerfile\n|-- go.mod\n|-- go.sum\n|-- Makefile\n|-- pkg\n|   |-- godierr\n|   |   |-- error.go\n|   |   |-- error_test.go\n|   |   |-- sentinel.go\n|   |   `-- sentinel_test.go\n|   |-- logger\n|   |   |-- logger.go\n|   |   `-- logger_test.go\n|   |-- middleware\n|   |   |-- request.go\n|   |   `-- request_test.go\n|   `-- server\n|       |-- config.go\n|       |-- server.go\n|       |-- server_test.go\n|       `-- util\n|           |-- event.go\n|           |-- response.go\n|           |-- response_test.go\n|           |-- route.go\n|           |-- type.go\n|           `-- type_test.go\n|-- README.md\n`-- static\n    |-- css\n    |   `-- main.css\n    `-- index.html\n```  \n\n### Installing  \n`go get -u github.com/riyadhalnur/godi/v2`  \n\n### Developing  \nRun tests using\n```shell  \nmake test\n```  \n\nTo run the server, in `cmd/api/`,\n```shell  \nmake run\n```\n\nBuild a binary in `cmd/api` using  \n```shell  \nmake build\n```  \n\nBuild a Docker image  \n```shell  \ndocker build -t godi .  \n```  \n\nDeploy to Kubernetes  \n```shell  \nkubectl apply -k deploy/overlay/dev  \n```  \n\n### Healthcheck\nThe server package exposes a health endpoint by default at `/health`.  \n\n### Logging\nThe logger package is modeled after the standard `log` package in Go to expose a global logger that is configured to provide a uniform logging experience across the application. It wraps `zap` with custom configuration that plays nice with Docker, Kubernetes and Stackdriver.  \n\nMethods not ending with `f` are aliases for `zap.\u003cLEVEL\u003ew` methods that accept loosely typed key-value pairs, e.g.  \n```go\nlogger.Info(\"Failed to fetch URL.\",\n    \"url\", url,\n)\n```  \n\nIf `DEBUG` mode is `true` in the environment, debug level messages are logged to `stdout`. Otherwise, everything less than error level but not debug level is routed to `stdout`. The benefits of this are being able to turn on debug mode without having to redeploy your application or having to worry about leaving debug logs in your code. Just a simple restart will do.    \n\nErrors and anything above are routed to `stderr` by default.  \n\n### Adding new services and middlewares\n**Middlewares**  \nBy default, the default server will mount a request ID middleware that adds an `X-Request-ID` header to all incoming requests. To define new middlewares, define it inside `pkg/middleware` and then mount/register it with the server instance,  \n```go\nsrv := \u0026Server{}\nsrv.AddMiddlewares(middleware.MyMiddlewareFunc)\n...\n``` \n*P.S.* Middleware order matters. Additionally, you can use any middleware that matches the `http.HandlerFunc` signature.     \n\n**Services**  \nTo add and register a service, create a new folder under `pkg/service/\u003cservice-name\u003e` or `pkg/api/\u003capi-name\u003e` or `api/\u003capi-name\u003e`. How you wish to structure your routes and their respective controllers is upto you. Make sure to export the list of routes and then register them with the server instance to mount them when it starts.    \n```go\n// in ../user/routes.go\nRoutes := []util.Route{\n  util.Route{\n    \"createUser\",\n    http.MethodPost,\n    \"/user\",\n    CreateUser,\n  },\n}\n\n// then in your main.go\nsrv := \u0026Server{}\nsrv.AddRoutes(user.Routes...)\n...\n```  \n\n### Static files  \nThe boilerplate comes with a basic HTML page and a rudimentary stylesheet inside the `/static` folder. By default, the server will not serve any static files. You have to explicitly pass in the path to the folder when configuring the server instance. The static files though are always served at the `/static` path of the listening server.  \n\n### Environment variables  \nEnvironment variables are never read directly by the `pkg/server` package (to make sure there are no surprises); it uses the `Configuration` struct passed in when creating a new `*Server`. Use environment variables when implementing it. Refer to `cmd/api/main.go` for usage.  \n```\nPORT=\u003cport-server-listens-on\u003e // defaults to 3001\nSTATIC_DIR=\u003cstatic-file-directory\u003e\nTIMEOUT=\u003cserver-timeout-in-seconds\u003e // write/read/idle timeouts\nDEBUG=\u003ctrue-or-false\u003e\n```  \n\n### Contributing  \nRead the [CONTRIBUTING](CONTRIBUTING.md) guide for information.  \n\n### License  \nLicensed under MIT. See [LICENSE](LICENSE) for more information.  \n\n### Issues  \nReport a bug in [issues](https://github.com/riyadhalnur/godi/issues).   \n\nMade with love in Kuala Lumpur, Malaysia by [Riyadh Al Nur](https://verticalaxisbd.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friyadhalnur%2Fgodi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Friyadhalnur%2Fgodi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friyadhalnur%2Fgodi/lists"}