diff options
| author | Chris Lu <chris.lu@gmail.com> | 2019-02-18 22:38:14 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2019-02-18 22:38:14 -0800 |
| commit | 07af52cb6fefc0ebf00a5b3c4223e2f861755560 (patch) | |
| tree | 9e1c65f0705f6f8c036c2fc5943fb72fd44cb72c /weed/util/grpc_client_server.go | |
| parent | 448645203aa8478c83a0376a4b229ad1405839d0 (diff) | |
| download | seaweedfs-07af52cb6fefc0ebf00a5b3c4223e2f861755560.tar.xz seaweedfs-07af52cb6fefc0ebf00a5b3c4223e2f861755560.zip | |
raft change from http to grpc
master grpc port is fixed to http port + 10000
Diffstat (limited to 'weed/util/grpc_client_server.go')
| -rw-r--r-- | weed/util/grpc_client_server.go | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/weed/util/grpc_client_server.go b/weed/util/grpc_client_server.go index b26366ae0..b989a35d1 100644 --- a/weed/util/grpc_client_server.go +++ b/weed/util/grpc_client_server.go @@ -83,18 +83,34 @@ func WithCachedGrpcClient(fn func(*grpc.ClientConn) error, address string, opts func ParseServerToGrpcAddress(server string, optionalGrpcPort int) (serverGrpcAddress string, err error) { hostnameAndPort := strings.Split(server, ":") if len(hostnameAndPort) != 2 { - return "", fmt.Errorf("The server should have hostname:port format: %v", hostnameAndPort) + return "", fmt.Errorf("server should have hostname:port format: %v", hostnameAndPort) } - filerPort, parseErr := strconv.ParseUint(hostnameAndPort[1], 10, 64) + port, parseErr := strconv.ParseUint(hostnameAndPort[1], 10, 64) if parseErr != nil { - return "", fmt.Errorf("The server port parse error: %v", parseErr) + return "", fmt.Errorf("server port parse error: %v", parseErr) } - filerGrpcPort := int(filerPort) + 10000 + grpcPort := int(port) + 10000 if optionalGrpcPort != 0 { - filerGrpcPort = optionalGrpcPort + grpcPort = optionalGrpcPort } - return fmt.Sprintf("%s:%d", hostnameAndPort[0], filerGrpcPort), nil + return fmt.Sprintf("%s:%d", hostnameAndPort[0], grpcPort), nil +} + +func ServerToGrpcAddress(server string, defaultGrpcPort int) (serverGrpcAddress string) { + hostnameAndPort := strings.Split(server, ":") + if len(hostnameAndPort) != 2 { + return fmt.Sprintf("%s:%d", server, defaultGrpcPort) + } + + port, parseErr := strconv.ParseUint(hostnameAndPort[1], 10, 64) + if parseErr != nil { + return fmt.Sprintf("%s:%d", hostnameAndPort[0], defaultGrpcPort) + } + + grpcPort := int(port) + 10000 + + return fmt.Sprintf("%s:%d", hostnameAndPort[0], grpcPort) } |
