Skip to content

Releases: gofr-dev/gofr

v1.34.0

18 Feb 14:30
50dd67e
Compare
Choose a tag to compare

Release - v1.34.0

🚀 New Features

1. NATS-KV Store Support

GoFr now supports NATS-KV Store as a datastore. The supported methods include:

type KVStore interface {
    Get(ctx context.Context, key string) (string, error)
    Set(ctx context.Context, key, value string) error
    Delete(ctx context.Context, key string) error
    HealthCheck(ctx context.Context) (any, error)
}

To integrate NATSKV Store as a datastore, add the following configuration:

app.AddKVStore(nats.New(nats.Configs{
        Server: "nats://localhost:4222",
        Bucket: "persons",
    }))

Refer to the documentation for more details.

2. ArangoDB Migrations

Added migration support for ArangoDB, allowing users to perform schema changes seamlessly. The following methods are now available in migration:

// CreateDB creates a new database in ArangoDB.
CreateDB(ctx context.Context, database string) error

// DropDB deletes an existing database in ArangoDB.
DropDB(ctx context.Context, database string) error

// CreateCollection creates a new collection in a database.
CreateCollection(ctx context.Context, database, collection string, isEdge bool) error

// DropCollection deletes an existing collection from a database.
DropCollection(ctx context.Context, database, collection string) error

// CreateGraph creates a new graph in a database.
//
// Parameters:
//   - ctx: Request context for tracing and cancellation.
//   - database: Name of the database where the graph will be created.
//   - graph: Name of the graph to be created.
//   - edgeDefinitions: Pointer to EdgeDefinition struct containing edge definitions.
//
// Returns an error if edgeDefinitions is not of type *EdgeDefinition or is nil.
CreateGraph(ctx context.Context, database, graph string, edgeDefinitions any) error

// DropGraph deletes an existing graph from a database.
DropGraph(ctx context.Context, database, graph string) error

🛠 Fixes & Improvements

1. Automatic PubSub Reconnection

Fixed automatic retries and reconnection in PubSub. It now reconnects immediately upon connection availability.

2. Added go.work

Simplifies dependency handling and development with better multi-module management.

3. Telemetry for Active GoFr Servers

GoFr now includes telemetry to track the number of running GoFr servers, helping us understand adoption and usage trends.

To disable telemetry, set:

GOFR_TELEMETRY=false

v1.33.0

06 Feb 06:37
d6cd85a
Compare
Choose a tag to compare

Release v1.33.0

🚀 Features

1. ArangoDB Support as a Datasource

Users can now integrate ArangoDB as a datasource within their GoFr applications. Supported Methods include :

type ArangoDB interface {
    // CreateDocument creates a new document in the specified collection.
	CreateDocument(ctx context.Context, dbName, collectionName string, document any) (string, error)
	// GetDocument retrieves a document by its ID from the specified collection.
	GetDocument(ctx context.Context, dbName, collectionName, documentID string, result any) error
	// UpdateDocument updates an existing document in the specified collection.
	UpdateDocument(ctx context.Context, dbName, collectionName, documentID string, document any) error
	// DeleteDocument deletes a document by its ID from the specified collection.
	DeleteDocument(ctx context.Context, dbName, collectionName, documentID string) error
	// GetEdges retrieves all the edge documents connected to a specific vertex in an ArangoDB graph.
	GetEdges(ctx context.Context, dbName, graphName, edgeCollection, vertexID string, resp any) error
	// Query executes an AQL query and binds the results
	Query(ctx context.Context, dbName string, query string, bindVars map[string]any, result any) error
    HealthCheck(context.Context) (any, error)
}

Refer to our official documentation to know more.

2. Default HealthCheck Support for gRPC Servers and Clients

