Schema Classes
Schema classes define the column structure of your models. In Nimbus, your model struct is the schema — you define columns as struct fields with GORM tags for type, constraints, and JSON serialization.
Struct as schema
GORM infers column names from field names (snake_case by default). Use struct tags to override:
type User struct {
database.Model
Name string `gorm:"size:255"`
Email string `gorm:"uniqueIndex;not null"`
Password string `gorm:"-"` // ignore in DB
Role string `gorm:"default:user"`
}
Common GORM tags
| Tag | Description |
|---|---|
primaryKey | Primary key |
uniqueIndex | Unique constraint |
not null | NOT NULL |
default:value | Default value |
size:255 | Column size |
column:db_name | Override column name |
- | Ignore field |
JSON serialization
Use json:"-" to hide sensitive fields from JSON output:
Password string `json:"-"` // omit from JSON