{"id":13574571,"url":"https://github.com/tompston/gomarvin","last_synced_at":"2025-04-14T22:12:07.757Z","repository":{"id":43404552,"uuid":"477420889","full_name":"tompston/gomarvin","owner":"tompston","description":"Generate Go REST servers \u0026 http clients","archived":false,"fork":false,"pushed_at":"2023-09-14T18:19:59.000Z","size":398,"stargazers_count":57,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T10:11:41.540Z","etag":null,"topics":["api","boilerpate","codegen","echo","gin","gin-gonic","go","gofiber","golang","rest","rest-api","typescript"],"latest_commit_sha":null,"homepage":"https://gomarvin.pages.dev","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/tompston.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2022-04-03T17:51:52.000Z","updated_at":"2025-02-22T20:27:01.000Z","dependencies_parsed_at":"2024-06-19T03:03:58.268Z","dependency_job_id":"fb1fc6c0-e90a-44e1-ad9f-cfbc423a795c","html_url":"https://github.com/tompston/gomarvin","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompston%2Fgomarvin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompston%2Fgomarvin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompston%2Fgomarvin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompston%2Fgomarvin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tompston","download_url":"https://codeload.github.com/tompston/gomarvin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248968916,"owners_count":21191162,"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","boilerpate","codegen","echo","gin","gin-gonic","go","gofiber","golang","rest","rest-api","typescript"],"created_at":"2024-08-01T15:00:52.720Z","updated_at":"2025-04-14T22:12:07.736Z","avatar_url":"https://github.com/tompston.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"\u003ch4 align=\"center\"\u003e\n\u003cimg src=\"./assets/gomarvin.svg\" height=\"70\"\u003e\n\n\u003ch2 align=\"center\"\u003eGenerate boilerplate for Gin / Fiber / Echo / Chi REST servers.\u003c/h2\u003e\n\n\u003cdiv align=\"center\"\u003e \u003cem\u003eAKA Why spend 5 minutes doing it when I can spend 3 months automating it?\u003c/em\u003e \u003c/div\u003e\n\n\u003cbr/\u003e\n\nhttps://user-images.githubusercontent.com/82293948/197339991-ca049896-7a0e-4fa9-ae2b-787f0bb021b2.mp4\n\nGenerate:\n\n- Init server + controllers for endpoints\n- Typescript fetch functions with type-checked payloads for generated endpoints\n- SQL files with tables and queries for controllers ( Postgres )\n\nfrom one config file.\n\n### Disclaimer!\n\nI'm still figuring out how to do stuff better, so if there's a new release where the `y` in `x.y.z` the version ( tag ) is incremented, that means that there are breaking changes. The current versions work, but there's a lot of improvements that can be done to make stuff better.\n\n## [Documentation](https://gomarvin.pages.dev/docs)\n\n## Install\n\n1.  Either create a custom config file [with the frontend editor](https://gomarvin.pages.dev/) or copy one of the config file from [examples dir](https://github.com/tompston/gomarvin/tree/main/examples)\n\n2.  Install gomarvin\n\n```bash\n# install the binary\ngo install github.com/tompston/gomarvin@latest\n# or clone the repo and run go run main.go\ngit clone https://github.com/tompston/gomarvin.git\n```\n\n3. run gomarvin\n\n```bash\n# run this in the same dir as the config file, if the name of the config is \"gomarvin.json\"\ngomarvin generate\n\n# run this if custom config file name or path\ngomarvin -config=\"PATH_TO_CONFIG\" generate\n\n# optionally generate the golang struct -\u003e typescript interface converters\ngomarvin -gut=true generate\n```\n\n4. run lower commands\n\n```bash\ncd GENERATED_SERVER\ngo mod tidy\ngo mod download\ngo run cmd/api/main.go\n```\n\n## CLI\n\n```\nFlags:\n  -config\t\tSpecify path to the gomarvin config file (default \"gomarvin.json\")\n  -dangerous-regen\tRegenerate everything. If set to true, init server will be regenerated and all previous changes will be lost (default \"false\")\n  -gut            generate additional file in the modules dir which concats all of the functions that convert possible response structs to typescript interfaces\n```\n\n### Generated Typescript fetch functions usage example\n\n```js\n// import the generated file\nimport * as gomarvin from \"../../../chi_with_modules/public/gomarvin\";\n// or just import a single fetch function\nimport { GetUserById } from \"../../../chi_with_modules/public/gomarvin\";\n\n// either use the default client created from\n// the settings of the config file, or create a new one\n// (useful when switching environments)\nconst defaultClient = gomarvin.defaultClient;\n\n// api client when deployed\nconst productionClient: gomarvin.Client = {\n  host_url: \"http://example.com\",\n  api_prefix: \"/api/v1\",\n  headers: {\n    \"Content-type\": \"application/json;charset=UTF-8\",\n  },\n};\n\nconst DEV_MODE = true;\n\n// switch to productionClient if DEV_MODE is false\nconst client = DEV_MODE ? defaultClient : productionClient;\n\n// fetch GetUserById endpoint\nasync function FetchGetUsersById() {\n  const res = await gomarvin.GetUserById(client, 10);\n  console.log(res);\n}\n\n// append optional string to the existing endpoint url\nasync function FetchEndpointWithAppendedUrl() {\n  const res = await gomarvin.GetUserById(client, 10, {\n    append_url: \"?name=jim\",\n  });\n  console.log(res);\n}\n\n// define custom options for the fetch request\nasync function FetchEndpointWithCustomOptions() {\n  const res = await gomarvin.GetUserById(client, 10, {\n    options: { method: \"POST\" },\n  });\n  console.log(res);\n}\n\n// Use both optional values\n// - append a string to the fetch url\n// - define a new options object used in the fetch request\nasync function FetchWithAppendedUrlAndCustomOptions() {\n  const res = await gomarvin.GetUserById(client, 10, {\n    options: { method: \"DELETE\" },\n    append_url: \"?name=jim\",\n  });\n  console.log(res);\n}\n```\n\n### Generated Python fetch functions usage example\n\n```python\nimport gomarvin as gomarvin\n\n# use the default localhost client\nclient = gomarvin.defaultClient\n\n# fetch get users by id endpoint\ndef get_users_by_id():\n  res = gomarvin.UserEndpoints(client).GetUserById(1)\n  print(res.json())\n\n# make a post request to the register user endpoint with a body\ndef register_user():\n  body = gomarvin.CreateUserBody(\n        username=\"jim\", password=\"very-long-password\", email=\"jim@email.com\")\n  res = gomarvin.UserEndpoints(client).CreateUser(body=body)\n  print(res.json())\n\n# append a string to the url\ndef get_users_with_params():\n  data = gomarvin.UserEndpoints(client).GetUsers(append_url=\"?name=jim\") \n  print(res.json())\n\n```\n\n### Notes\n\n- Gin crashes by default. This is due to the way the framework handles routing.\n\n- bugs caused by url params and routing should be fixed manually.\n\n- Seeding the db\n  - As the generated fetch functions are mapped to the endpoints, you can use them to seed the database pretty easily. Using deno with the faker package can make the process trivial.\n- If formatting does not work for some reason, run this\n\n  ```\n  gofmt -s -w .\n  ```\n\n- Using the tool to generate fetch functions for pre-existing REST APIs\n\n  - If you want to generate a client for an already existing REST API in a fast way, you can use the editor to document the needed values to codegen the fetch functions in a fast way\n\n- If there are errors after creating a new config file, submit an issue. There might be some edge cases that have not been tested yet.\n\n### Credits to used packages\n\n_Not installed locally to avoid any dependencies._\n\n- [go-pluralize](https://github.com/gertd/go-pluralize)\n- [strcase](https://github.com/iancoleman/strcase)\n\n\u003c!--\n\n# run a local example\nGOOS=darwin GOARCH=arm64 go build -o gomarvin main.go\n\n# release\ngit add .\ngit commit -m \"gomarvin: release v0.10.1\"\ngit tag v0.10.1\ngit push origin v0.10.1\nGOPROXY=proxy.golang.org go list -m github.com/tompston/gomarvin@v0.10.1\n\n// qwqwe qwe\n\n# create a new branch\ngit branch BRANCH_NAME\n# switch to branch\ngit checkout BRANCH_NAME\n\n# merge new branch to main branch\ngit checkout main\ngit merge v0.8.x\n\ngo run cmd/api/main.go\n\nqweqwe qwe \n--\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftompston%2Fgomarvin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftompston%2Fgomarvin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftompston%2Fgomarvin/lists"}