Merge pull request #48 from nhocki/port_env

Read PORT from the environment
This commit is contained in:
David Dollar
2015-01-02 17:01:36 -05:00
3 changed files with 16 additions and 2 deletions
+1 -1
View File
@@ -2,12 +2,12 @@ package main
import (
"bufio"
"bytes"
"fmt"
"github.com/ddollar/forego/Godeps/_workspace/src/github.com/daviddengcn/go-colortext"
"io"
"os"
"sync"
"bytes"
)
type OutletFactory struct {
+2
View File
@@ -104,6 +104,8 @@ func basePort(env Env) (int, error) {
return flagPort, nil
} else if env["PORT"] != "" {
return strconv.Atoi(env["PORT"])
} else if os.Getenv("PORT") != "" {
return strconv.Atoi(os.Getenv("PORT"))
}
return defaultPort, nil
}
+13 -1
View File
@@ -1,6 +1,9 @@
package main
import "testing"
import (
"os"
"testing"
)
func TestParseConcurrencyFlagEmpty(t *testing.T) {
c, err := parseConcurrency("")
@@ -117,6 +120,15 @@ func TestPortFromEnv(t *testing.T) {
t.Fatal("Base port should be 5000")
}
os.Setenv("PORT", "4000")
port, err = basePort(env)
if err != nil {
t.Fatal("Can not get port: %s", err)
}
if port != 4000 {
t.Fatal("Base port should be 4000")
}
env["PORT"] = "6000"
port, err = basePort(env)
if err != nil {