Convert Figma logo to code with AI

go-kratos logokratos

Your ultimate Go microservices framework for the cloud-native era.

23,116
3,985
23,116
115

Top Related Projects

21,800

A Go microservices framework

77,851

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.

29,410

High performance, minimalist Go web framework

33,019

⚡️ Express inspired web framework written in Go

31,537

beego is an open-source, high-performance web framework for the Go programming language.

20,665

Package gorilla/mux is a powerful HTTP router and URL matcher for building Go web servers with 🦍

Quick Overview

Kratos is a Go framework for building microservices, providing a comprehensive set of tools and libraries for developing robust, scalable, and maintainable applications. It offers features like service discovery, load balancing, middleware, and observability out of the box, making it easier for developers to focus on business logic.

Pros

  • Comprehensive ecosystem with built-in components for common microservice needs
  • Strong focus on performance and scalability
  • Well-documented with extensive examples and guides
  • Active community and regular updates

Cons

  • Steeper learning curve compared to simpler Go frameworks
  • May be overkill for small projects or monolithic applications
  • Some users report occasional breaking changes between versions
  • Limited third-party plugin ecosystem compared to more established frameworks

Code Examples

  1. Creating a new Kratos application:
package main

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

func main() {
    app := kratos.New(
        kratos.Name("myapp"),
        kratos.Version("1.0.0"),
        kratos.Server(
            http.NewServer(":8000"),
        ),
    )
    if err := app.Run(); err != nil {
        panic(err)
    }
}
  1. Defining a gRPC service:
package service

import (
    "context"
    pb "myapp/api/helloworld/v1"
)

type GreeterService struct {
    pb.UnimplementedGreeterServer
}

func (s *GreeterService) SayHello(ctx context.Context, req *pb.HelloRequest) (*pb.HelloReply, error) {
    return &pb.HelloReply{Message: "Hello " + req.Name}, nil
}
  1. Configuring middleware:
import (
    "github.com/go-kratos/kratos/v2/middleware/recovery"
    "github.com/go-kratos/kratos/v2/middleware/tracing"
    "github.com/go-kratos/kratos/v2/transport/http"
)

srv := http.NewServer(
    http.Address(":8000"),
    http.Middleware(
        recovery.Recovery(),
        tracing.Server(),
    ),
)

Getting Started

To start using Kratos, follow these steps:

  1. Install Kratos CLI:

    go install github.com/go-kratos/kratos/cmd/kratos/v2@latest
    
  2. Create a new project:

    kratos new myapp
    
  3. Navigate to the project directory and run the application:

    cd myapp
    go mod tidy
    kratos run
    

This will create a new Kratos project with a basic structure and run it on the default port. You can now start building your microservices using the Kratos framework.

Competitor Comparisons

21,800

A Go microservices framework

Pros of go-micro

  • More mature and established project with a larger community
  • Offers a wider range of plugins and extensions
  • Provides a complete ecosystem for microservices development

Cons of go-micro

  • Can be more complex to set up and configure
  • May have a steeper learning curve for beginners
  • Less focus on performance optimization compared to Kratos

Code Comparison

go-micro example:

service := micro.NewService(
    micro.Name("greeter"),
    micro.Version("latest"),
)

service.Init()

pb.RegisterGreeterHandler(service.Server(), new(Greeter))

if err := service.Run(); err != nil {
    fmt.Println(err)
}

Kratos example:

app := kratos.New(
    kratos.Name("greeter"),
    kratos.Version("latest"),
    kratos.Server(
        http.NewServer(),
        grpc.NewServer(),
    ),
)

if err := app.Run(); err != nil {
    log.Fatal(err)
}

Both frameworks provide similar functionality for creating microservices, but Kratos offers a more streamlined approach with built-in support for multiple protocols. go-micro requires additional configuration for multiple servers, while Kratos includes them by default. The syntax and structure of the code are different, reflecting the design philosophies of each framework.

77,851

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.

Pros of Gin

  • Lightweight and minimalist framework, offering high performance
  • Easy to learn and use, with a simple API and extensive documentation
  • Large community and ecosystem with numerous third-party middleware options

Cons of Gin

  • Limited built-in features compared to more comprehensive frameworks
  • Lacks built-in support for some advanced features like service discovery or circuit breaking

Code Comparison

Gin:

