mirror of
https://github.com/hanzoai/porto.git
synced 2026-11-03 18:08:27 +00:00
24 lines
517 B
Go
24 lines
517 B
Go
package testutils
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/effective-security/porto/x/netutil"
|
|
)
|
|
|
|
// CreateURL returns URL with a random port
|
|
func CreateURL(scheme, host string) string {
|
|
bind := CreateBindAddr(host)
|
|
|
|
return fmt.Sprintf("%s://%s", scheme, bind)
|
|
}
|
|
|
|
// CreateBindAddr returns a bind address with a random port
|
|
func CreateBindAddr(host string) string {
|
|
port, err := netutil.FindFreePort(host, 5)
|
|
if err != nil {
|
|
panic("unable to find free port: " + err.Error())
|
|
}
|
|
return fmt.Sprintf("%s:%d", host, port)
|
|
}
|