需要 Go 1.25 或更高版本,并额外安装 protoc 与 protoc-gen-go;从 v2 升级到 v3 前要先读 v2-to-v3 迁移指南,v3 精简了核心依赖且把隐式行为改为显式;示例服务默认监听 8000(HTTP)和 9000(gRPC)端口,注意端口占用

kratos
go-kratosMIT活跃维护面向云原生时代的 Go 微服务框架,内置 gRPC/HTTP 通信、代码生成和分层架构约定,帮团队快速搭建可维护的微服务。
Your ultimate Go microservices framework for the cloud-native era.
go install github.com/go-kratos/kratos/cmd/kratos/v3@latest
kratos upgradeREADME 未说明,纯 Go 框架无显存或 GPU 要求
轻量级 Go 微服务框架,提供传输、中间件、注册配置等小而明确的 API,让你专注业务逻辑
面向云原生时代的 Go 微服务框架,内置 gRPC/HTTP 通信、代码生成和分层架构约定,帮团队快速搭建可维护的微服务。
核心能力
- 用 Protobuf 做 API-first 开发并生成 HTTP/gRPC 代码
- 统一 HTTP 与 gRPC 的 transport 抽象层
- 可组合中间件覆盖恢复、日志、校验、链路追踪、指标、鉴权
- 注册中心、配置、编码组件均可插拔替换
- 基于标准库 log/slog 的日志,contrib 提供 OpenTelemetry 扩展
容易踩的坑
- v3.0.0最新正式版2026-06-26 · 2026-06-26 13:00 UTC
Breaking Changes
- break: update kratos modules to v3 (#3822)
New Features
- feat(errors): add standard library errors wrappers (#3844)
- feat(transport/http): add read/write deadline control to ServerStream (#3843)
- feat(protoc-gen-go-http): support google.api.HttpBody response (#3839)
- feat(config): add generic config Get support (#3778)
- feat(middleware/auth/jwt): add WithParserOptions to allow configuring… (#3803)
- feat: support pre condition failed code mapping (#3795)
- feat(cmd): add --repo flag to kratos new command (#3789)
- feat(errors): add TooManyRequests error type (#3787)
- feat(transport/http): support redirect errors in default error encoder (#3783)
- feat(validate): add custom validator support and improve flexibility (#3780)
Bug Fixes
- fix(transport/http): bind named body field for websocket client streaming (#3837)
- fix(transport/http): clone transport before applying TLSClientConfig to avoid mutating http.DefaultTransport (#3808)
- fix: JSON parsing error during hot reload caused by duplicate file write events
- fix(config/apollo): prevent panic on nil NewValue in watcher onChange (#3806)
- fix(metrics): remove redundant _bucket suffix from default histogram name (#3794)
- fix: trim service suffix of service name (#3785)
- fix(cmd): assign filepath.Join result to base in findCMD loop (#3798)
- fix(middleware/metrics): remove redundant _bucket suffix from default histogram names (#3797)
- fix(contrib/registry/discovery): replace context.TODO() with context.Background() (#3786)
- fix(contrib/registry/eureka): use shared http.Transport (#3772)
Chores
- chore(cmd): update dependencies and enhance project creation (#3779)
Others
- contrib/registry/nacos: upgrade nacos-sdk-go from v1 to v2 (#3804)
- refactor(contrib/registry/discovery): remove dead code (#3801)
- Acc/reg (#3800)
- build(deps): bump actions/cache from 4 to 5 (#3788)
- refactor(contrib/opensergo): replace golang.org/x/net/context with standard context (#3782)
- perf(encoding/form): replace fmt.Sprintf with string concatenation for map key encoding (#3777)
New Contributors
- @codeErrorSleep made their first contribution in https://github.com/go-kratos/kratos/pull/3777
- @lhlyu made their first contribution in https://github.com/go-kratos/kratos/pull/3789
- @hj24 made their first contribution in https://github.com/go-kratos/kratos/pull/3795
- @edwinhuish made their first contribution in https://github.com/go-kratos/kratos/pull/3785
- @mahendrarathore1742 made their first contribution in https://github.com/go-kratos/kratos/pull/3803
- @shcw made their first contribution in https://github.com/go-kratos/kratos/pull/3794
- @agermel made their first contribution in https://github.com/go-kratos/kratos/pull/3778
- @flytutu-susu made their first contribution in https://github.com/go-kratos/kratos/pull/3431
- @shenqidebaozi with @Copilot made their first contribution in https://github.com/go-kratos/kratos/pull/3808
Full Changelog: https://github.com/go-kratos/kratos/compare/v2.9.2...v3.0.0
- v2.9.22025-12-05 · 2025-12-05 16:05 UTC
查看更新说明
Dependencies
- deps: upgrade kratos version to v2.9.2 (#3773)
New Features
- feat(ci): implement comment-check in workflows. (#3426)
- feat(consul): support custom tags for service registration (#3707)
Bug Fixes
- fix(metadata): ensure Clone creates deep copy of slices (#3767)
- fix(http): ignored errors in error message (#3751)
- fix: google.protobuf.Empty produces invalid type*pb.google_protobuf_Empty(#3715) (#3716)
- fix(transport/grpc): ClientOption cannot initialize StreamMiddleware(#3697) (#3729)
Chores
- chore(ci): update GitHub Actions dependencies (#3746)
- chore(go.mod): update Go version to 1.22 across all modules (#3745)
- chore(all): normalize whitespace (#3713)
Others
-
build(deps): bump peter-evans/create-or-update-comment (#3761)
-
docs: correct official documentation URLs (#3768)
-
perf(config): move placeholder regex to package-level variable (#3769)
-
perf(encoding/form): optimize parseURLQueryMapKey with memory-efficient implementation (#3770)
-
docs: improve some comments (#3766)
-
build(deps): bump actions/checkout from 4 to 6 (#3762)
-
build(deps): bump peter-evans/find-comment from 3.1.0 to 4.0.0 (#3760)
-
refactor(transport/http): improve compatibility for 'RequestFromServerContext' (#3749)
-
ci: add missing fi in comment-check.yml (#3753)
-
refactor: use math/rand/v2 instead of math/rand (#3752)
-
Revert "支持nacos v2 (#3493)" (#3747)
-
支持nacos v2 (#3493)
-
style(contrib/registry/kubernetes): simplify namespace empty check in NewRegistry (#3665)
-
perf(log): optimize key-value pair processing in Filter.Log (#3664)
-
perf(selector/wrr): optimize map initialization and simplify node comparison (#3738)
-
build(all): remove unused compatibility files and legacy build tags (#3735)
-
ci: add Go 1.25 support (#3736)
-
test(selector/random): update TestWrr to use more reasonable statistical bounds (#3737)
-
build(deps): bump github/codeql-action from 3 to 4 (#3744)
New Contributors
- @Dark1Forest made their first contribution in https://github.com/go-kratos/kratos/pull/3729
- @CZJCC made their first contribution in https://github.com/go-kratos/kratos/pull/3493
- @HeimaoLST made their first contribution in https://github.com/go-kratos/kratos/pull/3716
- @unkmonster made their first contribution in https://github.com/go-kratos/kratos/pull/3749
Full Changelog: https://github.com/go-kratos/kratos/compare/v2.9.1...v2.9.2
- v2.9.12025-09-12 · 2025-09-12 10:45 UTC
查看更新说明
Dependencies
- deps: retract v2.9.0 (#3723)
Bug Fixes
- fix(transport/http): resolve breaking change with ResponseTransporter interface (#3721)
Others
- Revert "perf(transport/http): optimize URL construction with url.URL for bett…" (#3722)
New Contributors
- @qingbozhang made their first contribution in https://github.com/go-kratos/kratos/pull/3721
Full Changelog: https://github.com/go-kratos/kratos/compare/v2.9.0...v2.9.1
- v2.9.02025-09-10 · 2025-09-10 12:45 UTC
查看更新说明
Dependencies
- deps(middleware): upgrade protovalidate to resolve compatibility issue (#3706)
New Features
- feat(protoc-gen-go-http): mark deprecated methods in generated code (#3711)
- feat: add MCP transport (#3646)
Bug Fixes
- fix(encoding): extract all form fields even if some unsupported (#3694)
- fix meta variable (#3712)
- fix: honor shutdown timeout when provided context already canceled (#3695)
- fix stale entries before the each pick operation (#3690)
- fix: replace strconv.Itoa with strconv.FormatInt for int64 handling (#3667)
- fix: solve have syntax error when execute make command. (#3682)
- fix(internal/host): Extract optimizes the return of the minimum index IP (#3421)
- fix: Fixed zookeeper watcher exiting the loop under exceptional conditions, causing service discovery to terminate (#3517)
Chores
- chore: add deepwiki badge (#3701)
Others
- perf(transport/http): optimize URL construction with url.URL for better performance (#3678)
- perf(transport/http/binding): optimize EncodeURL performance for paths without placeholders (#3679)
- refactor(all): replace atomic functions with atomic types (#3699)
- contrib/register/nacos: refactor to use maps.Clone (#3703)
- *: use net.JoinHostPort to improve IPv6 compatible (#3675)
- perf(config/env): use strings.LastIndexByte instead of strings.LastIndex (#3660)
- Add trendshift badge (#3655)
- perf(metadata): simplify Metadata.Add by avoiding redundant strings.ToLower call (#3671)
- Mcp options (#3652)
- Revert "refactor: replace repeated error reasons with constants (#3612)" (#3651)
- perf(config/env): use strings.Cut to optimize env load method (#3645)
- add mcp middleware (#3649)
- refactor(contrib/registry/etcd): use Namespace Name and ID as the unique keys (#3594)
- go mod tidy (#3648)
- build(deps): bump golang.org/x/net from 0.23.0 to 0.33.0 (#3527)
- github: Remove submodule dependencies in Dependabot. (#3643)
- perf(encoding/form): optimize camelCase and snakeCase conversion (#3592)
- refactor: extract key for reuse and maintainability (#3602)
New Contributors
- @uucloud made their first contribution in https://github.com/go-kratos/kratos/pull/3561
- @ch3nnn made their first contribution in https://github.com/go-kratos/kratos/pull/3624
- @yuluo-yx made their first contribution in https://github.com/go-kratos/kratos/pull/3625
- @Piwriw made their first contribution in https://github.com/go-kratos/kratos/pull/3642
- @hengyumo made their first contribution in https://github.com/go-kratos/kratos/pull/3517
- @HoronLee made their first contribution in https://github.com/go-kratos/kratos/pull/3706
- @cuiweixie made their first contribution in https://github.com/go-kratos/kratos/pull/3703
Full Changelog: https://github.com/go-kratos/kratos/compare/v2.8.4...v2.9.0
- v2.8.42025-03-07 · 2025-03-07 16:21 UTC
查看更新说明
New Features
- feat: disable grpc reflection configuration
- feature(middleware/validate): migrate from PGV to protovalidate, since PGV has entered in maintenance (#3498)
Bug Fixes
- fix: Improve server stop handling with graceful shutdowns (#3525)
- fix(registry/consul): fix concurrency issues and improve performance (#3511)
Chores
- chore: replace interface{} with any (#3557)
Others
- optimize loops, when discover load is nil. (#3507)
New Contributors
- @zhanluxianshen made their first contribution in https://github.com/go-kratos/kratos/pull/3507
- @BandlSkyler made their first contribution in https://github.com/go-kratos/kratos/pull/3550
Full Changelog: https://github.com/go-kratos/kratos/compare/v2.8.3...v2.8.4
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
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/slogbased 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
- Go 1.25 or later
- protoc
- protoc-gen-go
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.
Acknowledgments
The following projects influenced Kratos design:
License
Kratos is open-sourced software licensed under the MIT license.