kratos README

The project's README from github.com/go-kratos/kratos. As one markdown file: README.md.

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

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 [email protected]. 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.

kratos (go-kratos/kratos)

Searching Database…

26K ·GitHub
这是什么?Kratos 是一个轻量级的 Go 框架,用于构建云原生微服务。它的 API 小巧而明确,让你的代码可以专注于业务逻辑,而不用在底层胶水代码上花功夫。
它是一个让我能搭建整个服务的基础框架,还是一套松散的辅助库?它是一个完整的框架:Kratos CLI 可以生成服务的初始代码,你在它明确的 API 之上进行开发,涵盖传输层、中间件、注册中心、配置、日志、编码和代码生成。
我怎么把第一个服务跑起来?先安装 Kratos CLI,然后用它创建一个服务——生成的服务启动后,你访问一个本地地址就能确认它正常运行,文档里还介绍了生成服务的更完整流程。
在生成项目代码之前,我需要先装好哪些东西?Go 1.25 或更高版本,另外还需要 protoc 和 protoc-gen-go,用来从 Protobuf 定义生成代码。
如果我升级现有的 Kratos 服务,有什么需要注意的?从 v2 迁移到 v3 并不能直接替换:v3 减少了核心依赖,并把以前隐式的行为改成显式的,所以 README 建议在升级生产环境服务之前先仔细阅读迁移指南。
Kratos 开箱即用地处理了哪些事情,让我不用自己去接?它提供了统一的 HTTP 和 gRPC 传输层,可组合的中间件覆盖异常恢复、日志、参数校验、链路追踪、监控指标和鉴权,还提供基于 slog 的日志(contrib 中有 OpenTelemetry 扩展),以及一致的元数据、错误处理、参数校验和 OpenAPI 工作流。
API 优先的开发流程实际用起来是什么样的?你先用 Protobuf 定义 API,Kratos 会根据它生成 HTTP 和 gRPC 代码,这样接口约定就决定了服务的具体实现。
如果核心库里缺少我需要的注册中心、配置存储或中间件怎么办?注册中心、配置和编码组件都是可插拔的,而且 contrib 生态还提供了注册中心、配置存储、中间件、编码和可观测性方面的可选集成。
哪些项目影响了 Kratos 的设计?README 提到 go-kit/kit、go-micro、google/go-cloud、go-zero 和 beego 都是其设计上的参考来源。
Creator
go-kratos
Size
9.8 MB
Stars
26K
Age
7y
Commits · 90 Days