r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
    c.JSON(200, gin.H{"message": "pong"})
})
r.Run()

Kratos:

app := kratos.New(
    kratos.Name("myapp"),
    kratos.Version("1.0.0"),
    kratos.Server(
        http.NewServer(":8000"),
    ),
)
app.Run()

Gin focuses on simplicity and ease of use, making it ideal for smaller projects or microservices. Kratos, on the other hand, provides a more comprehensive framework with built-in support for microservices architecture, making it suitable for larger, more complex applications. While Gin excels in performance and simplicity, Kratos offers more out-of-the-box features for building robust, scalable microservices.

29,410

High performance, minimalist Go web framework

Pros of Echo

  • Lightweight and minimalist design, focusing on core HTTP functionality
  • Excellent performance and low memory footprint
  • Simple and intuitive API, making it easy to learn and use

Cons of Echo

  • Less comprehensive feature set compared to Kratos
  • Fewer built-in middleware options and extensions
  • Limited support for microservices architecture out of the box

Code Comparison

Echo:

e := echo.New()
e.GET("/", func(c echo.Context) error {
    return c.String(http.StatusOK, "Hello, World!")
})
e.Logger.Fatal(e.Start(":1323"))

Kratos:

app := kratos.New(
    kratos.Name("helloworld"),
    kratos.Version("1.0.0"),
    kratos.Server(
        http.NewServer(":8000"),
    ),
)
app.Run()

Echo is more focused on simplicity and ease of use, with a straightforward API for handling HTTP requests. Kratos, on the other hand, provides a more comprehensive framework for building microservices, including features like service discovery, load balancing, and distributed tracing.

While Echo excels in lightweight web applications and APIs, Kratos is better suited for complex, distributed systems. Echo's simplicity makes it easier to get started, but Kratos offers more built-in tools for scalable and resilient microservices architectures.

33,019

⚡️ Express inspired web framework written in Go

Pros of Fiber

  • Extremely fast performance due to its lightweight design and use of the fasthttp library
  • Simple and expressive API, making it easy for developers to quickly build web applications
  • Extensive middleware ecosystem, offering a wide range of pre-built solutions for common tasks

Cons of Fiber

  • Less comprehensive than Kratos, focusing primarily on HTTP routing and middleware
  • Smaller community and ecosystem compared to more established frameworks like Kratos
  • Limited built-in support for microservices architecture and service discovery

Code Comparison

Fiber:

app := fiber.New()
app.Get("/", func(c *fiber.Ctx) error {
    return c.SendString("Hello, World!")
})
app.Listen(":3000")

Kratos:

app := kratos.New(
    kratos.Name("helloworld"),
    kratos.Version("1.0.0"),
    kratos.Server(
        http.NewServer(":8000"),
    ),
)
app.Run()

While Fiber focuses on simplicity and speed for HTTP routing, Kratos provides a more comprehensive framework for building microservices with additional features like service discovery, tracing, and metrics out of the box. Fiber's API is more concise and easier to get started with, while Kratos offers a more structured approach suitable for larger, more complex applications.

31,537

beego is an open-source, high-performance web framework for the Go programming language.

Pros of Beego

  • More mature and established framework with a larger community
  • Comprehensive documentation and extensive examples
  • Built-in ORM for database operations

Cons of Beego

  • Heavier and more opinionated framework, which may limit flexibility
  • Less focus on microservices architecture compared to Kratos
  • Slower development cycle and fewer recent updates

Code Comparison

Beego routing example:

beego.Router("/", &controllers.MainController{})
beego.Router("/api/list", &controllers.APIController{}, "get:List")
beego.Run()

Kratos routing example:

s := http.NewServer()
v1 := s.Group("/v1")
v1.GET("/hello", HelloWorld)
s.Run()

Both frameworks offer easy-to-use routing, but Kratos provides a more modern and flexible approach with its group-based routing system. Beego's routing is more traditional and closely tied to its MVC architecture.

Kratos is designed with microservices in mind, offering features like service discovery, load balancing, and distributed tracing out of the box. Beego, while capable of building microservices, is more suited for monolithic applications and requires additional setup for microservices architecture.

Overall, Beego is a solid choice for developers familiar with traditional MVC frameworks, while Kratos is better suited for those building modern, cloud-native applications and microservices.

20,665

