Gateway is a http restful API gateway.
- Traffic Control
- Circuit Breaker
- Loadbalance
- Service Discovery
- Plugin mechanism
- Routing based on URL
- API aggregation
- API Validation
- API Access Control(blacklist and whitelist)
- API Mock
- 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
You can run docker pull fagongzi/gateway
to get docker images, then use docker run -d fagongzi/gateway
to run. It export 3 ports:
-
80
proxy http serve port
-
8081
proxy manager port
-
8080
admin http port
You can read this for more infomation about build and run gateway.
-
admin
http://demo-admin.fagongzi.win admin/admin
-
proxy
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. more.
-
Cluster
Cluster is a set of servers which provide the same service. The Loadbalancer select a usable server to use. more.
-
API
API is the core concept in gateway. You can define a API with a URL pattern, http method, and at least one dispatch node. more.
-
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.
You can define restful API based on backend real apis. You can also define a aggregation API use more backend apis.
You can create some validation rules for api, these rules can validate args of api is correct.
You can create a mock API. These API is not depend on backend server api. It can used for front-end developer or default return value that the back-end server does not respond to.
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.
Gateway support plugin mechanism, currently it only support service discovery plugin.
Once gateway proxy started, it scan pluginDir
for plugins. In PluginDir
, a json file is correspond a external plugin. The json file formart is:
{
"type": "service-discovery",
"address": "127.0.0.1:8080"
}
Gateway proxy used http for communicate with plugin. Plugin must implementation this API for Registration:
URL | Method |
---|---|
/plugins/$type | POST |