sshpiper/libplugin/plugin_ext.go
Boshi Lian 7fdd88982a
introduce uri for flexable upstream conn (#615)
* Deprecate host and port fields in Upstream message; introduce uri field for connection details

* Update libplugin/plugin.proto

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* refactor(grpc): streamline upstream connection handling and add GetOrGenerateUri method

* refactor(libplugin): update GetOrGenerateUri to return error and add IPv6 test

* refactor(libplugin): simplify GetOrGenerateUri to remove error return and update tests

* Update cmd/sshpiperd/internal/plugin/grpc.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-06-30 15:18:57 -07:00

23 lines
409 B
Go

package libplugin
import (
"fmt"
"net"
"strconv"
)
// GetOrGenerateUri returns the existing Uri if set, otherwise constructs it from Host and Port.
func (x *Upstream) GetOrGenerateUri() string {
uri := x.GetUri()
if uri != "" {
return uri
}
port := x.GetPort()
if port <= 0 {
port = 22
}
addr := net.JoinHostPort(x.GetHost(), strconv.Itoa(int(port)))
return fmt.Sprintf("tcp://%v", addr)
}