Package gorilla/mux is a powerful HTTP router and URL matcher for building Go web servers with 🦍

Pros of mux

  • Lightweight and focused solely on HTTP routing
  • Extensive documentation and widespread community adoption
  • Easy to integrate with existing Go web applications

Cons of mux

  • Limited built-in features compared to full-fledged frameworks
  • Requires additional libraries for more complex functionality
  • Less opinionated, which may lead to inconsistent project structures

Code Comparison

mux:

r := mux.NewRouter()
r.HandleFunc("/", HomeHandler)
r.HandleFunc("/products", ProductsHandler)
http.ListenAndServe(":8000", r)

kratos:

app := kratos.New(
    kratos.Name("myapp"),
    kratos.Version("1.0.0"),
    kratos.Server(
        http.NewServer(),
        grpc.NewServer(),
    ),
)
app.Run()

Key Differences

  • mux focuses on HTTP routing, while kratos is a full-featured microservices framework
  • kratos provides built-in support for gRPC, while mux requires additional libraries
  • kratos offers more opinionated project structure and configuration
  • mux is easier to integrate into existing projects, while kratos is better suited for building microservices from scratch
  • kratos includes features like service discovery, tracing, and metrics out of the box

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Build Status GoDoc codeCov Go Report Card License Awesome Go Discord

Go Kratos - A Go framework for microservices. | Product Hunt

Translate to: 简体中文

About Kratos

The name is inspired by the Greek-mythology-based game "God of War". It tells the adventures of Kratos becoming a god of war from a mortal and launching a god-killing slaughter.

Kratos is a microservice-oriented governance framework implemented by golang, which offers convenient capabilities to help you quickly build a bulletproof application from scratch, such as:

Kratos is accessible, powerful, and provides tools required for large, robust applications.

Learning Kratos

Kratos has the most extensive and thorough documentation and example library of all modern web application frameworks, making it a breeze to get started with the framework.

We also provide a modern template. This template should help reduce the work required to setup up modern projects.

Goals

Kratos boosts your productivity. With the integration of excellent resources and further support, programmers can get rid of most issues might encounter in the field of distributed systems and software engineering such that they are allowed to focus on the release of businesses only. Additionally, for each programmer, Kratos is also an ideal one learning warehouse for many aspects of microservices to enrich their experiences and skills.

Principles

  • Simple: Appropriate design with plain and easy code.
  • General: Cover the various utilities for business development.
  • Highly efficient: Speeding up the efficiency of businesses upgrading.
  • Stable: The base libs validated in the production environment have the characteristics of high testability, high coverage as well as high security and reliability.
  • Robust: Eliminating misusing through high quality of the base libs.
  • High-performance: Optimal performance excluding the optimization of hacking in case of unsafe. 
  • Expandability: Properly designed interfaces where you can expand utilities such as base libs to meet your further requirements.
  • Fault-tolerance: Designed against failure, enhance the understanding and exercising of SRE within Kratos to achieve more robustness.
  • Toolchain: Includes an extensive toolchain, such as the code generation of cache, the lint tool, and so forth.

Getting Started

Create a kratos playground through docker:

docker run -it --rm -p 8000:8000 --workdir /workspace golang
apt-get update && apt-get -y install protobuf-compiler
export GOPROXY=https://goproxy.io,direct
go install github.com/go-kratos/kratos/cmd/kratos/v2@latest && kratos upgrade
kratos new helloworld
cd helloworld/ && go mod tidy
kratos run

Use a browser to open and visit: http://localhost:8000/helloworld/kratos, The kratos program is running!

If you need more, please visit the kratos documentation.

Security Vulnerabilities

If you discover a security vulnerability within Kratos, please send an e-mail to tonybase via go-kratos@googlegroups.com. All security vulnerabilities will be promptly addressed.

Community

Contributors

Thank you for considering contributing to the Kratos framework! The contribution guide can be found in the Kratos documentation.

License

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

Acknowledgments

The following project had particular influence on kratos's design.

  • go-kit/kit is a programming toolkit for building microservices in go.
  • asim/go-micro a distributed systems development framework.
  • google/go-cloud is go cloud development kit.
  • zeromicro/go-zero is a web and rpc framework with lots of builtin engineering practices.
  • beego/beego is a web framework including RESTful APIs, web apps and backend services.