gofr.dev

module
v1.63.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: Apache-2.0

README ΒΆ

GoFr

logo

GoFr: An Opinionated Microservice Development Framework

godoc gofr-docs Maintainability Code Coverage Go Report Card Apache 2.0 License discord

Listed in the CNCF Landscape

🎯 Goal

GoFr is designed to simplify microservice development, with a key focus on Kubernetes deployment and out-of-the-box observability. While capable of building generic applications, microservices remain at its core.


πŸ’‘ Key Features

  1. Simple API Syntax
  2. REST Standards by Default
  3. Configuration Management
  4. Observability (Logs, Traces, Metrics)
  5. Inbuilt Auth Middleware & Custom Middleware Support
  6. gRPC Support
  7. HTTP Service with Circuit Breaker Support
  8. Pub/Sub
  9. Health Check for All Datasources
  10. Database Migration
  11. Cron Jobs
  12. Support for Changing Log Level Without Restarting
  13. Swagger Rendering
  14. Abstracted File Systems
  15. Websockets
  16. LLM Integration (app.AddLLM, ctx.LLM()) with Built-in Tracing, Token Metrics and Streaming
  17. MCP Server (app.EnableMCP) to Expose Read-Only Handlers as Tools for AI Agents

πŸš€ Getting Started

Prerequisites

  • GoFr requires Go version 1.26 or above.

Installation

To get started with GoFr, add the following import to your code and use Go’s module support to automatically fetch dependencies:

import "gofr.dev/pkg/gofr"

Alternatively, use the command:

go get -u gofr.dev/pkg/gofr

πŸƒ Running GoFr

Here's a simple example to get a GoFr application up and running:

package main

import "gofr.dev/pkg/gofr"

func main() {
	app := gofr.New()

	app.GET("/greet", func(ctx *gofr.Context) (any, error) {
		return "Hello World!", nil
	})

	app.Run() // listens and serves on localhost:8000
}

To run this code:

$ go run main.go

Visit localhost:8000/greet to see the result.


πŸ€– AI Features

GoFr treats LLMs and AI agents like any other datasource: one line to set them up, with tracing, metrics, logs and health checks wired in automatically.

Call an LLM from a handler

app.AddLLM registers an OpenAI-compatible model (OpenAI, Groq, DeepSeek, Together, Ollama, or any endpoint via BaseURL). Handlers reach it through ctx.LLM(), which also offers Chat, Stream and Embed.

package main

import (
	"gofr.dev/pkg/gofr"
	"gofr.dev/pkg/gofr/ai/llm"
)

func main() {
	app := gofr.New()

	// The API key is read from LLM_API_KEY, or GROQ_API_KEY for this provider.
	app.AddLLM(&llm.Client{Provider: llm.Groq, Model: "llama-3.3-70b-versatile"})

	app.POST("/summarize", func(ctx *gofr.Context) (any, error) {
		var in struct {
			Text string `json:"text"`
		}

		if err := ctx.Bind(&in); err != nil {
			return nil, err
		}

		return ctx.LLM().Generate(ctx, "Summarize the following:\n"+in.Text)
	})

	app.Run()
}

A model can also be configured without code, through LLM_PROVIDER, LLM_MODEL and LLM_API_KEY in configs/.env. See the LLM guide.

Expose handlers to AI agents

app.EnableMCP serves your read-only handlers (GET, HEAD, OPTIONS and QUERY) as Model Context Protocol tools, so MCP clients such as Claude Code or Claude Desktop can discover and call them. Write handlers are never exposed. The MCP server listens on loopback at MCP_PORT (default 8200; 0 turns the transport off).

app := gofr.New()

app.EnableMCP()

app.GET("/products/{id}", getProduct)

app.Run()

ctx.LLM().Tools() gives a handler the same tools in-process, so you can build your own agent loop. See Building AI Agents and the using-ai example.


πŸ“‚ More Examples

Explore a variety of ready-to-run examples in the GoFr examples directory.


πŸ‘©β€πŸ’» Documentation

  • GoDoc: Official API documentation.
  • GoFr Documentation: Comprehensive guides and resources.
  • AI coding assistants: point your assistant at AGENTS.md for GoFr's conventions, and at llms.txt for an index of the docs.

πŸ‘ Contribute

Join Us in Making GoFr Better

Share your experience: If you’ve found GoFr helpful, consider writing a review or tutorial on platforms like Medium, Dev.to, or your personal blog. Your insights could help others get started faster!

Contribute to the project: Want to get involved? Check out our CONTRIBUTING.md guide to learn how you can contribute code, suggest improvements, or report issues.


πŸ”’ Secure Cloning

To securely clone the GoFr repository, you can use HTTPS or SSH:

Cloning with HTTPS

git clone https://github.com/gofr-dev/gofr.git

Cloning with SSH

git clone git@github.com:gofr-dev/gofr.git

🎁 Get a GoFr T-Shirt & Stickers!

If your PR is merged, or if you contribute by writing articles or promoting GoFr, we invite you to fill out this form to claim your GoFr merchandise as a token of our appreciation!

Partners

JetBrains logo

Directories ΒΆ

