Go-on-rails is a Rails generator that has been published as a gem for integration or development of Golang applications within Rails projects.
Project address: github.com/goonr/go-on… .
This article won’t go into the details of how to use it, so here are a few existing sample tutorials:
- The simple example is modeled after the beginner demo in Rails Guides that shows how to create and generate the GO API for a simple blog using Go-on-Rails.
- Advanced tutorial on how to create a Golang project and integrate it with Rails_admin, Revises, Cancancan, and more to quickly add an administrative backend to Go projects. It also demonstrates how to use the new WebPacker tool in Rails 5.1 and use React to create a separate front-end interface that calls the Go interface in Rails.
- How to read a Rails session from a Go interface generated by Rails for user authentication
What does Go-on-Rails do
- You use Rails to create the Model, and then go on- Rails generates the corresponding GO data structure from the Model definition, along with some basic CRUD methods, add validation, and generate pagination methods
- Generate goDoc documents for the methods generated above
- Generate the database connection configuration from the Rails database configuration
- Command-line tools help automate common tasks such as installing default dependencies, files generated by format, viewing GOdoc documents, and so on
Why use Go-on-Rails
The tool is primarily targeted at Rails developers who want to learn about Golang or integrate the Go API into their Rails projects. Be familiar with Rails, otherwise many people might not learn Rails just to try out the tool.
Let’s focus on why there is a gem, or is there really any advantage to developing Go projects using Rails?
-
Configuration management. For example, by configuring the database in Rails, the generated Go project generates the connection configuration for the corresponding environment database based on the Rails configuration. Similarly, other configurations can be shared using Rails configurations.
-
Take advantage of Rails’ rich toolchain, such as writing test data with Rails DB :seed, testing data with the Rails Console, and Rails DB :* for the database management section.
-
It is convenient to manage various migrations of the database without using a handwritten schema, which continues the database operation habits of Rails programmers during development.
-
The definition of the Model also makes it easier for Rails developers to get used to the fact that go-on Rails generates most of the action functions in association and validation.
-
The release of WebPacker in Rails 5.1 highlights Rails’ new capabilities as a “Web integrated development environment.” With the advent of more separate systems at the front and back, integrating the Go API into Rails is much less repetitive, and it is possible to complete a system overhaul with just a few changes to the links called. In addition, webPacker makes it easy to create front-end pages to call the Go API. See the tutorial here to learn how to use it.
-
For some small – to medium-sized systems, you can improve the performance of some interfaces by integrating the Go API into Rails without refactoring the system architecture.
Go-on-rails is still in development and welcomes all kinds of participation and PR.