Gateway is a API gateway based on http. It works at 7 layer.
- Traffic Control
- Circuit Breaker
- Loadbalance
- Routing based on URL
- API aggregation(support url rewrite)
- Backend Server heath check
- Use fasthttp
- Admin WEBUI
Gateway dependency etcd
git clone https://github.com/fagongzi.git
cd $GOPATH/src/github.com/fagongzi/gateway
go build cmd/proxy/proxy.go
go build cmd/admin/admin.go
Gateway has three component: proxy, admin, etcd.
The proxy provide http server. Proxy is stateless, you can scale proxy node to deal with large traffic.
The admin is a backend manager system. Admin also is a stateless node, you can use a Nginx node for HA. One Admin node can manager a set of proxy which has a same etcd prefix configuration.
The Etcd store gateway's mete data.
-
Server
Server is a backend server which provide restfule json service.The server is the basic unit at gateway.
-
Cluster
Cluster is a set of servers which provide the same service. The Loadbalancer select a usable server to use.
-
Aggregation
Aggregation is a set of URLs that correspond to some clusters. A http request arrive proxy, the proxy dispatcher the request to specify clusters, then wait responses and merge to response client. Notes, if your set a rewrite rule, it must container full request url, because proxy need set path value to query string or set query string to path value, to meet the demand that backend server url design.
-
Routing
Routing is a approach to control http traffic to clusters. You can use cookie, query string, request header infomation in a expression for control.
Your backend server provide some restful API, You can redefine the API URL that provide to API caller.Use this funcation you can provide beautiful APIs.
You can define a URL and configuration a URL set which you want to aggregation.
Gateway can use Traffic Control and Circuit Breaker functions to avoid backend crash by hight triffic.
Gateway's Routing fucntion can help your AB Test.