cmd args ip and port

This commit is contained in:
Liang Ding 2014-11-18 13:34:13 +08:00
parent 56fc7de68a
commit 1a1a09edfe
3 changed files with 37 additions and 29 deletions

View File

@ -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()

View File

@ -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": ""
}
}
]

View File

@ -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()