This release introduces built-in HealthCheck support for both gRPC servers and clients.

  • Prerequisites:
    To use the new health check features, ensure that gofr-cli v0.5.0 is installed. Use it to generate your gRPC client and server templates.

  • gRPC Servers
    After running the existing command:

      gofr wrap grpc server -proto=path/to/your/proto/file
    

    A new file named health_gofr.go will be generated. This file contains the health functionality for your gRPC server. The health methods are embedded within the GoFr gRPC server struct, which looks like this:

     type {serviceName}GoFrServer struct {
         health *healthServer
     }

    Supported HealthCheck Methods:

     // Check checks if the service is healthy.
     func (h *healthServer) Check(ctx *gofr.Context, req *grpc_health_v1.HealthCheckRequest) (*grpc_health_v1.HealthCheckResponse, error)
     // Watch watches for any changes in the service’s health status.
     func (h *healthServer) Watch(ctx *gofr.Context, in *grpc_health_v1.HealthCheckRequest, stream grpc_health_v1.Health_WatchServer) error
     // SetServingStatus allows you to set the health status of the service (healthy, unhealthy, etc.).
     func (h *healthServer) SetServingStatus(ctx *gofr.Context, service string, status grpc_health_v1.HealthCheckResponse_ServingStatus)
     // Shutdown gracefully shuts down the service.
     func (h *healthServer) Shutdown(ctx *gofr.Context)
     // Resume resumes the service after it has been shut down.
     func (h *healthServer) Resume(ctx *gofr.Context)

    To integrate these health features, register your gRPC server in main.go as follows:

     func main() {
         app := gofr.New()
    
         packageName.Register{serviceName}ServerWithGofr(app, &{packageName}.New{serviceName}GoFrServer())
    
         app.Run()
     }
  • For gRPC Clients
    HealthCheck calls are now supported on all gRPC clients generated through the gofr-cli command i.e :

     gofr wrap grpc client -proto=path/to/your/proto/file
    

    Supported HealthCheck methods include :

     // Check checks the service health.
     func (c *{serviceName}GoFrClient) Check(ctx *gofr.Context, in *grpc_health_v1.HealthCheckRequest) (*grpc_health_v1.HealthCheckResponse, error)
     // Watch allows the client to watch for health status changes.
     func (c *{serviceName}GoFrClient) Watch(ctx *gofr.Context, in *grpc_health_v1.HealthCheckRequest) (grpc.ServerStreamingClient[grpc_health_v1.HealthCheckResponse], error)

For a deeper understanding, check out our official documentation and refer to our example repo.

🛠️ Fix

Resolved an issue with the AddRESTHandlers support where PUT requests were not updating records in the database when we have autoincrement tag added in our entity struct. The issue has now been fixed.

v1.32.0

27 Jan 08:59
aae7488
Compare
Choose a tag to compare

Release v1.32.0

🚀 Features :

1. Support for SurrealDB as a Data Source
SurrealDB is now supported as a data source in GoFr. The following methods are supported:

type SurrealDB interface  {
	Query(ctx context.Context, query string, vars map[string]any) ([]any, error)
	Create(ctx context.Context, table string, data any) (map[string]any, error)
	Update(ctx context.Context, table string, id string, data any) (any, error)
	Delete(ctx context.Context, table string, id string) (any, error)
	Select(ctx context.Context, table string) ([]map[string]any, error)
	HealthCheck(context.Context) (any, error)
}

To integrate SurrealDB into your application, use the AddSurrealDB method in your main.go :

client := surrealdb.New(&surrealdb.Config{
    Host:       "localhost",
    Port:       8000,
    Username:   "root",
    Password:   "root",
    Namespace:  "test_namespace",
    Database:   "test_database",
    TLSEnabled: false,
})

app.AddSurrealDB(client)

For more details, refer to our official documentation.

2. Built-in Metrics for gRPC Services

GoFr now includes in-built metrics for all gRPC server executions and interservice gRPC calls. We automatically capture metrics to measure the response time of gRPC server/clients.

  • Prerequisites : gofr-cli version v0.4.0 must be installed.
  • Use the following commands :
    • gofr wrap grpc server --proto=<path/to/proto/file> to generate GoFr's gRPC handlers.
    • gofr wrap grpc client -proto=<path/to/proto/file> to generate GoFr's gRPC client.
  • Refer the official documentation & examples to set up gRPC server/clients with in built logging, tracing and metrics support.

🛠️ Fixes :

1. Enhanced gRPC Logging

  • Improved logs for interservice gRPC calls, now including:
    • Trace ID: For better tracking of distributed requests.
    • Status Code: Logs the response status of gRPC calls for easy debugging and issue resolution.

v1.31.0

20 Jan 11:18
fc8616b
Compare
Choose a tag to compare

Release v1.31.0

