Load balancing using Golang. source code
使用 Golang 实现的负载均衡。源码
import { LoadBalancer } from "@bfchain/load-balancer";
const lb = new LoadBalancer();
const res = await lb.start({
scheme: "http",
host: "0.0.0.0",
port: 8888,
servers: [
{
name: "Server A",
scheme: "http",
host: "127.0.0.1",
port: 9800,
},
{
name: "Server B",
scheme: "http",
host: "127.0.0.1",
port: 9801,
},
],
// custom static route
routes: [
{
mode: ":path",
value: "/a/*",
to: ["Server A"],
},
{
mode: ":path",
value: "/a/*",
to: ["Server B"],
},
],
});
:path
{ "mode": ":path", "value": "/a/*", "to": ["Server A"] }
:method
{ "mode": ":method", "value": "GET", "to": ["Server A"] }
:header
{ "mode": ":header", "key": "Set-Cookie", // need CamelCase "value": "x=x", "to": ["Server A"] }
:and
{ "mode": ":and", "left": { "mode": ":path", "value": "/a/*" }, "right": { "mode": ":path", "value": "/a/*" }, "to": ["Server A"] }
./load-balancer -config ./config.json