Skip to content

Commit

Permalink
use roundrobin for load balancing purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
d4l3k committed Jun 4, 2018
1 parent 8bf3664 commit 5e4093b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/mholt/caddy/caddyhttp/httpserver"
"github.com/pieterlouw/caddy-grpc/proxy"
"google.golang.org/grpc"
"google.golang.org/grpc/balancer/roundrobin"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"

Expand All @@ -25,8 +26,10 @@ type server struct {
// ServeHTTP satisfies the httpserver.Handler interface.
func (s server) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
//dial Backend
opt := []grpc.DialOption{}
opt = append(opt, grpc.WithCodec(proxy.Codec()))
opt := []grpc.DialOption{
grpc.WithBalancerName(roundrobin.Name),
grpc.WithCodec(proxy.Codec()),
}
if s.backendIsInsecure {
opt = append(opt, grpc.WithInsecure())
} else {
Expand Down

0 comments on commit 5e4093b

Please sign in to comment.