Welcome aboard! 🎉 This Microservice Template Project serves as a scaffold for quickly initiating microservice logic development. It's designed to facilitate the creation of microservices by providing a well-structured, easy-to-navigate project layout.
The project has a strong association with Polaris, utilizing its service discovery, rate limiting, and degradation functions.
Here's a tree-like representation of the project structure:
📦Microservice Template Project
┣ 📂api
┃ ┗📚 Protobuf files for API declaration and management
┣ 📂biz
┃ ┗🏢 Business logic, focusing on the overall process
┣ 📂bo
┃ ┗🔄 Data flow management between `biz` and `data` layers
┣ 📂code
┃ ┗🏷 Application status codes for quick issue identification
┣ 📂conf
┃ ┗⚙️ Configuration files with customizable mappings
┣ 📂data
┃ ┗💽 Data processing, including database and remote calls
┣ 📂service
┃ ┗🛎️ Service declarations, parameter validation, and data conversion
┗ 📂server
┗🖥️ Service configuration for API interfaces
If you want to use this microservice code template, all you need to do is execute the following command to install the Lynx CLI command-line tool, and then run the new command to automatically initialize a runnable project (the new command can support multiple project names).
go install github.com/go-lynx/lynx/cmd/lynx@latestlynx new demo1 demo2 demo3To get your microservice up and running in no time, use the following code (Some functionalities can be plugged in or out based on your choice.):
func main() {
boot.LynxApplication(wireApp).Run()
}This code initializes and runs the application with essential components like HTTP, gRPC with TLS, MySQL, Redis, Tracer, and Token.
We hope this guide helps you navigate our Microservice Template Project. Happy coding! 🎉
如果只想在本地调试服务且不依赖 Polaris,可按照下面的步骤操作:
- 使用 Go 1.25.3
或者确认
go env -w GOTOOLCHAIN=go1.25.3
go version输出为go1.25.3。 - 启动本地依赖(PostgreSQL & Redis)
该 compose 文件会启动
docker compose -f deployments/docker-compose.local.yml up -d
postgres://lynx:[email protected]:5432/lynx与redis://127.0.0.1:6379,并自动暴露到本机端口。 - 使用本地配置启动应用(该配置不会加载 Polaris)
如果你有自己的数据库/Redis,可以修改
go run ./cmd/user -conf ./configs/bootstrap.local.yaml
configs/bootstrap.local.yaml中的lynx.pgsql与lynx.redis配置。 - 调试完成后关闭依赖
docker compose -f deployments/docker-compose.local.yml down
默认的 configs/bootstrap.yaml 仍然保留对 Polaris 的配置,方便需要接入 Polaris 的环境使用。