{"id":13394084,"url":"https://github.com/railstack/go-on-rails","last_synced_at":"2025-10-07T03:30:43.895Z","repository":{"id":46759491,"uuid":"87204884","full_name":"railstack/go-on-rails","owner":"railstack","description":":bullettrain_side: Use Rails to Develop or Generate a Golang Application.","archived":true,"fork":false,"pushed_at":"2021-10-12T18:05:46.000Z","size":1334,"stargazers_count":289,"open_issues_count":4,"forks_count":17,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-09-21T00:46:55.157Z","etag":null,"topics":["code-generator","crud","crud-api","generator","golang","golang-crud","rails","rails-generators","restful-generator","ruby","transpiler"],"latest_commit_sha":null,"homepage":"","language":"HTML","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/railstack.png","metadata":{"files":{"readme":"README.md","changelog":"changelogs/README.md","contributing":null,"funding":".github/FUNDING.yml","license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":"go-on-rails","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2017-04-04T15:39:44.000Z","updated_at":"2024-12-10T09:30:18.000Z","dependencies_parsed_at":"2022-09-22T14:24:38.853Z","dependency_job_id":null,"html_url":"https://github.com/railstack/go-on-rails","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/railstack/go-on-rails","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railstack%2Fgo-on-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railstack%2Fgo-on-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railstack%2Fgo-on-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railstack%2Fgo-on-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/railstack","download_url":"https://codeload.github.com/railstack/go-on-rails/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railstack%2Fgo-on-rails/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278715508,"owners_count":26033296,"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-10-07T02:00:06.786Z","response_time":59,"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":["code-generator","crud","crud-api","generator","golang","golang-crud","rails","rails-generators","restful-generator","ruby","transpiler"],"created_at":"2024-07-30T17:01:08.422Z","updated_at":"2025-10-07T03:30:43.471Z","avatar_url":"https://github.com/railstack.png","language":"HTML","funding_links":["https://opencollective.com/go-on-rails"],"categories":["HTML","List"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg width=\"260\" height=\"260\" src=\"./go-on-rails.png\"\u003e\n\u003c/p\u003e\n\u003ch3 align=\"center\"\u003e\u003ca href=\"https://railstack.github.io\"\u003eGo on Rails\u003c/a\u003e\u003c/h3\u003e\n\u003cp align=\"center\"\u003eUse Rails to generate Golang code or manage Go app development\u003cp\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://badge.fury.io/rb/go-on-rails\"\u003e\u003cimg src=\"https://badge.fury.io/rb/go-on-rails.svg\" alt=\"Gem Version\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://travis-ci.org/railstack/go-on-rails\"\u003e\u003cimg src=\"https://travis-ci.org/railstack/go-on-rails.svg?branch=dev\" alt=\"Build Status\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://codeclimate.com/github/railstack/go-on-rails/maintainability\"\u003e\u003cimg src=\"https://api.codeclimate.com/v1/badges/6fba1f226f027a14c19b/maintainability\" alt=\"Maintainability\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/railstack/go-on-rails/blob/master/MIT-LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg\" alt=\"MIT License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n[用 Rails 开发 Go 应用：中文文档](./README_zh.md)\n\n`go-on-rails` is a Rails generator aims to:\n\n1. Help to develop and integrate some APIs written in Golang to existing Rails app for high performance\n2. Use your familiar Rails tools to develop and manage a Golang app project\n3. Convert a *not very complicated* Rails app to Golang equivalent\n\nHere's some examples:\n* A simple [example(tutorial)](https://github.com/railstack/example_simple) on the basic usage of go-on-rails generator\n* [An advanced example](https://github.com/railstack/example_with_admin) shows how to integrate Go APIs in a Rails project\n* [Another example](https://github.com/railstack/example_read_rails_session) shows how to handle a Rails session to get a user's info in a go-on-rails generated Go API\n\n## Prerequisites\n\n* Rails 4.2+ (Rails 6 not supported and need your help)\n* Golang 1.10.x(mainly be compatible with github.com/go-sql-driver/mysql)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'go-on-rails', '~\u003e 0.4.0'\n```\n\nAnd then execute:\n```bash\n$ bundle\n```\n\nOr install it yourself as:\n```bash\n$ gem install go-on-rails\n```\n## Usage\n\nYou must have an existing Rails app or to create a new one before you try go-on-rails to generate Golang codes.\n\nAfter that you can run the command just as other Rails generators:\n\n```bash\nrails g gor [dev(elopment) | pro(duction) | test | ...] [-m model_a model_b model_c ...]\n\n# OR (on rails version \u003c 5.0)\nrake g gor ...\n```\n\nhere we take generating all models for the `development` environment for example:\n\n```bash\nrails g gor dev\n```\n\nThen a folder named `go_app` that includes Golang codes will be generated under your Rails app root path.\n\nInstall the dependent Golang packages for this Go project:\n\n```bash\nrails gor:deps\n```\n\nThen change to the `go_app` directory and run:\n\n```bash\ngo run main.go\n```\n\nYou can visit the page in http://localhost:4000 by default.\n\nMore command details about go-on-rails generator:\n\n```bash\nrails g gor --help\n```\n\n## What will be generated?\n\n* Go project directory layout (all under the `go_app` directory, like `views`, `controllers`, `public`)\n* A Go data struct corresponding to each activerecord model\n* And each struct related CRUD functions/methods like FindModel, UpdateModel, DestroyModel etc. All these models related program files under the `go_app/models` directory\n* And godoc files for all the functions under `go_app/models/doc`\n* We use [Gin](https://github.com/gin-gonic/gin) as the default web framework, but you can change it to anyone that you favor in `main.go` and `controllers` programs\n\n### View the godoc of all functions\n\nYou can view the godoc page of all functions in http://localhost:7979/doc/models.html after run:\n\n```bash\nrails gor:doc\n```\n\nBesides, there's [a sample project](https://github.com/railstack/gor_models_sample) generated by go-on-rails, you can view its [godoc](https://godoc.org/github.com/railstack/gor_models_sample) at godoc.org just now to get a picture of what functions are generated.\n\n\n## Known issues and TODOs\n\nThe gem is still under development, so there're some known issues. You're welcomed to [contribute](#contributing). 👏\n\n* databases specific functions between MySQL and Postgres or other databases are not covered completely\n* sql.NullType not supported yet, so you'd better in the migrations set those columns \"not null\" with a default value that's consistent with Golang's zero value specification, such as \"\" default for string and text typed column, and 0 default for int, etc. And now we have an alternative approach for manipulating the database nullable fields, see the wiki [Working with database nullable fields](https://github.com/railstack/go-on-rails/wiki/Working-with-database-nullable-fields)\n\n- [x] Associations\n  - [x] has_many\n  - [x] has_one\n  - [x] belongs_to\n  - [x] dependent\n- [x] Validations\n  - [x] length\n  - [x] presence\n  - [x] format(string only)\n  - [x] numericality(partially)\n  - [ ] other validations\n- [x] Pagination(details see [wiki](https://github.com/railstack/go-on-rails/wiki/Pagination))\n- [ ] Callbacks\n- [ ] Transactions\n\n## Supported databases\n\n* SQLite\n* MySQL\n* Postgres\n\n## Wiki\n\n* [Built-in Pagination](https://github.com/railstack/go-on-rails/wiki/Pagination)\n* [Working with database nullable fields](https://github.com/railstack/go-on-rails/wiki/Working-with-database-nullable-fields)\n* [Some Make commands](https://github.com/railstack/go-on-rails/wiki/Some-Make-commands)\n* [Dockerize a Go-on-Rails application](https://github.com/railstack/go-on-rails/wiki/Dockerize-a-Go-on-Rails-application)\n\n## Golang dependencies by default\n\n* [github.com/jmoiron/sqlx](https://github.com/jmoiron/sqlx): an extension on the standard `database/sql` database API library\n* [github.com/railstack/go-sqlite3](https://github.com/railstack/go-sqlite3): a SQLite driver(This's a forked version of [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3), and This is [why we use this forked version](https://github.com/mattn/go-sqlite3/pull/468))\n* [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql): a MySQL driver\n* [github.com/lib/pq](https://github.com/lib/pq): a PostgreSQL driver\n* [github.com/asaskevich/govalidator](https://github.com/asaskevich/govalidator): for the struct validation\n* [github.com/gin-gonic/gin](https://github.com/gin-gonic/gin): a HTTP web framework\n\n## Acknowledgement\n\nWhen I had the idea to convert Rails app or build Golang app with Rails tools, I searched github and found the project: https://github.com/t-k/ar2gostruct. And from ar2gostruct I copied some codes on handling data structure conversion and models association, it made my idea come true faster than I imagined.\n\n## Contributing\n\nThere're two branches at present: `master` and `dev`.\n\nThe `dev` branch has a whole Rails environment for development: models, seeds for testing, and under `go_app` directory there's a file named `models_test.go` used to test generated Golang codes.\n\n- Fork the project switch to branch `dev`.\n- Make your feature addition or bug fix.\n- Add tests for it. This is important so I don't break it in a future version unintentionally.\n- Commit, do not mess with Rakefile or version (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)\n- Send me a pull request. Bonus points for topic branches.\n\n### Testing\n\nWe create four models for testing:\n\n- Physician\n- Patient\n- Appointment\n- Picture\n\nRun `rails db:seed` to use the data defined in `db/seeds.rb`. And change to `go_app/models` directory to run `go test` to test generated models-related functions. The test covers a small part of the functions currently. More will be added later on.\n\n## License\n\nSee the [LICENSE](https://github.com/railstack/go-on-rails/blob/master/MIT-LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frailstack%2Fgo-on-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frailstack%2Fgo-on-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frailstack%2Fgo-on-rails/lists"}