mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-29 18:36:30 +02:00
22 lines
523 B
Go
22 lines
523 B
Go
// Package netutil contains various functions that help with networking.
|
|
package netutil
|
|
|
|
import "net"
|
|
|
|
// AllocatePorts allocates random ports suitable for listening.
|
|
func AllocatePorts(count int) ([]string, error) {
|
|
var ports []string
|
|
for i := 0; i < count; i++ {
|
|
li, err := net.Listen("tcp", "127.0.0.1:0")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
_, port, _ := net.SplitHostPort(li.Addr().String())
|
|
err = li.Close()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ports = append(ports, port)
|
|
}
|
|
return ports, nil
|
|
}
|