Use net.JoinHostPort instead of: fmt.Sprintf("%s:%d", gatewayHost, gatewayPort)
983 gatewayHost := b.cliCtx.String(flags.GRPCGatewayHost.Name)
984 rpcHost := b.cliCtx.String(flags.RPCHost.Name)
985 selfAddress := fmt.Sprintf("%s:%d", rpcHost, b.cliCtx.Int(flags.RPCPort.Name))
986 gatewayAddress := fmt.Sprintf("%s:%d", gatewayHost, gatewayPort) 987 allowedOrigins := strings.Split(b.cliCtx.String(flags.GPRCGatewayCorsDomain.Name), ",")
988 enableDebugRPCEndpoints := b.cliCtx.Bool(flags.EnableDebugRPCEndpoints.Name)
989 selfCert := b.cliCtx.String(flags.CertFlag.Name)
Use net.JoinHostPort instead of: fmt.Sprintf("%s:%d", rpcHost, b.cliCtx.Int(flags.RPCPort.Name))
982 gatewayPort := b.cliCtx.Int(flags.GRPCGatewayPort.Name)
983 gatewayHost := b.cliCtx.String(flags.GRPCGatewayHost.Name)
984 rpcHost := b.cliCtx.String(flags.RPCHost.Name)
985 selfAddress := fmt.Sprintf("%s:%d", rpcHost, b.cliCtx.Int(flags.RPCPort.Name)) 986 gatewayAddress := fmt.Sprintf("%s:%d", gatewayHost, gatewayPort)
987 allowedOrigins := strings.Split(b.cliCtx.String(flags.GPRCGatewayCorsDomain.Name), ",")
988 enableDebugRPCEndpoints := b.cliCtx.Bool(flags.EnableDebugRPCEndpoints.Name)
Description
Instead of manually joining hostname and port combinations, it is better to use net.JoinHostPort
.
Bad practice
fmt.Sprintf("%s:%s", host, port)
fmt.Sprintf("%s:%d", host, port)
fmt.Sprintf("%s:%s", "", host)
fmt.Sprintf("%s:%d", "", host)
Recommended
net.JoinHostPort(host, port)
net.JoinHostPort(host, port)
net.JoinHostPort(host, "")
net.JoinHostPort(host, "")