Go-Chassis

在 Go 中快速开发微服务的微服务框架。(a microservice framework for rapid development of micro services in Go.)

Github stars Tracking Chart

Go chassis

Go-Chassis 是一个微服务框架,用于快速开发 Go 中的微服务。

为何使用 Go chassis

go chassis 是一个独立于协议的框架,任何协议都可以与 go chassis 集成,并利用负载均衡、断路器、速率限制、路由管理等相同功能,那些功能可以弹性你的服务。

go chassis 通过打开跟踪和 prometheus 使服务可观察到。

go chassis 是灵活的,许多不同的模块可以被其他实现替换,如注册表、指标、处理程序链、配置中心等。

通过路由管理、断路器、负载均衡、监控等许多内置功能,您无需亲自调查、实施和集成多种解决方案。

go chassis 支持 Istio 平台,虽然 Istio 是一个在数据平面上具有服务网格的优秀平台,但它肯定会降低吞吐量并增加服务的延迟,因此 chassis 可以为程序带来更好的性能,你可以使用 Istio 配置来控制 go chassis。

Go chassis 还有一个服务网络解决方案https://github.com/go-mesh/mesher ,它建立在 go chassis 之上。你可以使用相同的注册表,配置来完成用不同语言编写的所有服务。

特性

  • 可插拔的 registrator 和发现服务:支持服务中心,istio pilot,kubernetes 和 基于文件的注册表,适合客户端发现和服务器端发现模式
  • 可插拔协议:您可以自定义自己的协议,默认支持 http 和 grpc
  • 多服务器管理:您可以通过协议和端口分离 API
  • 断路器:在运行时保护您的微服务系统
  • 路由管理:能够根据权重和匹配规则路由到不同的服务,轻松实现 Canary Release
  • 客户端负载均衡:能够自定义策略
  • 速率限制:客户端和服务器端速率限制
  • 可插拔密码:能够为 AKSK 和 TLS 证书定制您自己的密码
  • 处理程序链:能够在客户端和服务器端的服务调用期间添加您自己的代码
  • 指标:能够自动公开 Prometheus 指标 API 和自定义指标报告者
  • 跟踪:使用 opentracing-go 作为标准库,易于集成跟踪 impl
  • 记录器:您可以自定义您自己的编写器以下载日志,默认支持文件和标准输出
  • 热重新配置:由 go-archaius 提供支持,配置可以在运行时重新加载,如负载平衡、断路器、速率限制
  • 动态配置框架:由 go-archaius 提供支持,开发人员能够轻松开发具有热重新配置功能的服务
  • 故障注入:在消费者方面,您可以注入故障以将混乱测试引入您的系统
  • 您可以检查插件以查看更多功能。

快速开始

您可以在此处查看更多文档,此文档适用于最新版本的 go chassis,如果您想查看您的版本文档,请按照此处生成它

  1. 安装 go 1.10+
  2. 克隆项目
git clone git@github.com:go-chassis/go-chassis.git
  1. 使用 go mod(go 1.11+, 实验但推荐的方法)
cd go-chassis
export GO111MODULE=on 
go mod download
#optional
export GO111MODULE=on 
go mod vendor

注意:如果您不使用 mod,我们不能保证您的兼容性。但是,您仍然可以维护自己的供应商,这意味着您必须自己解决编译问题。如果你使用 mod 不能下载所有的3pkg,设置 env GOPROXY=https://goproxy.io 之前,您使用 mod 下载 pkg。

  1. 安装 service-center
  2. 编写您的第一个 http 微服务

例子

你可以在这里查看例子

注意:现在示例正在迁移到此处

通信协议

Go-Chassis 支持3种通信协议。

  1. Rest -- REST 是一种利用 HTTP 协议进行通信的方法。
  2. Highway -- 这是一个 RPC 通信协议,它已被弃用。
  3. grpc -- 原生 grpc 协议,go chassis 将熔断机制、路由管理等带入 grpc。

dlv 的调试建议:

如果你的 go 版本是 go 1.10 以后,在调试之前将 -tags debug 添加到 go 构建参数中。

例:

go build -tags debug -o server -gcflags "all=-N -l" server.go

Chassis 定制 debug 标签以解决 dlv 调试问题:

https://github.com/golang/go/issues/23733

https://github.com/derekparker/delve/issues/865

生态系统

本部分介绍了go chassis 可以运行的一些 eco 系统。

Apache ServiceComb

使用 ServiceComb 服务中心作为注册表,强烈建议使用 chassis 提供更多功能,如合同管理和多服务注册表。 这不会阻止您使用 kubernetes 或 Istio,因为服务中心可以聚合异构注册表并为您提供统一的服务注册表入口点。

Kubenetes 和 Istio

go chassis 有 k8s 注册表和 Istio 注册表插件,并支持 Istio 流量管理。你可以使用 spring cloud 或 Envoy 在同一服务发现服务下使用 go chassis。

(First version: vz 2019/07/27)

Overview