🚀 Features :

  1. Support for ScyllaDB as a Data Source
    ScyllaDB is now supported as a data source in GoFr. The following methods are supported:

    Query(dest any, stmt string, values ...any) error  
    QueryWithCtx(ctx context.Context, dest any, stmt string, values ...any) error  
    Exec(stmt string, values ...any) error  
    ExecWithCtx(ctx context.Context, stmt string, values ...any) error  
    ExecCAS(dest any, stmt string, values ...any) (bool, error)  
    NewBatch(name string, batchType int) error  
    NewBatchWithCtx(ctx context.Context, name string, batchType int) error  
    BatchQuery(name, stmt string, values ...any) error  
    BatchQueryWithCtx(ctx context.Context, name, stmt string, values ...any) error  
    ExecuteBatchWithCtx(ctx context.Context, name string) error  

    To integrate ScyllaDB into your application, use the AddScyllaDB method:

    client := scylladb.New(scylladb.Config{
        Host:     app.Config.Get("SCYLLADB_HOST"),
        Keyspace: app.Config.Get("SCYLLADB_KEYSPACE"),
        Port:     app.Config.GetInt("SCYLLADB_PORT"),
        Username: app.Config.Get("SCYLLADB_USERNAME"),
        Password: app.Config.Get("SCYLLADB_PASSWORD"),
    })
    app.AddScyllaDB(client)

    For detailed instructions, refer to the ScyllaDB documentation.

  2. Built-in Tracing for Interservice gRPC Calls
    All interservice gRPC calls in GoFr now include in-built tracing support.

    • Prerequisite: Ensure gofr-cli v0.3.0 is installed. To install gofr-cli, run:

      go install gofr.dev/cli/gofr@latest
    • To generate the gRPC client, run:

      gofr wrap grpc client -proto=path/to/your/proto/file

    For detailed instructions on setting up the gRPC Client in GoFr, refer to the documentation. You can also explore an example gRPC client implementation in the examples folder.

Full Changelog: v1.30.0...v1.31.0

v1.30.0

10 Jan 06:24
9e01054
Compare
Choose a tag to compare

Release v1.30.0

🚀 Features

1. GoFr's Context Support in gRPC Handlers

Introduced context integration for gRPC handlers, enabling efficient dependency and tracing management.
Automatically generates gRPC handler templates with built-in support for gofr's context using the gofr wrap grpc command of gofr cli.

Note: For details on setting up Protocol Buffers and gRPC in GoFr, visit the official Documentation and Example

🔧 Fixes

1. ExpectSelect Update in SQL Mocks

Refactored the ExpectSelect function in SQL mocks. Users can now set expected responses using the ReturnsResponse method, ensuring accurate mock behavior during tests.

  • Example Usage:

    var result, actualResult Response
    
    mockContainer, sqlMock := NewMockContainer(t)
    ctx := &gofr.Context{
      Container: mockContainer,
    }
    
    expectedResult := Response{
      // ... fill with expected values
    }
    
    sqlMock.ExpectSelect(ctx, &result, query).ReturnsResponse(expectedResult)
    
    ctx.SQL.Select(ctx, &actualResult, query)
    
    assert.Equal(t, actualResult, expectedResult)

2. Environment Variable Handling

  • OS-level environment variables now override values from .env, .<APP_ENV>.env configurations, ensuring consistent behaviour across environments.

3. Improved Logging

  • Removed sensitive information (e.g., usernames and passwords) from MongoDB connection logs by replacing uri with host.
  • Fixed inaccurate Redis connection logs and removed unnecessary SQL connection logs when no SQL connection is established.
  • Added error logs for database migration failures, improving visibility during debugging.

4. Security Fixes

  • Updated golang.org/x/crypto to v0.31.0 to resolve potential authorization bypass issues.
  • Updated go.mod in pkg/gofr/datasource/mongo for compatibility with Go commands.

v1.29.0

24 Dec 13:12
5bc6ec2
Compare
Choose a tag to compare

Release v1.29.0


✨ Features:

  1. Custom Metadata in Responses
    Users can now include metadata in API responses using the response.Response struct. This allows for clean, structured responses while providing additional contextual information.
    • Response Structure:
      • With Metadata:
        {
            "data": {},
            "metadata": {}
        }
      • Without Metadata:
        {
            "data": {}
        }
    • Example Usage:
      func HelloHandler(c *gofr.Context) (interface{}, error) {
          headers := map[string]string{
              "X-Custom-Header": "CustomValue",
          }
      
          metaData := map[string]any{
              "environment": "staging",
              "timestamp":   time.Now(),
          }
      
          return response.Response{
              Data:     map[string]string{"message": "Hello, World!"},
              Metadata: metaData,
              Headers:  headers,
          }, nil
      }

  1. Support for Redis Database Selection:
  • Introduces a new config REDIS_DB to specify the Redis database index to be used.
  • Example usage:
    os.Setenv("REDIS_DB", "1")

🛠️ Fixes:

  1. Disconnected Spans Exported for Remote-log-url:
  • Resolves an issue where disconnected spans were created for each fetch request of the remote log.
  • Ensures that all traces exported for a single HTTP request have spans in hierarchy.
  1. Hardcoded Ports Fix:
  • Addresses the issue of hardcoded ports within the codebase.
  • Now allows for dynamic port configuration, improving flexibility and deployment scenarios.
  1. Lowercase Default Paths for CRUD Helpers:
  • Changes the default paths for CRUD helpers to be in lowercase.
  • Helps avoid confusion caused by case sensitivity on certain servers.

