aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/phayes/freeport/freeport.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-16 23:20:23 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-16 23:23:43 +0200
commit1d678dfdfa026968dbb19795c9bed16385603b21 (patch)
treecac862609d0103ee30da39cd0054b11884248e9d /vendor/github.com/phayes/freeport/freeport.go
parent131a862d313f12808d63e832126317a27226940b (diff)
downloadgit-bug-1d678dfdfa026968dbb19795c9bed16385603b21.tar.gz
vendor dependencies with dep
Diffstat (limited to 'vendor/github.com/phayes/freeport/freeport.go')
-rw-r--r--vendor/github.com/phayes/freeport/freeport.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/vendor/github.com/phayes/freeport/freeport.go b/vendor/github.com/phayes/freeport/freeport.go
new file mode 100644
index 00000000..c44b60df
--- /dev/null
+++ b/vendor/github.com/phayes/freeport/freeport.go
@@ -0,0 +1,30 @@
+package freeport
+
+import (
+ "net"
+)
+
+// GetFreePort asks the kernel for a free open port that is ready to use.
+func GetFreePort() (int, error) {
+ addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
+ if err != nil {
+ return 0, err
+ }
+
+ l, err := net.ListenTCP("tcp", addr)
+ if err != nil {
+ return 0, err
+ }
+ defer l.Close()
+ return l.Addr().(*net.TCPAddr).Port, nil
+}
+
+// GetPort is deprecated, use GetFreePort instead
+// Ask the kernel for a free open port that is ready to use
+func GetPort() int {
+ port, err := GetFreePort()
+ if err != nil {
+ panic(err)
+ }
+ return port
+}