MIT License

项目介绍

go-kratos/kratos-layout 是一个托管在 GitHub 上的开源项目,主要使用 Go 编写,采用 MIT License 许可证,目前获得 500 个 Star、229 次 Fork。

仓库全名
go-kratos/kratos-layout
开源许可证
MIT License
Star 数
500
Fork 数
229
未关闭 Issue
2

README 摘要

Kratos Project Template A project template for creating new Kratos services with HTTP and gRPC transports, protobuf-first APIs, Wire dependency injection, OpenAPI generation, and a small CRUD example. Use this repository as a starting point for a new service. The included sample resource is only reference code for API shape, layering, code generation, and testing. Replace it with your own domain model when creating…

完整内容见 GitHub 原始 README 或本页 。

常见问题

kratos-layout 用什么语言开发?

主要使用 Go 编写,采用 MIT License 许可证,目前有 500 个 Star。

kratos-layout 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 kratos-layout 的源码?

可以直接克隆仓库:git clone https://github.com/go-kratos/kratos-layout.git,默认分支为 main;安装与运行步骤见仓库 README。

kratos-layout 最近还在维护吗?

仓库最近一次更新为 9月1日,当前有 2 个未关闭 Issue;Star 数为 500,可作为社区活跃度的参考。

关于

A clean and production-ready project template for building Go microservices with Kratos.

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
974
价值分
370
活跃状态
活跃

语言占比

Dockerfile
Go
Makefile

Release

README

Kratos Project Template

A project template for creating new Kratos services with HTTP and gRPC transports, protobuf-first APIs, Wire dependency injection, OpenAPI generation, and a small CRUD example.

Use this repository as a starting point for a new service. The included sample resource is only reference code for API shape, layering, code generation, and testing. Replace it with your own domain model when creating a real project.

Create a New Project

  1. Copy or generate a repository from this template.
  2. Update the Go module path:
go mod edit -module github.com/your-org/your-service
  1. Replace existing import paths that reference this template module.
  2. Rename the command, service metadata, and sample API package to match your service.
  3. Replace the sample CRUD resource with your own resource.
  4. Regenerate code and verify the project:
make all
go test ./...

What Is Included

  • Kratos HTTP and gRPC server setup.
  • Protobuf API definitions and generated Go code.
  • OpenAPI generation.
  • Wire-based dependency injection.
  • Layered service, biz, and data packages.
  • A lightweight in-memory repository for the sample resource.
  • Unit tests for the service layer.
  • Server-streaming and bidirectional-streaming examples.

Project Layout

api/                  Protobuf APIs and generated bindings
cmd/                  Application entrypoints
configs/              Local configuration
internal/server/      HTTP and gRPC server construction
internal/service/     Transport-facing service methods
internal/biz/         Usecases, entities, errors, repository interfaces
internal/data/        Repository implementations
third_party/          Protobuf dependencies
openapi.yaml          Generated OpenAPI document

API Template Practices

The sample CRUD API demonstrates common conventions for Kratos projects:

  • Resource-oriented methods: create, get, list, update, delete.
  • HTTP annotations with google.api.http.
  • Required fields with google.api.field_behavior.
  • List requests with page_size, page_token, filter, and order_by.
  • Pagination with go.einride.tech/aip/pagination.
  • Partial updates with google.protobuf.FieldMask and fieldmask.Update.
  • Streaming RPC definitions for one-way and bidirectional streams.

The in-memory data layer intentionally stays simple. It demonstrates flow across layers, but does not implement a full query engine. Real repositories can apply parsed filters and ordering in SQL, Ent, or another storage layer.

Development Commands

Install generators:

make init

Regenerate API bindings and OpenAPI:

make api

Regenerate config protobufs:

make config

Run all generation steps, Wire, and module cleanup:

make all

Build:

make build

Test:

go test ./...

Run Locally

go run ./cmd/server -conf ./configs

Default local ports are configured in configs/config.yaml:

  • HTTP: 0.0.0.0:8000
  • gRPC: 0.0.0.0:9000

Docker

docker build -t <your-image-name> .
docker run --rm -p 8000:8000 -p 9000:9000 \
  -v </path/to/your/configs>:/data/conf \
  <your-image-name>

评论

暂无评论