func AddCommandList() { kmgConsole.AddAction(kmgConsole.Command{ Name: "FileHttpServer", Runner: runFileHttpServer, }) kmgConsole.AddCommandWithName("HttpGet", func() { requestUrl := "" key := "" flag.StringVar(&requestUrl, "url", "", "") flag.StringVar(&key, "key", "", "crypto key use to decrypt respond") flag.Parse() if requestUrl == "" { kmgConsole.ExitOnErr(errors.New("Usage: kmg HttpGet -url http://xxx")) } b := MustUrlGetContent(requestUrl) var err error if key != "" { b, err = kmgCrypto.CompressAndEncryptBytesDecodeV2(kmgCrypto.Get32PskFromString(key), b) if err != nil { panic(err) } } fmt.Print(string(b)) }) }
func main() { //go func(){ // for { // time.Sleep(time.Second) // fmt.Println("sleep") // } //}() //go func(){ // err := http.ListenAndServe(":23456",nil) // if err!=nil{ // panic(err) // } //}() //go func(){ // tun,err:=kmgSys.NewTunNoName() // if err!=nil{ // panic(err) // } // buf:=make([]byte,4096) // _,err=tun.Read(buf) // if err!=nil{ // panic(err) // } //}() //kmgCmd.MustRun("ls") kmgConsole.AddCommandWithName("cmd", cmd) kmgConsole.Main() }
func AddCommandList() { cmdGroup := kmgConsole.NewCommandGroup(). AddCommand(kmgConsole.Command{ Name: "setAndRestart", Desc: "install the service,and restart the service,uninstall and stop if need", Runner: setAndRestartCmd, }).AddCommandWithName( "setAndRestartV1", setAndRestartCmdV1, ).AddCommand(kmgConsole.Command{ Name: "install", Desc: "install the service", Runner: installCmd, }).AddCommand(kmgConsole.Command{ Name: "uninstall", Desc: "uninstall the serivce", Runner: newNameCmd(Uninstall), }).AddCommand(kmgConsole.Command{ Name: "start", Desc: "start the service", Runner: newNameCmd(Start), }).AddCommand(kmgConsole.Command{ Name: "stop", Desc: "stop the service", Runner: newNameCmd(Stop), }).AddCommand(kmgConsole.Command{ Name: "restart", Desc: "restart the service", Runner: newNameCmd(Restart), }) kmgConsole.AddCommand(kmgConsole.Command{ Name: "Service", Runner: cmdGroup.Main, }) kmgConsole.AddCommand(kmgConsole.Command{ Name: "Service.Process", Runner: processCmd, Hidden: true, }) kmgConsole.AddCommandWithName("Service.RunTest", func() { cmd := "" flag.StringVar(&cmd, "c", "kmg service restart kmgServiceTest", "") flag.Parse() wg := sync.WaitGroup{} wg.Add(10) for i := 0; i < 10; i++ { go func() { kmgCmd.MustRunInBash("setsid " + cmd) wg.Done() }() } wg.Wait() }) kmgConsole.AddCommandWithName("Service.TestJob", func() { time.Sleep(time.Second * 3) ServiceStartSuccess() }) kmgConsole.AddCommandWithName("Service.TestJobTimeout", func() { time.Sleep(time.Minute * 10) ServiceStartSuccess() }) }