Path Synopsis
cli
gofr module
examples
http-server command
sample-cmd command
using-ai command
This example shows the whole GoFr AI surface in one service:
This example shows the whole GoFr AI surface in one service:
using-cron-jobs command
using-file-bind command
using-graphql command
using-publisher command
pkg
gofr/ai
Package ai is a generated GoMock package.
Package ai is a generated GoMock package.
gofr/ai/llm
Package llm provides an OpenAI-compatible LLM client that satisfies the gofr.dev/pkg/gofr/ai model contract.
Package llm provides an OpenAI-compatible LLM client that satisfies the gofr.dev/pkg/gofr/ai model contract.
gofr/ai/mcp
Package mcp exposes an ai.Tools set as agent-callable tools over the Model Context Protocol, speaking JSON-RPC 2.0 over Streamable HTTP.
Package mcp exposes an ai.Tools set as agent-callable tools over the Model Context Protocol, speaking JSON-RPC 2.0 over Streamable HTTP.
gofr/container
Package container provides a centralized structure to manage common application-level concerns such as logging, connection pools, and service management.
Package container provides a centralized structure to manage common application-level concerns such as logging, connection pools, and service management.
gofr/datasource
Package datasource contains all the supported data sources in GoFr.
Package datasource contains all the supported data sources in GoFr.
gofr/datasource/file
Package file is a generated GoMock package.
Package file is a generated GoMock package.
gofr/datasource/pubsub
Package pubsub provides a foundation for implementing pub/sub clients for various message brokers such as google pub-sub, kafka and MQTT.
Package pubsub provides a foundation for implementing pub/sub clients for various message brokers such as google pub-sub, kafka and MQTT.
gofr/datasource/pubsub/google
Package google provides a client for interacting with Google Cloud Pub/Sub.This package facilitates interaction with Google Cloud Pub/Sub, allowing publishing and subscribing to topics, managing subscriptions, and handling messages.
Package google provides a client for interacting with Google Cloud Pub/Sub.This package facilitates interaction with Google Cloud Pub/Sub, allowing publishing and subscribing to topics, managing subscriptions, and handling messages.
gofr/datasource/pubsub/kafka
Package kafka provides a client for interacting with Apache Kafka message queues.This package facilitates interaction with Apache Kafka, allowing publishing and subscribing to topics, managing consumer groups, and handling messages.
Package kafka provides a client for interacting with Apache Kafka message queues.This package facilitates interaction with Apache Kafka, allowing publishing and subscribing to topics, managing consumer groups, and handling messages.
gofr/datasource/pubsub/mqtt
Package mqtt provides a client for interacting with MQTT message brokers.This package facilitates interaction with MQTT brokers, allowing publishing and subscribing to topics, managing subscriptions, and handling messages.
Package mqtt provides a client for interacting with MQTT message brokers.This package facilitates interaction with MQTT brokers, allowing publishing and subscribing to topics, managing subscriptions, and handling messages.
gofr/datasource/redis
Package redis provides a client for interacting with Redis key-value stores.This package allows creating and managing Redis clients, executing Redis commands, and handling connections to Redis databases.
Package redis provides a client for interacting with Redis key-value stores.This package allows creating and managing Redis clients, executing Redis commands, and handling connections to Redis databases.
gofr/datasource/sql
Package sql provides functionalities to interact with SQL databases using the database/sql package.This package includes a wrapper around sql.DB and sql.Tx to provide additional features such as query logging, metrics recording, and error handling.
Package sql provides functionalities to interact with SQL databases using the database/sql package.This package includes a wrapper around sql.DB and sql.Tx to provide additional features such as query logging, metrics recording, and error handling.
gofr/file
Package file provides unified access to various file operations, such as creating, reading, writing files across : - S3 - FTP - SFTP - Local FileSystem
Package file provides unified access to various file operations, such as creating, reading, writing files across : - S3 - FTP - SFTP - Local FileSystem
gofr/grpc
Package grpc provides gRPC-related additions within the GoFr framework.
Package grpc provides gRPC-related additions within the GoFr framework.
gofr/http
Package http provides a set of utilities for handling HTTP requests and responses within the GoFr framework.
Package http provides a set of utilities for handling HTTP requests and responses within the GoFr framework.
gofr/http/middleware
Package middleware provides a collection of middleware functions that handles various aspects of request handling, such as authentication, logging, tracing, and metrics collection.
Package middleware provides a collection of middleware functions that handles various aspects of request handling, such as authentication, logging, tracing, and metrics collection.
gofr/internal/rbaccheck
Package rbaccheck compares an RBAC config against the route table an app serves, so that a rule guarding nothing, or a route no rule guards, is found at startup rather than by a request served without role checks.
Package rbaccheck compares an RBAC config against the route table an app serves, so that a rule guarding nothing, or a route no rule guards, is found at startup rather than by a request served without role checks.
gofr/internal/routemark
Package routemark records which route a request matched and which route is GoFr's own 404 catch-all, so that the http router, the RBAC middleware and the RBAC route check all ask the same question the same way.
Package routemark records which route a request matched and which route is GoFr's own 404 catch-all, so that the http router, the RBAC middleware and the RBAC route check all ask the same question the same way.
gofr/logging
Package logging provides logging functionalities for GoFr applications.
Package logging provides logging functionalities for GoFr applications.
gofr/metrics
Package metrics provides functionalities for instrumenting GoFr applications with metrics.
Package metrics provides functionalities for instrumenting GoFr applications with metrics.
gofr/migration
Package migration is a generated GoMock package.
Package migration is a generated GoMock package.
gofr/service
Package service provides an HTTP client with features for logging, metrics, and resilience.It supports various functionalities like health checks, circuit-breaker and various authentication.
Package service provides an HTTP client with features for logging, metrics, and resilience.It supports various functionalities like health checks, circuit-breaker and various authentication.
gofr/traces/exporters
Package exporters resolves the span exporter behind TRACE_EXPORTER and assembles the application's TracerProvider.
Package exporters resolves the span exporter behind TRACE_EXPORTER and assembles the application's TracerProvider.
gofr/websocket
Package websocket is a generated GoMock package.
Package websocket is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL