{"id":13670079,"url":"https://github.com/chuan-yu/go-thrift-mock","last_synced_at":"2025-04-27T09:31:29.569Z","repository":{"id":217141752,"uuid":"336713364","full_name":"chuan-yu/go-thrift-mock","owner":"chuan-yu","description":"A thrift mock server written in Go","archived":false,"fork":false,"pushed_at":"2021-02-21T14:36:20.000Z","size":2357,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-08-03T09:07:03.937Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/chuan-yu.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,"publiccode":null,"codemeta":null}},"created_at":"2021-02-07T06:00:15.000Z","updated_at":"2023-08-14T12:41:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"e062f14e-9d39-4c2c-ae7b-0da32f79bcf1","html_url":"https://github.com/chuan-yu/go-thrift-mock","commit_stats":null,"previous_names":["chuan-yu/go-thrift-mock"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chuan-yu%2Fgo-thrift-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chuan-yu%2Fgo-thrift-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chuan-yu%2Fgo-thrift-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chuan-yu%2Fgo-thrift-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chuan-yu","download_url":"https://codeload.github.com/chuan-yu/go-thrift-mock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224067008,"owners_count":17250097,"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":[],"created_at":"2024-08-02T09:00:31.920Z","updated_at":"2024-11-11T07:31:06.236Z","avatar_url":"https://github.com/chuan-yu.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# GO-THRIFT-MOCK\n![Test](https://github.com/chuan-yu/go-thrift-mock/actions/workflows/ci.yml/badge.svg)\n\n`go-thrift-mock` is a thrift mock server written in `Go`. It can return any mock thrift response without a predefined IDL.\n\nThis project is inspired by [thrift-mock](https://github.com/didi/thrift-mock) project.\n\n## Intallation\n```\ngo get https://github.com/chuan-yu/go-thrift-mock\n```\n\n## Quick Start\n### Start a mock server instance\n```go\nserverAddr := \":8888\"\ns := server.MustNewMockServer(serverAddr)\n\ngo func() {\n    if err := s.Start(); err != nil {\n        fmt.Printf(\"failed to start server: %s\", err.Error())\n        return\n    }\n}()\n\n// wait for mock server to start properly\ntime.Sleep(1 * time.Second)\n```\n### Set expected return\n\nAssume you have an IDL below.\n```thrift\nstruct Request{\n    1:optional string msg,\n}\n\nstruct Response{\n    1:required i32 code,\n    2:required string responseMsg,\n}\n\nservice HelloService {\n    Response sayHello(1:required Request request);\n}\n```\n\nTo set the `sayHello` method to return a mock `Response` instance:\n```go\nresult := Response{\n    Code: 200,\n    ResponseMsg: \"mock message\",\n}\nexpectedReturn := server.ExpectedReturn{\n    Response: \u0026result,\n}\n\ns.SetExpectedReturn(\"sayHello\", expectedReturn)\n```\nNow when a client calls the server, the above mock response is returned.\n\nYou can also mock an error response:\n```go\nexpectedReturn = server.ExpectedReturn{\n    Err: errors.New(\"mock error\"),\n}\ns.SetExpectedReturn(\"sayHello\", expectedReturn)\n```\n### Stop the mock server\n```go\ns.Stop()\n```\n\n## Example Code\n\nSee `example/main.go` for a working example\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchuan-yu%2Fgo-thrift-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchuan-yu%2Fgo-thrift-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchuan-yu%2Fgo-thrift-mock/lists"}