libra:动态反向代理

  • t8_341183
    了解作者
  • 25.9KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-18 08:49
    上传日期
libra是动态反向代理/负载平衡器 , 特征 动态和多个反向代理服务器 动态更改原始服务器地址 动态变化响应头 严格的单元测试 您可以使用此程序包更快地构建动态反向代理服务器,现在它具有三种负载平衡算法,即随机,轮循,轮循(权重轮循) 入门 安装 要安装此软件包,您需要安装Go并在计算机上设置Go工作区。 安装库的最简单方法是运行: go get github.com/zhuCheer/libra 运行示例 将目录更改为libra软件包并运行example.go,您可以启动反向代理。 > cd ../src/github.com/zhuCheer/libra/example > go run example.go 现在,你可以打开浏览器来http://127.0.0.1:5000 ,你会看到反向代理,它与循环平衡运行到http://127.0.0.1:5001 , http://
libra-master.zip
  • libra-master
  • balancer
  • balancer_test.go
    7.1KB
  • wroundrobin.go
    3.6KB
  • balancer.go
    4.6KB
  • wroundrobin_test.go
    3.6KB
  • roundrobin.go
    1KB
  • roundrobin_test.go
    2KB
  • random_test.go
    1.8KB
  • random.go
    989B
  • logger
  • logger_test.go
    1.5KB
  • logger.go
    1.6KB
  • example
  • example.go
    12.1KB
  • .travis.yml
    184B
  • README_CN.md
    3.4KB
  • LICENSE
    1.1KB
  • README.md
    3.4KB
  • proxy.go
    5.9KB
  • .gitignore
    6B
  • errpage.go
    2KB
  • proxy_test.go
    6.6KB
内容介绍
# libra is a dynamic reverse proxy / load balancer [![Build Status](https://travis-ci.org/zhuCheer/libra.svg?branch=master)](https://travis-ci.org/zhuCheer/libra) [![Go Report Card](https://goreportcard.com/badge/github.com/zhuCheer/libra)](https://goreportcard.com/report/github.com/zhuCheer/libra) [![GoDoc](https://godoc.org/github.com/zhuCheer/libra?status.svg)](https://godoc.org/github.com/zhuCheer/libra) [![codecov](https://codecov.io/gh/zhuCheer/libra/branch/master/graph/badge.svg)](https://codecov.io/gh/zhuCheer/libra) [English document](https://github.com/zhuCheer/libra/blob/master/README.md), [中文文档](https://github.com/zhuCheer/libra/blob/master/README_CN.md) ## Feature - dynamic and multiple reverse proxy server - dynamic change origin server addr - dynamic change response header - rigorous unit testing You can use this package build a dynamic reverse proxy server faster, now it has three load balance algorithms, random, roundrobin, wroundrobin (round robin with weight) ## Getting Started #### Installation To install this package, you need to install Go and setup your Go workspace on your computer. The simplest way to install the library is to run: `go get github.com/zhuCheer/libra` #### run example Change directory to libra package and run the example.go, you can start a reverse proxy. ``` > cd ../src/github.com/zhuCheer/libra/example > go run example.go ``` Now,you can open browser to `http://127.0.0.1:5000`,you will see the reverse proxy, it running with round robin balance to `http://127.0.0.1:5001`, `http://127.0.0.1:5002` and `http://127.0.0.1:5003` http server. #### How to use ``` import "github.com/zhuCheer/libra" // create a new reverse proxy,input three params bind ip:port, custom response header; // then register a site, fill in domain name, balancer algorithm and origin url scheme; // it has three balancer algorithm random,roundrobin,wroundrobin(round robin with weight) var srv = libra.NewHttpProxySrv("127.0.0.1:5000", nil) srv.RegistSite("www.yourappdomain.com", "roundrobin", "http") // add target domain and ip:port srv.AddAddr("www.yourappdomain.com", "127.0.0.1:5001", 1) srv.AddAddr("www.yourappdomain.com", "127.0.0.1:5001", 2) // start reverse proxy server srv.Start() ``` #### Principles - The reverse proxy serves as a gateway between users and your application origin server. In so doing it handles all policy management and traffic routing; - A reverse proxy operates by: - 1. Receiving a user connection request - 2. Completing a TCP three-way handshake, terminating the initial connection - 3. Connecting with the origin server and forwarding the original request ![image](https://img.douyucdn.cn/data/yuba/weibo/2019/07/02/201907021730116899917826388.gif) ## Functions ``` import "github.com/zhuCheer/libra" var srv = libra.NewHttpProxySrv("127.0.0.1:5000", nil) srv.RegistSite("www.yourappdomain.com", "roundrobin", "http") // set response header srv.ResetCustomHeader(map[string]string{"X-LIBRA": "the smart ReverseProxy"}) // change balance algorithm srv.ChangeLoadType("www.yourappdomain.com", "random") // add origin server addr, dynamic change without restarting srv.AddAddr("www.yourappdomain.com","192.168.1.100:8081", 1) // delete origin server addr, dynamic change without restarting srv.DelAddr("www.yourappdomain.com","192.168.1.100:8081") ``` ## Contributors - [@Chase](https://www.facebook.com/profile.php?id=100017355485621) ## License [MIT](./LICENSE)
评论
    相关推荐