v1.28.2

11 Dec 07:29
16de8ae
Compare
Choose a tag to compare

Release v1.28.2

Fixes 🛠️️ :

  • Set Content-Type: application/json for HTTP service that doesn't explicitly provide a content type, when calling GET, POST, or similar methods during interservice communication.

v1.28.1

09 Dec 08:44
f8639d4
Compare
Choose a tag to compare

Release v1.28.1

🛠️ Fixes:

  1. Improved Static File Metrics

    • Metrics middleware now accurately identifies and tracks static file requests, including handling file paths with query parameters.

    Example:
    Metrics will now correctly log /static/example.js or /static/example.js?v=42.

  2. Subscription Handler Validation

    • Improved error handling in App.Subscribe().
    • Ensures that topic and handler parameters are validated to prevent runtime errors.
    • Logs detailed error messages for invalid subscriptions.

v1.28.0

27 Nov 12:51
4df66c5
Compare
Choose a tag to compare

✨ Features:

Custom Response Headers Support:
Users can add custom HTTP response headers using the Response struct. This feature helps add extra information, such as security policies or other metadata, to improve communication between clients and servers.

  • Example usage:
        return response.Response{
            Data:    "Hello World from new Server",
            Headers: map[string]string{"X-Custom-Header": "CustomValue", "X-Another-Header": "AnotherValue"},
        }` 

OpenTSDB Support:
Users can integrate OpenTSDB to store and retrieve time-series data.

  • Methods include:

    • PutDataPoints: Send data to OpenTSDB.
    • QueryDataPoints: Retrieve data based on specified parameters.
    • GetAggregators: Get available aggregation functions.
    • QueryAnnotation, PostAnnotation, PutAnnotation, DeleteAnnotation: Manage annotations in OpenTSDB.
  • To import GoFr's external OpenTSDB driver:
    go get gofr.dev/pkg/gofr/datasource/opentsdb@latest

type OpenTSDB interface { 
    HealthChecker 
    PutDataPoints(ctx context.Context, data any, queryParam string, res any) error
    QueryDataPoints(ctx context.Context, param any, res any) error 
    QueryLatestDataPoints(ctx context.Context, param any, res any) error 
    GetAggregators(ctx context.Context, res any) error QueryAnnotation(ctx context.Context, queryAnnoParam map[string]any, res any) error 
    PostAnnotation(ctx context.Context, annotation any, res any) error
    PutAnnotation(ctx context.Context, annotation any, res any) error 
    DeleteAnnotation(ctx context.Context, annotation any, res any) error 
}

Support for Binding Binary/Octet Stream:
Users can bind binary/octet-stream content directly to []byte slices using GoFr context.

  • Example usage:

        var result []byte
        err := req.Bind(&result)
        if err != nil {
          log.Fatalf("Bind error: %v", err)
        } 

🛠️ Fixes:

Milliseconds Logged as Microseconds:

  • Previously, operation duration was calculated in milliseconds but was incorrectly logged as microseconds, which led to confusion. This has been fixed to ensure that logs display the accurate duration in microseconds.

Dgraph Datasource Panic Fix

  • Fixed an issue where the Dgraph datasource would panic due to an uninitialized tracer when added as an external datasource. This bug has been addressed.

Solr Methods Fixes:

  • Fixed errors occurring in the following Solr datasource methods: Update, Delete, ListFields, Retrieve, AddField, UpdateField, DeleteField.
  • Updated documentation and provided a working example, accordingly.

Deprecated UseMiddlewareWithContainer Method:

  • The method UseMiddlewareWithContainer has been deprecated and will be removed in future releases. Developers should use the *App.UseMiddleware method instead, which does not depend on the container.

Static File Path Handling Fix:

  • Fixed an issue in the AddStaticFiles method where file paths were not correctly resolved when they didn't start with ./ or were not absolute paths. The fix ensures that the correct file path is registered for static file serving.

v1.27.1

17 Nov 04:50
9a97ec5
Compare
Choose a tag to compare

Release v1.27.1

🛠️ Fixes

Fix Google Pubsub Panic

The callback function for the Google client Subscribe function was configured to fetch one message per Subscribe call. Still, at times the message was being sent to a closed channel causing unexpected behaviour. Fixed the issue of receiving messages on a channel that closes only on application shutdown.