From 10f8f9f86c6b4ff5c44db5345e906ae022cb4e1b Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 18 Nov 2014 15:05:01 +0800 Subject: [PATCH] containerize --- conf/wide.go | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/conf/wide.go b/conf/wide.go index f90e8db..afa3342 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -280,9 +280,11 @@ func Load(confPath, confIP, confPort, confServer, confChannel string, confDocker // keep the raw content json.Unmarshal(bytes, &rawWide) + // Working Driectory Wide.WD = util.OS.Pwd() glog.V(5).Infof("${pwd} [%s]", Wide.WD) + // IP ip, err := util.Net.LocalIP() if err != nil { glog.Error(err) @@ -292,18 +294,6 @@ func Load(confPath, confIP, confPort, confServer, confChannel string, confDocker glog.V(5).Infof("${ip} [%s]", ip) - if confDocker { - h, err := net.LookupHost("wide") - - if nil != err { - glog.Error(err) - - os.Exit(-1) - } - - ip = h[0] - } - if "" != confIP { ip = confIP } @@ -314,12 +304,16 @@ func Load(confPath, confIP, confPort, confServer, confChannel string, confDocker Wide.Port = confPort } + // Server Wide.Server = strings.Replace(Wide.Server, "{IP}", Wide.IP, 1) if "" != confServer { Wide.Server = confServer } + // Static Server Wide.StaticServer = strings.Replace(Wide.StaticServer, "{IP}", Wide.IP, 1) + + // Channels Wide.EditorChannel = strings.Replace(Wide.EditorChannel, "{IP}", Wide.IP, 1) if "" != confChannel { Wide.EditorChannel = confChannel @@ -337,6 +331,23 @@ func Load(confPath, confIP, confPort, confServer, confChannel string, confDocker 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)