Skip to content

BioforestChain/load-balancer

Repository files navigation

Load Balancer

Load balancing using Golang. source code

使用 Golang 实现的负载均衡。源码

Usage

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"],
    },
  ],
});

Route Mode

  • :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"]
    }

Run Load-Balancer without nodejs 独立运行程序

./load-balancer -config ./config.json

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published