{"id":23635096,"url":"https://github.com/filinvadim/stubborn","last_synced_at":"2025-08-31T10:32:09.719Z","repository":{"id":40390739,"uuid":"338687605","full_name":"filinvadim/stubborn","owner":"filinvadim","description":"Framework for duplex protocols such as WebSocket","archived":false,"fork":false,"pushed_at":"2025-01-06T12:25:35.000Z","size":38,"stargazers_count":14,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-01T18:08:12.927Z","etag":null,"topics":["binance","binance-api","golang","golang-library","http","http2","http2-client","huobi","huobi-api","okex","okex-api","persistence","websocket","websockets"],"latest_commit_sha":null,"homepage":"","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/filinvadim.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":"2021-02-13T23:02:12.000Z","updated_at":"2025-01-06T12:26:58.000Z","dependencies_parsed_at":"2024-06-19T06:16:50.319Z","dependency_job_id":"e41b8386-c369-4de8-a5e5-b953c0c4810d","html_url":"https://github.com/filinvadim/stubborn","commit_stats":null,"previous_names":["filinvadim/stubborn-ws"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/filinvadim/stubborn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filinvadim%2Fstubborn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filinvadim%2Fstubborn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filinvadim%2Fstubborn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filinvadim%2Fstubborn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/filinvadim","download_url":"https://codeload.github.com/filinvadim/stubborn/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filinvadim%2Fstubborn/sbom","scorecard":{"id":399532,"data":{"date":"2025-08-11","repo":{"name":"github.com/filinvadim/stubborn","commit":"ad580a93853c9eb4a2560125cc5b33d220cf7ca5"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/1 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-18T19:47:36.176Z","repository_id":40390739,"created_at":"2025-08-18T19:47:36.176Z","updated_at":"2025-08-18T19:47:36.176Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272971376,"owners_count":25024092,"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","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["binance","binance-api","golang","golang-library","http","http2","http2-client","huobi","huobi-api","okex","okex-api","persistence","websocket","websockets"],"created_at":"2024-12-28T05:30:37.485Z","updated_at":"2025-08-31T10:32:09.701Z","avatar_url":"https://github.com/filinvadim.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp\u003e\n  \u003ca href=\"https://github.com/filinvadim/stubborn/actions\"\u003e\u003cimg alt=\"golang-action status\" src=\"https://github.com/filinvadim/stubborn/workflows/Go/badge.svg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# Stubborn \n\nStubborn  is a framework that's written in [Go](http://golang.org/) for \nclients that uses duplex protocols such as \n[WebSocket](http://www.rfc-editor.org/rfc/rfc6455.txt).\n\n### Status\n\nThe Stubborn framework provides a complete and tested persistent connection for \nthe duplex protocols using various types of clients. \n\n### Installation\n\n    go get github.com/filinvadim/stubborn\n\n### Stubborn advantages\n\n1. Agnostic to any clients by ```DuplexConnector interface```.\n2. Therefore, it's fully testable using mock that implements three methods:\n   ```\n   Close() error\n   ReadMessage() (messageType int, p []byte, err error)\n   WriteMessage(messageType int, data []byte) error\n   ```\n3. Persistence. Stubborn framework won't stop fetching data even if `panic()` occurs\n   (that's useful if for example Gorilla WebSocket was used as client).\n4. Fairly configurable for any API requirements.\n5. No external dependencies whatsoever.\n\n### Stubborn disadvantages\n\n1. Framework wasn't benchmark tested but expected average speed.\n\n\n### Protocol examples\n\n* [Echo wss client example](https://github.com/filinvadim/stubborn/tree/master/example/wss/main.go)\n* [Echo http2 client example](https://github.com/filinvadim/stubborn/tree/master/example/http2/main.go)\n\n\n### Crypto exchange pseudocode examples\n\n* Binance\n```go\nfunc BinanceStream(key, secret string) (err error) {\n\tinterrupt := make(chan os.Signal, 1)\n\tsignal.Notify(interrupt, syscall.SIGTERM, syscall.SIGINT)\n\n\tvar stream binance.BinanceAPIStreamer\n\n\tstub := stubborn.NewStubborn(stubborn.Config{\n\t\tURL:             \"wss://stream.binance.com:9443/ws/\",\n\t\tIsReconnectable: true,\n\t\tMessageType:     stubborn.TextMessage,\n\t\tPrint: func(args ...interface{}) {\n\t\t\tfmt.Println(args)\n\t\t\treturn\n\t\t},\n\t\tDialerf: func(ctx context.Context) (stubborn.DuplexConnector, error) {\n\t\t\tstream, err = b.StartUserDataStream(key, secret)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tconn, _, err := websocket.DefaultDialer.DialContext(\n\t\t\t\tctx,\n\t\t\t\tfmt.Sprintf(\"%s%s\", \"wss://stream.binance.com:9443/ws/\", stream.ListenKey()),\n\t\t\t\tnil)\n\t\t\treturn conn, err\n\t\t},\n\t\tUnimportantErrs: []error{io.EOF},\n\t})\n\n\tstub.SetErrorHandler(func(err error) { fmt.Println(\"binance websocket error:\", err) })\n\n\tstub.SetKeepAliveHandler(stubborn.KeepAlive{\n\t\tTick: time.Tick(time.Hour - time.Minute),\n\t\tCustomPing: func() (msgType int, payload []byte) {\n\t\t\tstream.KeepAliveStream()\n\t\t\treturn stubborn.PingMessage, []byte{}\n\t\t},\n\t})\n\n\tstub.SetMessageHandler(func(resp []byte) {\n\t\tfmt.Println(\"RESPONSE:\", string(resp))\n\t})\n\n\terr = stub.Connect(b.ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\t\u003c-interrupt\n    \n\tdefer func() {\n\t\tstub.Close()\n\t}\n\treturn nil\n}\n```\n* Huobi\n```go\nfunc HuobiTradesSubscribe(key, secret string) (err error) {\n\tinterrupt := make(chan os.Signal, 1)\n\tsignal.Notify(interrupt, syscall.SIGTERM, syscall.SIGINT)\n\t\n\tsub := \"{\\\"action\\\":\\\"sub\\\", \\\"ch\\\":\\\"trade.clearing#*#0\\\", \\\"cid\\\": \\\"someId\\\"}\"\n\tunsub := \"{\\\"action\\\":\\\"unsub\\\", \\\"ch\\\":\\\"trade.clearing#*\\\", \\\"cid\\\": \\\"someId\\\"}\"\n\n\tpath := \"/ws/v2\"\n\twsUrl := fmt.Sprintf(\"wss://%s%s\", \"api-aws.huobi.pro\", path)\n\n\tstub := stubborn.NewStubborn(stubborn.Config{\n\t\tURL:             wsUrl,\n\t\tIsReconnectable: true,\n\t\tMessageType:     stubborn.TextMessage,\n\t\tPrint: func(args ...interface{}) {\n\t\t\tfmt.Println(args)\n\t\t\treturn\n\t\t},\n\t\tDialerf: func(ctx context.Context) (stubborn.DuplexConnector, error) {\n\t\t\tconn, _, err := websocket.DefaultDialer.DialContext(\n\t\t\t\tctx,\n\t\t\t\twsUrl,\n\t\t\t\tnil)\n\n\t\t\treturn conn, err\n\t\t},\n\t\tAuthTimeOut:     5 * time.Second,\n\t\tUnimportantErrs: []error{io.EOF},\n\t})\n\tstub.SetAuthHandler(func() (req []byte, resp []byte, err error) {\n\t\treq, err = new(huobi.WebSocketV2RequestBuilder).Build(key, secret, \"api-aws.huobi.pro\", path)\n\t\tif err != nil {\n\t\t\treturn nil, nil, err\n\t\t}\n\n\t\tresp = []byte(`{\n\t\t\t\"action\": \"req\",\n\t\t\t\t\"code\": 200,\n\t\t\t\t\"ch\": \"auth\",\n\t\t\t\t\"data\": {}\n\t\t}`)\n\t\treturn\n\t})\n\n\tstub.SetErrorHandler(func(err error) {\n\t\tfmt.Println(\"huobi websocket error:\", err)\n\n\t\tif errors.Is(err, stubborn.ErrCritical) {\n\t\t\t// resubscribe\n\t\t\terr = stub.Send(stubborn.TextMessage, []byte(sub))\n\t\t\tif err != nil {\n\t\t\t\tfmt.Println(\"huobi websocket error:\", err)\n\t\t\t}\n\t\t}\n\t})\n\n\tstub.SetKeepAliveHandler(stubborn.KeepAlive{\n\t\tTick: time.After(1 * time.Hour), \n\t\tCustomPong: func(typ int, payload []byte) (int, []byte) {\n\t\t\tping := struct {\n\t\t\t\tAction string `json:\"action\"`\n\t\t\t\tData   *struct {\n\t\t\t\t\tTimestamp int64 `json:\"ts\"`\n\t\t\t\t} `json:\"data\"`\n\t\t\t}{}\n\t\t\terr := json.Unmarshal(payload, \u0026ping)\n\t\t\tif err != nil {\n\t\t\t\treturn 0, nil\n\t\t\t}\n\t\t\t\n\t\t\tpong := fmt.Sprintf(\"{\\\"action\\\": \\\"pong\\\", \\\"data\\\": { \\\"ts\\\": %d } }\", ping.Data.Timestamp)\n\t\t\treturn stubborn.TextMessage, []byte(pong)\n\t\t},\n\t})\n\n\tstub.SetMessageHandler(func(resp []byte) {\n\t\tfmt.Println(\"RESPONSE:\", string(resp))\n\t})\n\n\terr = stub.Connect(hc.ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// subscribe\n\terr = stub.Send(stubborn.TextMessage, []byte(sub))\n\tif err != nil {\n\t\treturn err\n\t}\n\t\u003c-interrupt\n\tdefer func() {\n\t\tstub.Send(stubborn.TextMessage, []byte(unsub))\n\t\tstub.Close()\n\t}\n\treturn nil\n}\n```\n* Okex\n```go\nfunc OkexOrdersSubscribe(key, secret, pass string) (err error) {\n\tinterrupt := make(chan os.Signal, 1)\n\tsignal.Notify(interrupt, syscall.SIGTERM, syscall.SIGINT)\n\t\n\tvar url  = \"wss://real.okex.com:8443/ws/v3?compress=true\"\n\t\n\tsubOp := BaseOp{\n\t\tOp:   \"subscribe\",\n\t\tArgs: []string{\"spot/order:ETH-USDT\"},\n\t}\n\n\tsubMsg, _ := json.Marshal(subOp)\n\n\tstub := stubborn.NewStubborn(stubborn.Config{\n\t\tURL:             url,\n\t\tIsReconnectable: true,\n\t\tMessageType:     stubborn.TextMessage,\n\t\tPrint: func(args ...interface{}) {\n\t\t\tfmt.Println(args)\n\t\t\treturn\n\t\t},\n\t\tDialerf: func(ctx context.Context) (stubborn.DuplexConnector, error) {\n\t\t\tconn, _, err := websocket.DefaultDialer.DialContext(\n\t\t\t\tctx,\n\t\t\t\turl,\n\t\t\t\tnil,\n\t\t\t)\n\n\t\t\treturn conn, err\n\t\t},\n\t\tAuthTimeOut:     5 * time.Second,\n\t\tUnimportantErrs: []error{io.EOF},\n\t})\n\n\tstub.SetAuthHandler(func() (req []byte, resp []byte, err error) {\n\t\tresp = []byte(`{\"event\":\"login\",\"success\":true}`)\n        \tet := epochTime()\n\t\tsigningString := et + http.MethodGet + \"/users/self/verify\"\n\t\tsigned, err := hmacSha256Base64Sign(signingString, secret)\n\t\tif err != nil {\n\t\t\treturn nil, nil, err\n\t\t}\n\n\t\tb := BaseOp{\n\t\t\tOp:   \"login\",\n\t\t\tArgs: []string{key, pass, et, signed},\n\t\t}\n\t\treq, err = json.Marshal(b)\n\t\treturn\n\t})\n\n\tstub.SetErrorHandler(func(err error) {\n\t\tfmt.Println(\"okex websocket error:\", err)\n\t\tif errors.Is(err, stubborn.ErrCritical) {\n\t\t\t// resubscribe\n\t\t\terr = stub.Send(stubborn.TextMessage, subMsg)\n\t\t\tif err != nil {\n\t\t\t\tfmt.Println(\"okex websocket error:\", err)\n\t\t\t}\n\t\t}\n\t})\n\n\tstub.SetKeepAliveHandler(stubborn.KeepAlive{\n\t\tTick: time.Tick(25 * time.Second),\n\t\tCustomPing: func() (msgType int, payload []byte) {\n\t\t\treturn stubborn.TextMessage, []byte(\"ping\")\n\t\t},\n\t})\n\n\tstub.SetMessageHandler(func(resp []byte) {\n\t\tfmt.Println(\"RESPONSE:\", string(resp))\n\t})\n\n\terr = stub.Connect(oc.ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// subscribe\n\terr = stub.Send(stubborn.TextMessage, subMsg)\n\tif err != nil {\n\t\treturn err\n\t}\n\t\u003c-interrupt\n\tdefer func() {\n\t\tunsubOp := BaseOp{\n\t\t\tOp:   \"unsubcribe\",\n\t\t\tArgs: args,\n\t\t}\n\t\tunsubMsg, _ := json.Marshal(unsubOp)\n\t\tstub.Send(stubborn.TextMessage, unsubMsg)\n\t\tstub.Close()\n\t}\n\treturn nil\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilinvadim%2Fstubborn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffilinvadim%2Fstubborn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilinvadim%2Fstubborn/lists"}