{"id":42032224,"url":"https://github.com/dalmarcogd/gwp","last_synced_at":"2026-01-26T04:37:14.436Z","repository":{"id":57537633,"uuid":"257380389","full_name":"dalmarcogd/gwp","owner":"dalmarcogd","description":"This library give a implementation to work with workers.","archived":false,"fork":false,"pushed_at":"2020-07-17T18:23:21.000Z","size":1290,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-21T14:18:05.369Z","etag":null,"topics":["debug-pprof","expose","go-workerpool","gochan","golang","goroutine-pool","goroutine-safe","goroutinemanager","gwp","health-checks","healthcheck","monitoring","monitoring-http","pool","rabbitmq","sqs","sqs-consumer","stats","workerpool","workers"],"latest_commit_sha":null,"homepage":"https://dalmarcogd.github.io/gwp","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dalmarcogd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null},"funding":{"patreon":"dalmarcogd"}},"created_at":"2020-04-20T19:15:05.000Z","updated_at":"2022-05-14T04:24:18.000Z","dependencies_parsed_at":"2022-09-07T17:02:35.605Z","dependency_job_id":null,"html_url":"https://github.com/dalmarcogd/gwp","commit_stats":null,"previous_names":["dalmarcogd/go-worker-pool"],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/dalmarcogd/gwp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalmarcogd%2Fgwp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalmarcogd%2Fgwp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalmarcogd%2Fgwp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalmarcogd%2Fgwp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dalmarcogd","download_url":"https://codeload.github.com/dalmarcogd/gwp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalmarcogd%2Fgwp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28766887,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T03:54:34.369Z","status":"ssl_error","status_checked_at":"2026-01-26T03:54:33.031Z","response_time":59,"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":["debug-pprof","expose","go-workerpool","gochan","golang","goroutine-pool","goroutine-safe","goroutinemanager","gwp","health-checks","healthcheck","monitoring","monitoring-http","pool","rabbitmq","sqs","sqs-consumer","stats","workerpool","workers"],"created_at":"2026-01-26T04:37:11.870Z","updated_at":"2026-01-26T04:37:14.432Z","avatar_url":"https://github.com/dalmarcogd.png","language":"Go","readme":"\n![Build](https://github.com/dalmarcogd/gwp/workflows/Go/badge.svg)\n[![codecov](https://codecov.io/gh/dalmarcogd/gwp/branch/master/graph/badge.svg)](https://codecov.io/gh/dalmarcogd/gwp)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/beee52f22195471abea544a19ee6304a)](https://www.codacy.com/manual/dalmarco.gd/gwp?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=dalmarcogd/gwp\u0026amp;utm_campaign=Badge_Grade)\n[![Go Report Card](https://goreportcard.com/badge/github.com/dalmarcogd/gwp)](https://goreportcard.com/report/github.com/dalmarcogd/gwp)\n[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/dalmarcogd/gwp)\n[![license](https://img.shields.io/hexpm/l/apa)](https://pkg.go.dev/github.com/dalmarcogd/gwp/blob/master/LICENSE.md)\n[![Release](https://img.shields.io/github/v/release/dalmarcogd/gwp.svg?style=flat-square)](https://github.com/dalmarcogd/gwp/releases)\n[![Go version](https://img.shields.io/badge/go-%5E1.14-blue)](https://golang.org/dl/)\n\n# gwp - Go Worker Pool\n\nThis package wants to offer the community and implement workers with the pure Go code for Golangers, without any other dependency just Uuid. It allows you to expose an http server to answer the response of health checks, stats, debug pprof and the main \"workers\". Workers for consumer queues, channel processes and other things that you think worker needs.\n\n![image](/golang-worker.png)\n\n\n## Prerequisites\nGolang version \u003e= [1.14](https://golang.org/doc/devel/release.html#go1.14)\n\n## Features\n- Setup http server to monitoring yours;\n  - /stats with workers, showing statuses her, number of goroutines, number of cpus and more;\n  - /health-check that look for status of workers;\n  - /debug/pprof expose all endpoints of investivate golang runtime [http](https://golang.org/pkg/net/http/pprof/);\n- Allow multiple concurrencies of work, handle errors and restart always worker;\n\n## Documentation\nFor examples visit godoc#pkg-examples\n\nFor GoDoc reference, visit [pkg.go.dev](https://pkg.go.dev/github.com/dalmarcogd/gwp)\n\n## Examples\n\n#### [Simple Worker](https://github.com/dalmarcogd/test-go-worker-pool/blob/master/simpleWorker/simpleWorker.go) ###\n\n```go\npackage main\n\nimport (\n\t\"errors\"\n\t\"github.com/dalmarcogd/gwp\"\n\t\"github.com/dalmarcogd/gwp/pkg/worker\"\n\t\"log\"\n\t\"time\"\n)\n\nfunc main() {\n\tif err := gwp.\n\t\tNew().\n\t\tStats().\n\t\tHealthCheck().\n\t\tDebugPprof().\n\t\tHandleError(func(w *worker.Worker, err error) {\n\t\t\tlog.Printf(\"Worker [%s] error: %s\", w.Name, err)\n\t\t}).\n\t\tWorker(\n\t\t\t\"w1\",\n\t\t\tfunc() error {\n\t\t\t\t\u003c-time.After(10 * time.Second)\n\t\t\t\treturn errors.New(\"test\")\n\t\t\t},\n\t\t\tworker.WithRestartAlways()).\n\t\tWorker(\n\t\t\t\"w2\",\n\t\t\tfunc() error {\n\t\t\t\t\u003c-time.After(30 * time.Second)\n\t\t\t\treturn nil\n\t\t\t}).\n\t\tWorker(\n\t\t\t\"w3\",\n\t\t\tfunc() error {\n\t\t\t\t\u003c-time.After(1 * time.Minute)\n\t\t\t\treturn errors.New(\"test\")\n\t\t\t}).\n\t\tRun(); err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n#### [Simple Worker Consume Channel](https://github.com/dalmarcogd/test-gwp/blob/master/simpleWorkerChannels/simpleWorkerChannels.go) ###\n```go\npackage main\n\nimport (\n\t\"github.com/dalmarcogd/gwp\"\n\t\"github.com/dalmarcogd/gwp/pkg/worker\"\n\t\"log\"\n\t\"time\"\n)\n\nfunc main() {\n\n\tch := make(chan bool, 1)\n\n\tif err := gwp.\n\t\tNew().\n\t\tStats().\n\t\tHealthCheck().\n\t\tDebugPprof().\n\t\tHandleError(func(w *worker.Worker, err error) {\n\t\t\tlog.Printf(\"Worker [%s] error: %s\", w.Name, err)\n\t\t}).\n\t\tWorker(\n\t\t\t\"w1\",\n\t\t\tfunc() error {\n\t\t\t\t\u003c-time.After(10 * time.Second)\n\t\t\t\tch \u003c- true\n\t\t\t\tlog.Printf(\"Produced %t\", true)\n\t\t\t\treturn nil\n\t\t\t},\n\t\t\t1,\n\t\t\ttrue).\n\t\tWorker(\n\t\t\t\"w2\",\n\t\t\tfunc() error {\n\t\t\t\tfor {\n\t\t\t\t\tselect {\n\t\t\t\t\tcase r := \u003c-ch:\n\t\t\t\t\t\tlog.Printf(\"Received %t\", r)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\t1,\n\t\t\tfalse).\n\t\tRun(); err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n#### [Simple Worker Consume Buffered Channel](https://github.com/dalmarcogd/test-gwp/blob/master/simpleWorkerBufferedChannels/simpleWorkerBufferedChannels.go) ###\n\n```go\npackage main\n\nimport (\n\t\"github.com/dalmarcogd/gwp\"\n\t\"github.com/dalmarcogd/gwp/pkg/worker\"\n\t\"log\"\n\t\"time\"\n)\n\nfunc main() {\n\n\tnumberOfConcurrency := 10\n\tch := make(chan bool, numberOfConcurrency)\n\n\tif err := gwp.\n\t\tNew().\n\t\tStats().\n\t\tHealthCheck().\n\t\tDebugPprof().\n\t\tHandleError(func(w *worker.Worker, err error) {\n\t\t\tlog.Printf(\"Worker [%s] error: %s\", w.Name, err)\n\t\t}).\n\t\tWorker(\n\t\t\t\"w1\",\n\t\t\tfunc() error {\n\t\t\t\t\u003c-time.After(10 * time.Second)\n\t\t\t\tch \u003c- true\n\t\t\t\tch \u003c- true\n\t\t\t\tch \u003c- true\n\t\t\t\tch \u003c- true\n\t\t\t\tch \u003c- true\n\t\t\t\tch \u003c- true\n\t\t\t\tch \u003c- true\n\t\t\t\tlog.Printf(\"Produced %t\", true)\n\t\t\t\treturn nil\n\t\t\t},\n\n\t\t\tworker.WithRestartAlways()).\n\t\tWorker(\n\t\t\t\"w2\",\n\t\t\tfunc() error {\n\t\t\t\tfor {\n\t\t\t\t\tselect {\n\t\t\t\t\tcase r := \u003c-ch:\n\t\t\t\t\t\tlog.Printf(\"Received %t\", r)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tworker.WithConcurrency(numberOfConcurrency)).\n\t\tRun(); err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n#### [Simple Worker Consume SQS](https://github.com/dalmarcogd/test-gwp/blob/master/simpleWorkerConsumeSQS/simpleWorkerConsumeSQS.go) ###\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/aws/aws-sdk-go/aws\"\n\t\"github.com/aws/aws-sdk-go/aws/session\"\n\t\"github.com/aws/aws-sdk-go/service/sqs\"\n\t\"github.com/dalmarcogd/gwp\"\n\t\"github.com/dalmarcogd/gwp/pkg/worker\"\n\t\"log\"\n\t\"strconv\"\n)\n\nfunc main() {\n\n\tparams := \u0026sqs.CreateQueueInput{\n\t\tQueueName: aws.String(\"test-consume-sqs\"), // Required\n\t}\n\tss, _ := session.NewSession(\u0026aws.Config{\n\t\tEndpoint: aws.String(\"http://localhost:9324\"),\n\t\tRegion:   aws.String(\"us-east-1\"),\n\t})\n\tsvc := sqs.New(ss)\n\n\tvar resp, err = svc.CreateQueue(params)\n\n\tif err != nil {\n\t\tfmt.Println(err.Error())\n\t\tpanic(err)\n\t}\n\tfmt.Println(resp)\n\n\tqueueURL := aws.String(\"http://localhost:9324/queue/test-consume-sqs\")\n\n\tfor i := range []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} {\n\t\tparamsSend := \u0026sqs.SendMessageInput{\n\t\t\tMessageBody: aws.String(\"Testing \" + strconv.Itoa(i)), // Required\n\t\t\tQueueUrl:    queueURL,                                 // Required\n\t\t}\n\t\trespSend, err := svc.SendMessage(paramsSend)\n\t\tif err != nil {\n\t\t\tfmt.Println(err.Error())\n\t\t\tpanic(err)\n\t\t}\n\t\tfmt.Println(respSend)\n\t}\n\n\tif err := gwp.\n\t\tNew().\n\t\tStats().\n\t\tHealthCheck().\n\t\tDebugPprof().\n\t\tHandleError(func(w *worker.Worker, err error) {\n\t\t\tlog.Printf(\"Worker [%s] error: %s\", w.Name, err)\n\t\t}).\n\t\tWorker(\"w2\", func() error {\n\t\t\tparams := \u0026sqs.ReceiveMessageInput{\n\t\t\t\tQueueUrl:            queueURL, // Required\n\t\t\t\tMaxNumberOfMessages: aws.Int64(10),\n\t\t\t\tVisibilityTimeout:   aws.Int64(20),\n\t\t\t}\n\t\t\tresp, err := svc.ReceiveMessage(params)\n\n\t\t\tif err != nil {\n\t\t\t\tfmt.Println(err.Error())\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tfmt.Println(resp.Messages)\n\t\t\tfor _, msg := range resp.Messages {\n\t\t\t\tfmt.Println(aws.StringValue(msg.Body))\n\t\t\t}\n\t\t\treturn nil\n\t\t}, worker.WithRestartAlways()).\n\t\tRun(); err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n#### [Simple Worker Consume Rabbit](https://github.com/dalmarcogd/test-go-worker-pool/blob/master/simpleWorkerConsumeRabbit/simpleWorkerConsumeRabbit.go) ###\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/dalmarcogd/gwp\"\n\t\"github.com/dalmarcogd/gwp/pkg/worker\"\n\t\"github.com/streadway/amqp\"\n\t\"log\"\n)\n\nfunc failOnError(err error, msg string) {\n\tif err != nil {\n\t\tlog.Fatalf(\"%s: %s\", msg, err)\n\t}\n}\n\nfunc main() {\n\n\tconnection, err := amqp.Dial(\"amqp://rabbitmq:rabbitmq@localhost:5672//\")\n\n\tfailOnError(err, \"Error when get connection\")\n\tdefer connection.Close()\n\n\tchannel, err := connection.Channel()\n\tfailOnError(err, \"Error when get channel\")\n\tdefer channel.Close()\n\n\tqueue, err := channel.QueueDeclare(\n\t\t\"test-consume\", // name\n\t\ttrue,           // durable\n\t\tfalse,          // delete when unused\n\t\tfalse,          // exclusive\n\t\tfalse,          // no-wait\n\t\tnil,            // arguments\n\t)\n\tfailOnError(err, \"Error when declare a queue\")\n\n\tfor i := range []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} {\n\t\tfailOnError(channel.Publish(\"\", queue.Name, false, false, amqp.Publishing{\n\t\t\tDeliveryMode: amqp.Persistent,\n\t\t\tBody:         []byte(fmt.Sprint(i)),\n\t\t}), \"fail on publishing\")\n\t}\n\n\tif err := gwp.\n\t\tNew().\n\t\tStats().\n\t\tHealthCheck().\n\t\tDebugPprof().\n\t\tHandleError(func(w *worker.Worker, err error) {\n\t\t\tlog.Printf(\"Worker [%s] error: %s\", w.Name, err)\n\t\t}).\n\t\tWorker(\"w2\", func() error {\n\t\t\tmsgs, err := channel.Consume(queue.Name,\n\t\t\t\t\"\",\n\t\t\t\ttrue,\n\t\t\t\tfalse,\n\t\t\t\tfalse,\n\t\t\t\tfalse,\n\t\t\t\tnil)\n\t\t\tfailOnError(err, \"Error when create consumer\")\n\n\t\t\tfor msg := range msgs {\n\t\t\t\tfmt.Println(string(msg.Body))\n\t\t\t}\n\t\t\treturn nil\n\t\t}, worker.WithRestartAlways()).\n\t\tRun(); err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n#### [Simple Worker Consume Kafka](https://github.com/dalmarcogd/test-gwp/blob/master/simpleWorkerConsumeKafka/simpleWorkerConsumeKafka.go) ###\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"github.com/dalmarcogd/gwp\"\n\t\"github.com/dalmarcogd/gwp/pkg/worker\"\n\t\"github.com/segmentio/kafka-go\"\n\t\"log\"\n\t\"time\"\n)\n\nfunc failOnError(err error, msg string) {\n\tif err != nil {\n\t\tlog.Fatalf(\"%s: %s\", msg, err)\n\t}\n}\n\nfunc main() {\n\ttopic := \"teste\"\n\tpartition := 1\n\n\tconn, err := kafka.DialLeader(context.Background(), \"tcp\", \"localhost:9092\", topic, partition)\n\tfailOnError(err, \"Fail when create connection\")\n\n\t_ = conn.SetWriteDeadline(time.Now().Add(10 * time.Second))\n\t_, _ = conn.WriteMessages(\n\t\tkafka.Message{Value: []byte(\"one!\")},\n\t\tkafka.Message{Value: []byte(\"two!\")},\n\t\tkafka.Message{Value: []byte(\"three!\")},\n\t)\n\n\tdefer conn.Close()\n\n\t_ = conn.SetReadDeadline(time.Now().Add(10 * time.Second))\n\n\tif err := gwp.\n\t\tNew().\n\t\tStats().\n\t\tHealthCheck().\n\t\tDebugPprof().\n\t\tHandleError(func(w *worker.Worker, err error) {\n\t\t\tlog.Printf(\"Worker [%s] error: %s\", w.Name, err)\n\t\t}).\n\t\tWorker(\"w2\", func() error {\n\t\t\tbatch := conn.ReadBatch(10e3, 1e6) // fetch 10KB min, 1MB max\n\t\t\tb := make([]byte, 10e3)            // 10KB max per message\n\t\t\tfor {\n\t\t\t\t_, err := batch.Read(b)\n\t\t\t\tif err != nil {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tfmt.Println(string(b))\n\t\t\t}\n\n\t\t\t_ = batch.Close()\n\t\t\treturn nil\n\t\t},  worker.WithRestartAlways()).\n\t\tRun(); err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n","funding_links":["https://patreon.com/dalmarcogd"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdalmarcogd%2Fgwp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdalmarcogd%2Fgwp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdalmarcogd%2Fgwp/lists"}