This commit is contained in:
Liang Ding 2014-11-18 15:32:55 +08:00
parent 9c701edb86
commit 260bd543ad
2 changed files with 21 additions and 2 deletions

View File

@ -18,6 +18,7 @@ package conf
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"net"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -266,7 +267,7 @@ func Save() bool {
} }
// Load loads the configurations from wide.json. // Load loads the configurations from wide.json.
func Load(confPath, confIP, confPort, confServer, confChannel string) { func Load(confPath, confIP, confPort, confServer, confChannel string, confDocker bool) {
bytes, _ := ioutil.ReadFile(confPath) bytes, _ := ioutil.ReadFile(confPath)
err := json.Unmarshal(bytes, &Wide) err := json.Unmarshal(bytes, &Wide)
@ -330,6 +331,23 @@ func Load(confPath, confIP, confPort, confServer, confChannel string) {
Wide.SessionChannel = confChannel Wide.SessionChannel = confChannel
} }
// Docker
if confDocker {
h, err := net.LookupHost("wide")
if nil != err {
glog.Error(err)
os.Exit(-1)
}
// XXX: secure protocol wss enchance
channel := "ws://" + h[0] + ":" + Wide.Port
Wide.EditorChannel = channel
Wide.OutputChannel = channel
Wide.ShellChannel = channel
Wide.SessionChannel = channel
}
Wide.Server = strings.Replace(Wide.Server, "{Port}", Wide.Port, 1) Wide.Server = strings.Replace(Wide.Server, "{Port}", Wide.Port, 1)
Wide.StaticServer = strings.Replace(Wide.StaticServer, "{Port}", Wide.Port, 1) Wide.StaticServer = strings.Replace(Wide.StaticServer, "{Port}", Wide.Port, 1)
Wide.EditorChannel = strings.Replace(Wide.EditorChannel, "{Port}", Wide.Port, 1) Wide.EditorChannel = strings.Replace(Wide.EditorChannel, "{Port}", Wide.Port, 1)

View File

@ -45,6 +45,7 @@ func init() {
confPort := flag.String("port", "", "port to visit") confPort := flag.String("port", "", "port to visit")
confServer := flag.String("server", "", "this will overwrite Wide.Server if specified") confServer := flag.String("server", "", "this will overwrite Wide.Server if specified")
confChannel := flag.String("channel", "", "this will overwrite Wide.XXXChannel if specified") confChannel := flag.String("channel", "", "this will overwrite Wide.XXXChannel if specified")
confDocker := flag.Bool("docker", false, "whether run in a docker container")
flag.Set("logtostderr", "true") flag.Set("logtostderr", "true")
flag.Set("v", "3") flag.Set("v", "3")
@ -54,7 +55,7 @@ func init() {
event.Load() event.Load()
conf.Load(*confPath, *confIP, *confPort, *confServer, *confChannel) conf.Load(*confPath, *confIP, *confPort, *confServer, *confChannel, *confDocker)
conf.FixedTimeCheckEnv() conf.FixedTimeCheckEnv()
conf.FixedTimeSave() conf.FixedTimeSave()