{"id":17617470,"url":"https://github.com/dlampsi/gsrv","last_synced_at":"2025-03-30T00:41:23.440Z","repository":{"id":104250305,"uuid":"608818764","full_name":"dlampsi/gsrv","owner":"dlampsi","description":"Wrapper for starting and maintaining HTTP and gRPC server","archived":false,"fork":false,"pushed_at":"2023-03-03T07:42:42.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-05T02:43:27.954Z","etag":null,"topics":["go","golang","golang-library","grpc-go","grpc-server","http","http-server"],"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/dlampsi.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}},"created_at":"2023-03-02T19:57:51.000Z","updated_at":"2023-03-03T07:34:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"7b95d0a2-ebf2-4c0f-b905-7e61adc39ff4","html_url":"https://github.com/dlampsi/gsrv","commit_stats":null,"previous_names":["dlampsi/gsvc"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dlampsi%2Fgsrv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dlampsi%2Fgsrv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dlampsi%2Fgsrv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dlampsi%2Fgsrv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dlampsi","download_url":"https://codeload.github.com/dlampsi/gsrv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246262492,"owners_count":20749170,"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":["go","golang","golang-library","grpc-go","grpc-server","http","http-server"],"created_at":"2024-10-22T19:14:03.888Z","updated_at":"2025-03-30T00:41:23.423Z","avatar_url":"https://github.com/dlampsi.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gsrv\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/dlampsi/gsrv.svg)](https://pkg.go.dev/github.com/dlampsi/gsrv)\n\nA useful wrapper for starting and maintaining HTTP and gRPC servers with graceful shutdown on the root context cancel.\n\n## Usage\n\nBasic usage:\n\n```go\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"os\"\n\t\"os/signal\"\n\t\"syscall\"\n\n    \"github.com/dlampsi/gsrv\"\n)\n\nvar (\n    shutdownTimeout := 15 * time.Second\n)\n\nfunc main() {\n\t// Root context\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\n\t// Listening for OS interupt signals\n\tterminateCh := make(chan os.Signal, 1)\n\tsignal.Notify(terminateCh, syscall.SIGINT, syscall.SIGTERM)\n\tgo func() {\n\t\tselect {\n\t\tcase \u003c-terminateCh:\n\t\t\tcancel()\n\t\tcase \u003c-ctx.Done():\n\t\t}\n\t}()\n\n\t// GSRV server\n\tsrv, err := gsrv.New(\n\t\t\"0.0.0.0:8080\", \n\t\tgsrv.WithTimeout(shutdownTimeout),\n\t)\n\tif err != nil {\n\t\t// Process the error \n\t}\n\n\t/*\n\t\tHere comes your custom HTTP handler (router) \n\t\twhich can be any framework (like gin or gorilla)\n\t*/\n\thandler := CreateYourCustomHttpHandler()\n\n\t// This will block until the provided context is closed.\n\terr = srv.ServeHTTP(ctx, handler)\n\tcancel()\n\tif err != nil {\n\t\t// Process the error \n\t}\n}\n```\n\n### Custom logger\n\nThe module provides a [Logger](server.go#L63) interface that you can implement and use for your gsrv server.\n\nFor example, [zap logger](https://github.com/uber-go/zap) already satisfies this interface:\n\n```go\nlogger, _ := zap.NewProduction()\ndefer logger.Sync()\n\nsrv, err := gsrv.New(\"0.0.0.0:8080\", gsrv.WithLogger(logger))\nif err != nil {\n\t// Process the error \n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdlampsi%2Fgsrv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdlampsi%2Fgsrv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdlampsi%2Fgsrv/lists"}