Compile natural language API descriptions into idiomatic, high-performance Go backend services with routing, models, and database integration.
| File | Purpose |
|---|---|
| main.go | Server setup, router initialization, middleware |
| models/user.go | Go struct with JSON tags for each model |
| handlers/user.go | HTTP handler functions for each route |
| database/db.go | Database connection and auto-migration |
| middleware/auth.go | Bearer token authentication middleware |
| go.mod | Module definition and dependency declarations |
| English Type | Go Type |
|---|---|
| "string", "text" | string |
| "number", "integer" | int |
| "float", "decimal" | float64 |
| "boolean" | bool |
| "date", "time" | time.Time |
| "id", "uuid" | string |
The engine supports PostgreSQL, MySQL, and SQLite via GORM. When a database is specified, the generator creates a database/db.go file with connection logic and AutoMigrate calls, and updates all handler functions to use db.Find, db.Create, db.Save, and db.Delete.
| Field | Type | Value / Default | Modifier |
|---|---|---|---|
| ID | int | auto-increment | json:"id" |
| Name | string | required | json:"name" |
| string | required | json:"email" | |
| GET /users | route | list all | no auth |
| POST /users | route | create | no auth |
| GET /users/{id} | route | get by id | no auth |
// models/user.go
package models
type User struct {
ID int `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
}
// handlers/user.go
package handlers
import (
"encoding/json"
"net/http"
"strconv"
"github.com/gorilla/mux"
)
var users []models.User
var nextID = 1
func GetUsers(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(users)
}
func CreateUser(w http.ResponseWriter, r *http.Request) {
var u models.User
json.NewDecoder(r.Body).Decode(&u)
u.ID = nextID; nextID++
users = append(users, u)
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(u)
}
func GetUser(w http.ResponseWriter, r *http.Request) {
id, _ := strconv.Atoi(mux.Vars(r)["id"])
for _, u := range users {
if u.ID == id {
json.NewEncoder(w).Encode(u)
return
}
}
http.NotFound(w, r)
}
// main.go
package main
import (
"log"
"net/http"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
r.HandleFunc("/users", handlers.GetUsers).Methods("GET")
r.HandleFunc("/users", handlers.CreateUser).Methods("POST")
r.HandleFunc("/users/{id}", handlers.GetUser).Methods("GET")
log.Fatal(http.ListenAndServe(":8080", r))
}