From 260bd543adb467e2dce97b3728c6da7354075066 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 18 Nov 2014 15:32:55 +0800 Subject: [PATCH] . --- conf/wide.go | 20 +++++++++++++++++++- main.go | 3 ++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/conf/wide.go b/conf/wide.go index 19d8620..37204c4 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -18,6 +18,7 @@ package conf import ( "encoding/json" "io/ioutil" + "net" "os" "os/exec" "path/filepath" @@ -266,7 +267,7 @@ func Save() bool { } // 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) err := json.Unmarshal(bytes, &Wide) @@ -330,6 +331,23 @@ func Load(confPath, confIP, confPort, confServer, confChannel string) { 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.StaticServer = strings.Replace(Wide.StaticServer, "{Port}", Wide.Port, 1) Wide.EditorChannel = strings.Replace(Wide.EditorChannel, "{Port}", Wide.Port, 1) diff --git a/main.go b/main.go index 4861c69..d476685 100644 --- a/main.go +++ b/main.go @@ -45,6 +45,7 @@ func init() { confPort := flag.String("port", "", "port to visit") confServer := flag.String("server", "", "this will overwrite Wide.Server 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("v", "3") @@ -54,7 +55,7 @@ func init() { event.Load() - conf.Load(*confPath, *confIP, *confPort, *confServer, *confChannel) + conf.Load(*confPath, *confIP, *confPort, *confServer, *confChannel, *confDocker) conf.FixedTimeCheckEnv() conf.FixedTimeSave()