上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 22 下一页
摘要: func (this *LoadBalance) RoundRobinByWeight() *HttpServer { server := this.Servers[ServerIndices[this.CurIndex]] this.CurIndex = (this.CurIndex + 1) % len(ServerIndices) //ServersIndices存放的是按照... 阅读全文
posted @ 2019-12-19 22:39 离地最远的星 阅读(179) 评论(0) 推荐(0) 编辑
摘要: func (this *LoadBalance) SelectByWeightBetter(ip string) *HttpServer { rand.Seed(time.Now().UnixNano()) sumList := make([]int, len(this.Servers)) //this.servers是服务器列表 sum := 0 for ... 阅读全文
posted @ 2019-12-19 22:38 离地最远的星 阅读(154) 评论(0) 推荐(0) 编辑
摘要: package util import ( "fmt" "hash/crc32" "math/rand" "time" ) type HttpServer struct { //目标server类 Host string Weight int } func NewHttpServer(host st 阅读全文
posted @ 2019-12-19 22:11 离地最远的星 阅读(317) 评论(0) 推荐(0) 编辑
摘要: ![](https://xiahualou.oss-cn-shanghai.aliyuncs.com/img/20191219143156.png) 来自为知笔记(Wiz) 阅读全文
posted @ 2019-12-19 22:08 离地最远的星 阅读(528) 评论(0) 推荐(0) 编辑
摘要: 创建服务端并调用 syntax = "proto3"; package services; message ProdRequest { int32 prod_id = 1; //传入id } message ProdResponse { int32 prod_stock = 1; //商品库存 } 阅读全文
posted @ 2019-12-19 22:06 离地最远的星 阅读(232) 评论(0) 推荐(0) 编辑
摘要: package main import ( "io/ioutil" "log" "net/http" "os" "os/signal" . "反向代理/util" ) type ProxyHandler struct { } func (*ProxyHandler) ServeHTTP(w http 阅读全文
posted @ 2019-12-19 22:06 离地最远的星 阅读(229) 评论(0) 推荐(0) 编辑
摘要: Models.proto syntax = "proto3"; package services; //商品模型 message ProdModel { int32 prod_id = 1; string prod_name = 2; float prod_price = 3; } Prod.pro 阅读全文
posted @ 2019-12-19 22:04 离地最远的星 阅读(721) 评论(0) 推荐(0) 编辑
摘要: package main import ( "context" "fmt" "google.golang.org/grpc" "grpccli/services" "log" ) func main() { conn, err := grpc.Dial("localhost:8081", grpc. 阅读全文
posted @ 2019-12-19 22:02 离地最远的星 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 上面的的是通用的,可以生成java php python等等之类的通用版本 Go版本安装 go get -v github.com/golang/protobuf/protoc-gen-go protoc --go_out=../services Prod.proto 通过这个命令根据proto文件 阅读全文
posted @ 2019-12-19 21:56 离地最远的星 阅读(272) 评论(0) 推荐(0) 编辑
摘要: 服务端流 syntax = "proto3"; package services; import "Models.proto"; message UserScoreRequest { repeated UserInfo users = 1; } message UserScoreResponse { 阅读全文
posted @ 2019-12-19 21:55 离地最远的星 阅读(727) 评论(0) 推荐(0) 编辑
上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 22 下一页