From 1a1a09edfe769a7729ae301e5c7cc8b1a68ed3d8 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 18 Nov 2014 13:34:13 +0800 Subject: [PATCH] cmd args ip and port --- conf/wide.go | 34 +++++++++++++++++++++++++--------- conf/wide.json | 28 +++++++++------------------- main.go | 4 +++- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/conf/wide.go b/conf/wide.go index 09a57e4..f1067ad 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -71,12 +71,13 @@ type Editor struct { // Configuration. type conf struct { IP string // server ip, ${ip} - Server string // server host and port ({IP}:7070) - StaticServer string // static resources server scheme, host and port (http://{IP}:7070) - EditorChannel string // editor channel (ws://{IP}:7070) - OutputChannel string // output channel (ws://{IP}:7070) - ShellChannel string // shell channel(ws://{IP}:7070) - SessionChannel string // wide session channel (ws://{IP}:7070) + Port string // server port + Server string // server host and port ({IP}:{Port}) + StaticServer string // static resources server scheme, host and port (http://{IP}:{Port}) + EditorChannel string // editor channel (ws://{IP}:{Port}) + OutputChannel string // output channel (ws://{IP}:{Port}) + ShellChannel string // shell channel(ws://{IP}:{Port}) + SessionChannel string // wide session channel (ws://{IP}:{Port}) HTTPSessionMaxAge int // HTTP session max age (in seciond) StaticResourceVersion string // version of static resources MaxProcs int // Go max procs @@ -265,7 +266,7 @@ func Save() bool { } // Load loads the configurations from wide.json. -func Load(confPath string) { +func Load(confPath, confIP, confPort string) { bytes, _ := ioutil.ReadFile(confPath) err := json.Unmarshal(bytes, &Wide) @@ -278,6 +279,9 @@ func Load(confPath string) { // keep the raw content json.Unmarshal(bytes, &rawWide) + Wide.WD = util.OS.Pwd() + glog.V(5).Infof("${pwd} [%s]", Wide.WD) + ip, err := util.Net.LocalIP() if err != nil { glog.Error(err) @@ -287,11 +291,16 @@ func Load(confPath string) { glog.V(5).Infof("${ip} [%s]", ip) - Wide.WD = util.OS.Pwd() - glog.V(5).Infof("${pwd} [%s]", Wide.WD) + if "" != confIP { + ip = confIP + } Wide.IP = strings.Replace(Wide.IP, "${ip}", ip, 1) + if "" != confPort { + Wide.Port = confPort + } + Wide.Server = strings.Replace(Wide.Server, "{IP}", Wide.IP, 1) Wide.StaticServer = strings.Replace(Wide.StaticServer, "{IP}", Wide.IP, 1) Wide.EditorChannel = strings.Replace(Wide.EditorChannel, "{IP}", Wide.IP, 1) @@ -299,6 +308,13 @@ func Load(confPath string) { Wide.ShellChannel = strings.Replace(Wide.ShellChannel, "{IP}", Wide.IP, 1) Wide.SessionChannel = strings.Replace(Wide.SessionChannel, "{IP}", Wide.IP, 1) + 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) + Wide.OutputChannel = strings.Replace(Wide.OutputChannel, "{Port}", Wide.Port, 1) + Wide.ShellChannel = strings.Replace(Wide.ShellChannel, "{Port}", Wide.Port, 1) + Wide.SessionChannel = strings.Replace(Wide.SessionChannel, "{Port}", Wide.Port, 1) + glog.V(5).Info("Conf: \n" + string(bytes)) initWorkspaceDirs() diff --git a/conf/wide.json b/conf/wide.json index dc1cf5c..385e52d 100644 --- a/conf/wide.json +++ b/conf/wide.json @@ -1,11 +1,12 @@ { "IP": "${ip}", - "Server": "{IP}:7070", + "Port": "7070", + "Server": "{IP}:{Port}", "StaticServer": "", - "EditorChannel": "ws://{IP}:7070", - "OutputChannel": "ws://{IP}:7070", - "ShellChannel": "ws://{IP}:7070", - "SessionChannel": "ws://{IP}:7070", + "EditorChannel": "ws://{IP}:{Port}", + "OutputChannel": "ws://{IP}:{Port}", + "ShellChannel": "ws://{IP}:{Port}", + "SessionChannel": "ws://{IP}:{Port}", "HTTPSessionMaxAge": 86400, "StaticResourceVersion": "201411171800", "MaxProcs": 4, @@ -27,20 +28,9 @@ "LineHeight": "17px" }, "LatestSessionContent": { - "FileTree": [ - "E:\\Work\\go\\src", - "E:\\Work\\go\\src\\code.google.com\\p", - "E:\\Work\\go\\src\\code.google.com\\p\\go.net", - "E:\\Work\\go\\src\\github.com", - "E:\\Work\\go\\src\\github.com\\88250", - "E:\\Work\\go\\src\\github.com\\88250\\gohtml" - ], - "Files": [ - "E:\\Work\\go\\src\\github.com\\88250\\gohtml\\consts.go", - "E:\\Work\\go\\src\\github.com\\88250\\gohtml\\doc.go", - "E:\\Work\\go\\src\\github.com\\88250\\gohtml\\formatter.go" - ], - "CurrentFile": "E:\\Work\\go\\src\\github.com\\88250\\gohtml\\formatter.go" + "FileTree": [], + "Files": [], + "CurrentFile": "" } } ] diff --git a/main.go b/main.go index 831a007..aecb792 100644 --- a/main.go +++ b/main.go @@ -41,6 +41,8 @@ import ( func init() { // TODO: args confPath := flag.String("conf", "conf/wide.json", "path of wide.json") + confIP := flag.String("ip", "", "ip to visit") + confPort := flag.String("port", "", "port to visit") flag.Set("logtostderr", "true") flag.Set("v", "3") @@ -50,7 +52,7 @@ func init() { event.Load() - conf.Load(*confPath) + conf.Load(*confPath, *confIP, *confPort) conf.FixedTimeCheckEnv() conf.FixedTimeSave()