Sandbox
@go-kratos/kratos

Go microservice framework for HTTP, gRPC, and Protobuf

Kratos provides a small set of explicit building blocks for Go services: servers, middleware, registry, config, logging, and encoding. It is designed around API-first development with Protobuf, generated HTTP/gRPC code, and a shared transport layer for both protocols.

25,920 stars4.2k forksGoUpdated 29d ago
Who it's for

Builders who are setting up Go services and want a framework with transport, middleware, config, and code generation.

What it delivers

You can start new microservices with a consistent API-first structure instead of wiring every service by hand.

What it does

API-first service generation

Uses Protobuf plus generated HTTP and gRPC code to define and build services from APIs.

Unified transport layer

Provides one transport setup for both HTTP and gRPC servers.

Composable middleware

Includes middleware for recovery, logging, validation, tracing, metrics, auth, and related request handling.

Pluggable service components

Supports registry, configuration, and encoding as separate components you can swap in or extend.

Structured logging

Uses `log/slog` for logging, with OpenTelemetry support available in contrib packages.

Contrib integrations

Adds optional packages for registries, config stores, middleware, encodings, and observability.

How to get it

  1. 1Run
    go install github.com/go-kratos/kratos/cmd/kratos/v3@latest
    kratos upgrade

README

Build Status GoDoc DeepWiki codeCov Go Report Card License Awesome Go Discord

go-kratos%2Fkratos | Trendshift Go Kratos - A Go framework for microservices. | Product Hunt

Translations: English | 简体中文

Kratos

Kratos is a lightweight Go framework for building cloud-native microservices. It provides small, explicit APIs for transport, middleware, registry, configuration, logging, encoding, and code generation so applications can focus on business logic.

Features

  • API-first development with Protobuf and generated HTTP/gRPC code.
  • Unified transport layer for HTTP and gRPC.
  • Composable middleware for recovery, logging, validation, tracing, metrics, auth, and more.
  • Pluggable registry, configuration, and encoding components.
  • Standard-library log/slog based logging with OpenTelemetry extensions in contrib packages.
  • Consistent metadata, errors, validation, OpenAPI, and code-generation workflows.
  • A contrib ecosystem for optional integrations such as registries, config stores, middleware, encodings, and observability.

Installation

Requirements

Install the CLI

go install github.com/go-kratos/kratos/cmd/kratos/v3@latest
kratos upgrade

Create a Service

kratos new helloworld
cd helloworld
go mod tidy
kratos run

Visit http://localhost:8000/helloworld/kratos after the service starts.

For a fuller generated service flow:

kratos proto add api/helloworld/helloworld.proto
kratos proto client api/helloworld/helloworld.proto
kratos proto server api/helloworld/helloworld.proto -t internal/service
go generate ./...
kratos run

Usage Example

package main

import (
	"github.com/go-kratos/kratos/v3"
	"github.com/go-kratos/kratos/v3/transport/grpc"
	"github.com/go-kratos/kratos/v3/transport/http"
)

func main() {
	httpSrv := http.NewServer(http.Address(":8000"))
	grpcSrv := grpc.NewServer(grpc.Address(":9000"))

	app := kratos.New(
		kratos.Name("helloworld"),
		kratos.Version("v1.0.0"),
		kratos.Server(httpSrv, grpcSrv),
	)
	if err := app.Run(); err != nil {
		panic(err)
	}
}

v3 Migration

Kratos v3 reduces core dependencies and makes previously implicit behavior explicit. Review the v2 to v3 migration guide before upgrading production services.

Further Reading

Development

make test
make lint

Community

Security

If you discover a security vulnerability in Kratos, please contact go-kratos@googlegroups.com. Security reports are handled privately before disclosure.

Contributors

Thank you for contributing to Kratos. The contribution guide is available in the Kratos documentation.

Kratos contributors

Acknowledgments

The following projects influenced Kratos design:

License

Kratos is open-sourced software licensed under the MIT license.

Files in the repo

Repository payload36 top-level entries
  • .github
  • cmd
  • config
  • contrib
  • docs
  • encoding
  • errors
  • hack
  • internal
  • log
  • metadata
  • middleware
  • registry
  • selector
  • third_party
  • transport
  • .gitignore
  • .golangci.yml
  • app_test.go
  • app.go
  • buf.gen.yaml
  • buf.yaml
  • CODE_OF_CONDUCT.md
  • codecov.yml
  • CONTRIBUTING.md
  • go.mod
  • go.sum
  • LICENSE
  • Makefile
  • options_test.go
  • options.go
  • README_zh.md
  • README.md
  • ROADMAP.md
  • SECURITY.md
  • version.go

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More frameworks & sdks

HKUDS/nanobotFrameworks & SDKs

Ultra-lightweight, open-source, self-hosted personal AI agent framework in Python with WebUI, tools, memory, MCP, multi-agent workflows, automation, and chat apps

48k
microsoft/
SkillOpt
microsoft/SkillOptFrameworks & SDKs

SkillOpt is a text-space optimizer that trains reusable natural-language skills for frozen LLM agents through trajectory-driven edits, validation-gated updates, and deployable best_skill.md artifacts.

17k
omnigent-ai/omnigentFrameworks & SDKs

Omnigent is an open-source AI agent framework and meta-harness: orchestrate Claude Code, Codex, Cursor, Pi, and custom agents — swap harnesses without rewriting, enforce policies and sandboxing, and collaborate in real time from any device.

9.8k
kyegomez/
OpenMythos
kyegomez/OpenMythosFrameworks & SDKs

A theoretical reconstruction of the Claude Mythos architecture, built from first principles using the available research literature.

15k
D4Vinci/ScraplingFrameworks & SDKs

🕷️ An adaptive Web Scraping framework that handles everything from a single request to a full-scale crawl!

80k