Name With Ownergo-chassis/go-chassis
Primary LanguageGo
Program languageGo (Language Count: 2)
PlatformLinux, Mac, Huawei Cloud, Kubernetes, Docker, Windows
License:Apache License 2.0
Release Count64
Last Release Namev2.7.1 (Posted on )
First Release Namev0.1 (Posted on )
Created At2018-01-15 12:57:10
Pushed At2023-10-11 21:15:01
Last Commit At2023-03-08 14:08:27
Stargazers Count2.7k
Watchers Count119
Fork Count500
Commits Count893
Has Issues Enabled
Issues Count266
Issue Open Count34
Pull Requests Count696
Pull Requests Open Count6
Pull Requests Close Count109
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

Build Status
Coverage Status Go Report Card GoDoc HitCount Join Slack

中文版README

Go-Chassis is a microservice framework for rapid development of microservices in Go

Why use Go chassis

  • go chassis is designed as a protocol-independent framework, any protocol
    is able to integrate with go chassis and leverage same function like load balancing,
    circuit breaker,rate limiting, routing management, those function resilient your service

  • go chassis makes service observable by bringing open tracing and prometheus to it.

  • go chassis is flexible, many different modules can be replaced by other implementation,
    like registry, metrics, handler chain, config server etc

  • With many build-in function like route management, circuit breaker, load balancing, monitoring etc,
    your don't need to investigate, implement and integrate many solutions yourself.

  • go chassis supports Istio control panel, go chassis can bring better performance to go program,
    you can use Istio configurations to control go chassis.

  • https://github.com/huaweicloud/spring-cloud-huawei integrate with servicecomb, go chassis can work together with spring cloud.

Features

  • Pluggable registrator and discovery service: Support Service center, istio pilot, kubernetes and file based registry,
    fit both client side discovery and server side discovery pattern
  • Pluggable Protocol: You can custom your own protocol, by default support http and grpc
  • Multiple server management: you can separate API by protocols and ports
  • Circuit breaker: Protect your micro service system in runtime
  • Route management: Able to route to different service based on weight and match rule to achieve Canary Release easily
  • Client side Load balancing: Able to custom strategy
  • Rate limiting: Both client side and server side rate limiting
  • Pluggable Cipher: Able to custom your own cipher for AKSK and TLS certs
  • Handler Chain: Able to add your own code during service calling for client and server side
  • Metrics: Able to expose Prometheus metric API automatically and custom metrics reporter
  • Tracing:Use opentracing-go as standard library, easy to integrate tracing impl
  • Logger: You can custom your own writer to sink log, by default support file and stdout
  • Hot-reconfiguraion: Powered by go-archaius, configurations can be reload in runtime, like load balancing, circuit breaker, rate limiting
  • Dynamic Configuration framework: Powered by go-archaius, developer is able to develop a service which has hot-reconfiguration feature easily
  • Fault Injection: In consumer side, you can inject faults to bring chaos testing into your system
  • API gateway and service mesh solution: powered by servicecomb-mesher.
  • Open API 2.0 support go chassis will automatically generate Open API 2.0 doc and register it to service center. you can manage all the API docs in one place

You can check plugins to see more features

Get started

1.Generate go mod

go mod init

2.Add go chassis

GO111MODULE=on go get github.com/go-chassis/go-chassis

if you are facing network issue

export GOPROXY=https://goproxy.io

3.Write your first http micro service

Documentations

You can see more documentations in here,
this online doc is for latest version of go chassis, if you want to see your version's doc,
follow here to generate it in local

Examples

You can check examples here

NOTICE: Now examples is migrating to here

Communication Protocols

Go-Chassis supports 3 types of communication protocol.

  1. Rest - REST is an approach that leverages the HTTP protocol for communication.
  2. Highway - This is a RPC communication protocol, it was deprecated.
  3. grpc - native grpc protocol, go chassis bring circuit breaker, route management etc to grpc.

Debug suggestion for dlv:

Add -tags debug into go build arguments before debugging, if your go version is go1.10 onward.

example:

go build -tags debug -o server -gcflags "all=-N -l" server.go

Chassis customized debug tag to resolve dlv debug issue:

https://github.com/golang/go/issues/23733

https://github.com/derekparker/delve/issues/865

Eco system

this part introduce some eco systems that go chassis can run with

Apache ServiceComb

With ServiceComb service center as registry, go chassis supply more features like contract management
and multiple service registry,
highly recommended. that will not prevent you from using kubernetes or Istio,
Because service center can aggregate heterogeneous registry
and give you a unified service registry entry point.

Kubernetes and Istio

go chassis has k8s registry and Istio registry plugins, and support Istio traffic management
you can use spring cloud or Envoy with go chassis under same service discovery service.

Other project using go-chassis

Known Users

趣头条

To start developing go chassis

  1. Install go 1.12+

  2. Clone the project

git clone git@github.com:go-chassis/go-chassis.git
  1. Download vendors
cd go-chassis
export GO111MODULE=on 
go mod download
#optional
export GO111MODULE=on 
go mod vendor

NOTICE:if you do not use mod, We can not ensure you the compatibility.
however you can still maintain your own vendor,
which means you have to solve compiling issue your own.

  1. Install service-center
To the top