From PHP to Go + AI: Building an Admin Model and Hot-Reload in a GORM-Powered Project
This series shows a real-world workflow where a non-Go developer uses AI tools to produce production-quality Go code. The security warning about AI installing counterfeit dependencies is a practical alert for any developer using AI assistants in their build pipeline.
In the latest installment of a series documenting a PHP full-stack engineer's transition to Go with AI assistance, the focus is on two concrete tasks: designing an admin database model using GORM, and configuring Air for hot-reload in development.
The admin model is built without embedding gorm.Model — all fields are defined explicitly to control ordering and add Chinese comments. The Register function is refactored to accept variadic parameters, allowing multiple models to be registered in a single call. The author emphasizes that AI-generated model designs should be manually reviewed and fine-tuned, and that varchar lengths are chosen for readability rather than strict technical reasons.
For hot-reload, Air is installed via go install (not as a project dependency) and configured with a .air.toml file. The author includes a notable security warning: always provide official repository links when asking AI to install dependencies, to prevent the AI from being tricked into installing counterfeit packages that could contain malware.
Using AI to generate model code is efficient, but manual review of field types, comments, and tags is still essential for production quality.
The decision to avoid enum types for the Status field — using a string instead — gives developers flexibility to add custom statuses without schema changes.
The security practice of pinning official dependency URLs in AI prompts is a low-effort, high-impact safeguard that many developers overlook.
Hot-reload tools like Air are not built into Go's standard library, making third-party setup a necessary step for efficient Go development workflows.