修改flag解析参数 "-n 1 -i 1" to "-n1 -i1"
This commit is contained in:
parent
3584ff5e7e
commit
0ff73b5f57
36
app.go
36
app.go
@ -1,9 +1,10 @@
|
|||||||
package f5
|
package f5
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"q5"
|
"q5"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@ -75,10 +76,7 @@ func (this *app) init(userApp UserApp) {
|
|||||||
_httpCliMgr = new(HttpCliMgr)
|
_httpCliMgr = new(HttpCliMgr)
|
||||||
_httpCliMgr.init()
|
_httpCliMgr.init()
|
||||||
{
|
{
|
||||||
var tmpNodeId, tmpInstanceId int
|
tmpNodeId, tmpInstanceId := parseArgs()
|
||||||
flag.IntVar(&tmpNodeId, "n", 0, "node id")
|
|
||||||
flag.IntVar(&tmpInstanceId, "i", 0, "instance id")
|
|
||||||
flag.Parse()
|
|
||||||
this.nodeId = int32(tmpNodeId)
|
this.nodeId = int32(tmpNodeId)
|
||||||
this.instanceId = int32(tmpInstanceId)
|
this.instanceId = int32(tmpInstanceId)
|
||||||
}
|
}
|
||||||
@ -256,3 +254,31 @@ func (this *app) installTimer() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseArgs() (int, int) {
|
||||||
|
args := os.Args[1:]
|
||||||
|
if len(args) <= 0 {
|
||||||
|
return 0, 0
|
||||||
|
}
|
||||||
|
var nodeId, instanceId int
|
||||||
|
for i := 0; i < len(args); i++ {
|
||||||
|
arg := args[i]
|
||||||
|
if strings.HasPrefix(arg, "-n") {
|
||||||
|
if len(arg) > 2 {
|
||||||
|
fmt.Sscanf(arg[2:], "%d", &nodeId)
|
||||||
|
} else if i+1 < len(args) {
|
||||||
|
fmt.Sscanf(args[i+1], "%d", &nodeId)
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
} else if strings.HasPrefix(arg, "-i") {
|
||||||
|
if len(arg) > 2 {
|
||||||
|
fmt.Sscanf(arg[2:], "%d", &instanceId)
|
||||||
|
} else if i+1 < len(args) {
|
||||||
|
fmt.Sscanf(args[i+1], "%d", &instanceId)
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodeId, instanceId
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user