mirror of
https://github.com/wahyd4/forego.git
synced 2026-08-09 05:07:05 +10:00
Merge pull request #48 from nhocki/port_env
Read PORT from the environment
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user