Complete End-to-End Code Blueprint
Below is a complete, standalone, runnable example showing how all components integrate:
package main
import (
"context"
"fmt"
"net/http"
"sync"
"time"
"github.com/golaravel/gofilament/pkg/activitylog"
"github.com/golaravel/gofilament/pkg/colors"
"github.com/golaravel/gofilament/pkg/filament"
"github.com/golaravel/gofilament/pkg/forms"
"github.com/golaravel/gofilament/pkg/support"
"github.com/golaravel/gofilament/pkg/tables"
"github.com/golaravel/gofilament/pkg/widgets"
"github.com/golaravel/golaravel/pkg/golaravel"
)
// 1. Data Model
type Device struct {
ID string `json:"id"`
Name string `json:"name"`
SerialNo string `json:"serial_no"`
Model string `json:"model"`
Location string `json:"location"`
Status string `json:"status"`
Battery int `json:"battery_level"`
IsActive bool `json:"is_active"`
DeletedAt *time.Time `json:"deleted_at"`
}
var (
deviceLock sync.RWMutex
devices = []*Device{
{ID: "1", Name: "Gateway Frankfurt 01", SerialNo: "SN-8821-X", Model: "EdgeCore-Pro", Location: "Frankfurt DC", Status: "online", Battery: 98, IsActive: true},
{ID: "2", Name: "Gateway Zurich 02", SerialNo: "SN-9942-Z", Model: "EdgeCore-Pro", Location: "Zurich Hub", Status: "online", Battery: 84, IsActive: true},
{ID: "3", Name: "Sensor Riyadh 01", SerialNo: "SN-1022-A", Model: "PulseSense", Location: "Riyadh Data Hub", Status: "maintenance", Battery: 45, IsActive: false},
}
)
// 2. Resource Definition
func buildDeviceResource() *filament.BaseResource[*Device] {
res := filament.NewResource[*Device]("devices")
res.ModelName("Device").
PluralModelName("Devices").
NavigationGroup("Fleet Management").
NavigationSort(1).
NavigationIcon(`<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z"/></svg>`).
RecordID(func(d *Device) string { return d.ID })
// Soft Deletes & Trash Recovery
res.SoftDeletes(true).
SoftDeleteColumn("deleted_at").
IsTrashed(func(d *Device) bool { return d.DeletedAt != nil })
// Form Schema
res.Form(func(f *forms.Form) *forms.Form {
return f.Schema(
forms.Section("Device Identity & Deployment").Schema(
forms.Grid(2).Schema(
forms.TextInput("name").Required().Label("Device Name"),
forms.TextInput("serial_no").Required().Label("Serial Number"),
forms.Select("model").Options(map[string]string{
"EdgeCore-Pro": "EdgeCore Pro Gateway",
"PulseSense": "PulseSense Telemetry Node",
}).Required(),
forms.TextInput("location").Required().Label("Data Center / Location"),
),
forms.Grid(2).Schema(
forms.Select("status").Options(map[string]string{
"online": "Online (Nominal)",
"offline": "Offline (Disconnected)",
"maintenance": "Under Maintenance",
}).Default("online"),
forms.Toggle("is_active").Label("Active Telemetry Ingestion").Default(true),
),
),
)
})
// Table Schema
res.Table(func(t *tables.Table[*Device]) *tables.Table[*Device] {
return t.
Columns(
tables.TextColumn[*Device]("name").Label("Device Name").Sortable().Searchable().Weight("bold"),
tables.TextColumn[*Device]("serial_no").Label("Serial").Sortable().Copyable(),
tables.BadgeColumn[*Device]("status").Label("Status").Colors(map[string]string{
"online": "success",
"maintenance": "warning",
"offline": "danger",
}),
tables.TextColumn[*Device]("location").Label("Location").Sortable(),
tables.ToggleColumn[*Device]("is_active").Label("Ingestion Active"),
).
Filters(
tables.SelectFilter[*Device]("status").Options(map[string]string{
"online": "Online Only",
"offline": "Offline Only",
"maintenance": "Maintenance Only",
}),
tables.TrashedFilter[*Device](),
).
Actions(
tables.ViewAction[*Device](),
tables.EditAction[*Device](),
tables.DeleteAction[*Device](),
tables.RestoreAction[*Device](),
tables.ForceDeleteAction[*Device](),
).
BulkActions(
tables.DeleteBulkAction[*Device](),
tables.RestoreBulkAction[*Device](),
tables.ForceDeleteBulkAction[*Device](),
)
})
// Handlers
res.OnList(func(ctx *filament.Context, search, sortCol, sortDir string, page, perPage int, filters map[string]string) ([]*Device, int, error) {
deviceLock.RLock()
defer deviceLock.RUnlock()
return devices, len(devices), nil
}).
OnFind(func(ctx *filament.Context, id string) (*Device, error) {
deviceLock.RLock()
defer deviceLock.RUnlock()
for _, d := range devices {
if d.ID == id {
return d, nil
}
}
return nil, fmt.Errorf("device not found")
}).
OnCellUpdate(func(ctx *filament.Context, id, column string, value any) error {
deviceLock.Lock()
defer deviceLock.Unlock()
for _, d := range devices {
if d.ID == id {
if column == "is_active" {
if b, ok := value.(bool); ok {
d.IsActive = b
}
}
return nil
}
}
return fmt.Errorf("device not found")
})
return res
}
// 3. Application Entrypoint
func main() {
app := golaravel.Default()
// Configure GoFilament Admin Panel
adminPanel := filament.NewPanel("admin").
Path("/admin").
BrandName("Pulse Fleet").
Version("v1.25.0").
BuildID("20261109-prod").
DarkMode(true).
SidebarCollapsibleOnDesktop().
MaxContentWidth(filament.Width7xl).
Colors(map[string]any{
colors.RolePrimary: colors.Amber,
colors.RoleGray: colors.Slate,
}).
// i18n & RTL Configuration
Locales("en", "ar", "es", "de").
DefaultLocale("en").
LocaleLabels(map[string]string{
"en": "English",
"ar": "العربية",
"es": "Español",
"de": "Deutsch",
}).
LocaleFlags(map[string]string{
"en": "🇺🇸",
"ar": "🇸🇦",
"es": "🇪🇸",
"de": "🇩🇪",
})
// Mount Device Resource with Automated Audit Trail
deviceRes := buildDeviceResource()
activitylog.EnableAuditLog(deviceRes)
adminPanel.Resource(deviceRes)
// Mount Activity Audit Resource
adminPanel.Resource(activitylog.NewActivityResource())
// Mount Live Chat & AI Support Concierge Resource (v1.25.0)
adminPanel.Resource(support.NewSupportResource())
// Mount Dashboard KPI & Trend Widgets
adminPanel.Widgets(
widgets.NewStatsOverviewWidget(func(ctx *filament.Context) []widgets.Stat {
return []widgets.Stat{
*widgets.NewStat("Connected Gateways", "2 Nodes").
Description("99.9% uptime").
Color("success").
Chart([]float64{1, 1, 2, 2, 2, 2}),
*widgets.NewStat("Telemetry Rate", "1.4k / sec").
Description("IoT live stream active").
Color("info"),
*widgets.NewStat("Active Alarms", "0").
Description("No sensor breaches").
Color("success"),
}
}),
)
// Register Panel with GoLaravel Router
if err := adminPanel.Register(app); err != nil {
panic(err)
}
fmt.Println("🚀 GoFilament v1.25.0 Control Center running at http://localhost:8080/admin")
app.Run(":8080")
}