v1.40.0
v1.40.0
🚀 Features
Support for Supabase Database
Users can now connect their GoFr services to a Supabase database using environment variables. This feature supports both direct and pooled connections, enabling secure and scalable Postgres usage via Supabase.
🔧 Environment Variable Setup:
DB_DIALECT=supabase
DB_HOST=db.[PROJECT_REF].supabase.co # Optional, derived from PROJECT_REF
DB_USER=postgres # Or database user name
DB_PASSWORD=password
DB_NAME=postgres # Or your database name
DB_PORT=5432 # Optional, defaults based on connection type
DB_SSL_MODE=require # Optional, forced to "require" for Supabase
# Supabase-specific configs
SUPABASE_PROJECT_REF=your_project_ref
SUPABASE_CONNECTION_TYPE=direct # Options: direct, session, transaction
SUPABASE_REGION=us-east-1 # Required for pooled connections
# Alternatively, can provide full connection string
DATABASE_URL=postgresql://postgres:password@db.your_project_ref.supabase.co:5432/postgres
Inter-Service WebSocket Communication
GoFr now supports Inter-Service WebSocket Communication, enabling services to exchange real-time messages over WebSocket connections. Ideal for microservices needing live updates or event-driven communication.
🔑 Key Methods:
-
AddWSService
: Register a persistent WebSocket connection to another service with optional auto-reconnect. -
WriteMessageToService
: Send messages to any registered service.
✅ Example Usage:
func main(){
app := gofr.New()
err := app.AddWSService("notification-service", "ws://notifications.example.com/ws", nil, true, 5*time.Second)
if err != nil {
app.Logger.Errorf("Failed to add WebSocket service: %v", err)
return
}
app.POST("/send-notification", func(ctx *gofr.Context) (any, error) {
message := map[string]string{
"title": "New Message",
"content": "You have a new notification!",
}
err := ctx.WriteMessageToService("notification-service", message)
if err != nil {
return nil, err
}
return "Notification sent successfully!", nil
})
app.Run()
}
This enables resilient, real-time service communication with minimal configuration.
🔧 Improvements
1. New HTTP Error Type: ServiceUnavailable
A new standardized error type ErrorServiceUnavailable
has been introduced for representing service unavailability due to dependency issues like database failures or third-party service outages.
⚙️ Use Case Example:
err := http.ErrorServiceUnavailable{
Dependency: "PostgreSQL",
ErrorMessage: "Connection timeout",
}
This improvement enhances observability and clarity when dealing with critical external failures.