README
ΒΆ
Gort Framework
A Rails-inspired web framework for Go, bringing developer happiness and convention over configuration to the Go ecosystem.
β‘ Try It Now (5 Minutes)
# Install Gort
go install github.com/AndrewNgKF/gort/cmd/gort@latest
# Create your first app
gort new myblog && cd myblog
# Setup everything
go mod tidy && gort db:setup
# Generate a blog scaffold
gort generate scaffold Post title:string body:text published:boolean
# Run migrations and start server
gort db:migrate && gort server
π Open http://localhost:3000 to see your app!
Installation
Option 1: Install Globally (Recommended)
Install Gort so you can use it from anywhere, just like Rails:
# Install from GitHub
go install github.com/AndrewNgKF/gort/cmd/gort@latest
# Or install from local source
cd go_rt_framework
go install ./cmd/gort
# Verify installation
gort version
# Now you can use 'gort' from any directory!
The gort command will be installed to $GOPATH/bin (usually ~/go/bin). Make sure this is in your PATH:
# Add to ~/.zshrc or ~/.bashrc if needed
export PATH=$PATH:$HOME/go/bin
Option 2: Development Mode
If you're working on the Gort framework itself:
cd go_rt_framework
go build -o bin/gort ./cmd/gort
# Use ./bin/gort for commands
Quick Start
# Create a new application
gort new myblog
cd myblog
# Install dependencies
go mod tidy
# Setup database (creates database and runs migrations)
gort db:setup
# Generate a complete CRUD scaffold
gort generate scaffold Post title:string body:text published:boolean
# Run new migrations
gort db:migrate
# Start the server
gort server
Visit http://localhost:3000 to see the welcome page, or http://localhost:3000/posts to see your scaffold!
Available Commands
Application Generation
gort new <app_name> # Create new application
Generators
gort generate model <name> [fields...] # Generate model + migration
gort generate controller <name> [actions...] # Generate controller
gort generate scaffold <name> [fields...] # Generate full CRUD resource
Supported Field Types:
| Type | SQL Type | Go Type | Use Case |
|---|---|---|---|
string |
VARCHAR(255) |
string |
Short text (names, emails, titles) |
text |
TEXT |
string |
Long text (descriptions, content) |
integer / int |
INTEGER |
int |
Numbers |
bigint / int64 |
BIGINT |
int64 |
Large numbers |
boolean / bool |
BOOLEAN |
bool |
True/false flags |
float / decimal |
DECIMAL(10,2) |
float64 |
Money, ratings, percentages |
datetime / timestamp |
TIMESTAMP |
time.Time |
Date and time |
date |
DATE |
time.Time |
Date only |
uuid |
UUID |
string |
Unique identifiers |
json |
JSON |
interface{} |
JSON data |
jsonb |
JSONB |
interface{} |
Binary JSON (faster, PostgreSQL) |
array |
TEXT[] |
[]string |
List of values |
Field Modifiers:
:unique- Add unique constraint:index- Add database index:nullable/:null- Allow NULL values:ref:ModelName- Foreign key reference
Examples:
# Basic types
gort generate model User name:string bio:text age:integer active:boolean
# Advanced types with modifiers
gort generate model Article title:string:unique slug:string:index body:text views:bigint rating:float published_at:datetime tags:array metadata:jsonb
# With relationships
gort generate model Comment body:text user_id:integer:ref:User post_id:integer:ref:Post
Database Commands
Both db:command (Rails style) and db command (Go style) syntaxes are supported!
# Database setup
gort db:create # Create the database
gort db:drop # Drop the database
gort db:setup # Create database and run migrations (recommended!)
# Migrations
gort db:migrate # Run pending migrations
gort db:rollback # Rollback last migration
gort db:reset # Reset database (rollback all + migrate)
# Schema
gort db:schema:dump # Update schema.go with current database structure
Server Command
gort server # Start the development server (default: port 3000)
gort server -p 8080 # Start server on custom port
gort s # Short alias
Other Commands
gort routes # Display all registered routes
gort version # Show version information
Project Structure
myapp/
βββ app/
β βββ controllers/ # Request handlers
β β βββ application_controller.go
β β βββ posts_controller.go
β βββ models/ # Data models
β β βββ post.go
β βββ views/ # HTML templates
β β βββ layouts/
β β β βββ application.html
β β βββ posts/
β β βββ index.html
β β βββ show.html
β β βββ new.html
β β βββ edit.html
β β βββ _form.html # Partial template
β βββ middleware/ # Custom middleware
βββ config/
β βββ application.go # App configuration
β βββ database.yml # Database settings
β βββ routes.go # Route definitions
β βββ environments/ # Environment-specific config
βββ db/
β βββ migrations/ # Database migrations
β βββ schema.go # Current database schema
β βββ seeds.go # Seed data
βββ public/
β βββ assets/ # Static files (CSS, JS, images)
βββ test/ # Test files
βββ main.go # Application entry point
Documentation
See SPEC.md for the complete specification and ROADMAP.md for development progress.
Features
β
CLI Generators - Scaffold models, controllers, and full CRUD resources
β
RESTful Routing - Rails-like routing DSL with Resources()
β
Database ORM - CRUD operations with automatic timestamps
β
Migration System - Version-controlled database schema changes
β
Template Engine - Layouts and partials with html/template
β
Method Override - PUT/DELETE support via _method parameter
β
Multi-Database - PostgreSQL, MySQL, and SQLite support
β
Rich Data Types - Support for string, text, integer, bigint, boolean, float, datetime, date, uuid, json, jsonb, array
β
Dev Server - Built-in gort server command with hot reload support
β
Rails-style Commands - Both db:migrate and db migrate syntaxes supported
β
Beautiful Welcome Page - Minimal, Rails-inspired landing page with community globe illustration
Example: Creating a Blog in 5 Commands
# 1. Create application
gort new blog
cd blog
# 2. Install dependencies
go mod tidy
# 3. Setup database (creates DB and runs migrations)
gort db:setup
# 4. Generate Post scaffold with rich field types
gort generate scaffold Post title:string body:text author:string:unique published:boolean views:integer rating:float published_at:datetime tags:array
# 5. Run new migrations and start server
gort db:migrate
gort server
Now visit:
- http://localhost:3000 - Beautiful welcome page with Rails-style globe
- http://localhost:3000/posts - Full CRUD application with:
- List all posts (Index)
- Create new posts (New/Create)
- View individual posts (Show)
- Edit posts (Edit/Update)
- Delete posts (Destroy)
Development Workflow
Working on the Gort Framework Itself
If you're developing the Gort framework and want to test changes:
- Make changes to Gort framework code
- Rebuild Gort:
go build -o bin/gort ./cmd/gort - In your test app, add a replace directive:
# In your app directory (e.g., blog/) echo "" >> go.mod echo "replace gort => ../path/to/go_rt_framework" >> go.mod - Use the local version:
../bin/gort generate scaffold ...
This is similar to using gem 'rails', path: '../rails' in a Gemfile for Rails development.
Using Published/Installed Gort
Once installed globally with go install, just use:
gort new myapp # No ./ or ../bin/ prefix needed!
cd myapp
gort generate scaffold Post title:string body:text
gort db migrate
Database Configuration
Edit config/database.yml:
development:
adapter: postgresql
database: myapp_development
host: localhost
port: 5432
username: your_username
password: your_password
sslmode: disable
production:
adapter: postgresql
database: myapp_production
# ... production settings
Routing Example
In config/routes.go:
func Routes() *gort.Router {
r := gort.NewRouter()
// Middleware
r.Use(gort.Logger())
r.Use(gort.Recovery())
// Root route
r.Root(controllers.HomeIndex)
// RESTful resources (generates 7 routes)
r.Resources("posts", &controllers.PostController{})
// Custom routes
r.Get("/about", controllers.AboutPage)
return r
}
Model Example
type Post struct {
ID int64 `db:"id"`
Title string `db:"title"`
Body string `db:"body"`
Published bool `db:"published"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
func (Post) TableName() string {
return "posts"
}
Controller Example
func (c *PostController) Index(w http.ResponseWriter, r *http.Request) {
var posts []models.Post
if err := gort.FindAll("posts", &posts); err != nil {
c.InternalServerError(w, err.Error())
return
}
c.Render(w, r, "posts/index", map[string]interface{}{
"posts": posts,
})
}
License
MIT