上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 22 下一页
摘要: package main import ( "fmt" "sort" ) type ServerSlice []Server type Server struct { Weight int } //只要实现了下面三个方法就可以传入sort方法使用 func (p ServerSlice) Len() int { return len(p) } fu... 阅读全文
posted @ 2019-12-19 22:49 离地最远的星 阅读(378) 评论(0) 推荐(0) 编辑
摘要: package util import ( "fmt" "hash/crc32" "math/rand" "sort" "time" ) type HttpServer struct { //目标server类 Host string Weight int CWeight int //当前权重 ... 阅读全文
posted @ 2019-12-19 22:48 离地最远的星 阅读(1036) 评论(0) 推荐(0) 编辑
摘要: package main import ( "log" "net/http" "net/http/httputil" "net/url" "os" "os/signal" "regexp" "反向代理/util" ) type ProxyHandler struct { } func (*ProxyHandler) ServeH... 阅读全文
posted @ 2019-12-19 22:47 离地最远的星 阅读(442) 评论(0) 推荐(0) 编辑
摘要: 来自为知笔记(Wiz) 阅读全文
posted @ 2019-12-19 22:46 离地最远的星 阅读(209) 评论(0) 推荐(0) 编辑
摘要: package util import ( "fmt" "hash/crc32" "math/rand" "time" ) type HttpServer struct { //目标server类 Host string Weight int } func NewHttpServer(host string, weight int) *Ht... 阅读全文
posted @ 2019-12-19 22:45 离地最远的星 阅读(297) 评论(0) 推荐(0) 编辑
摘要: func (this *LoadBalance) RoundRobinByWeight3() *HttpServer { //平滑加权轮询 for _, s := range this.Servers { s.CWeight = s.CWeight + s.Weight } sort.Sort(this.Servers) max := this.... 阅读全文
posted @ 2019-12-19 22:44 离地最远的星 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 来自为知笔记(Wiz) 阅读全文
posted @ 2019-12-19 22:43 离地最远的星 阅读(288) 评论(0) 推荐(0) 编辑
摘要: package util import ( "math/rand" "time" ) type HttpServer struct { //目标server类 Host string } func NewHttpServer(host string) *HttpServer { return &HttpServer{Host: host} } type Lo... 阅读全文
posted @ 2019-12-19 22:41 离地最远的星 阅读(241) 评论(0) 推荐(0) 编辑
摘要: Go实现 在头里设置WWW-Authenticate 返回401 func (webhandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { writer.Header().Set("WWW-Authenticate", `Basic realm="您必须输入用户名和密码"`) writer... 阅读全文
posted @ 2019-12-19 22:41 离地最远的星 阅读(174) 评论(0) 推荐(0) 编辑
摘要: package main import ( "io/ioutil" "log" "net/http" "os" "os/signal" ) type ProxyHandler struct { } func (*ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { d... 阅读全文
posted @ 2019-12-19 22:40 离地最远的星 阅读(120) 评论(0) 推荐(0) 编辑
上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 22 下一页