-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(http-server-go): split sys by platform
- Loading branch information
Showing
9 changed files
with
95 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Folders (A => Z) | ||
build | ||
node_modules | ||
|
||
# Files (A => Z) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
) | ||
|
||
func performOpOnSelf(config *Config, op ServiceOperationType) error { | ||
switch config.sysCmdPkg { | ||
case "exec": | ||
var cmd *exec.Cmd | ||
switch op { | ||
case REBOOT: | ||
cmd = exec.Command("reboot") | ||
case STOP: | ||
cmd = exec.Command("shutdown") | ||
} | ||
return cmd.Run() | ||
case "syscall": | ||
return fmt.Errorf("sysCmdPkg not supported on this OS : %s", config.sysCmdPkg) | ||
default: | ||
return fmt.Errorf("invalid sysCmdPkg : %s", config.sysCmdPkg) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os/exec" | ||
"syscall" | ||
) | ||
|
||
func performOpOnSelf(config *Config, op ServiceOperationType) error { | ||
switch config.sysCmdPkg { | ||
case "exec": | ||
var cmd *exec.Cmd | ||
switch op { | ||
case REBOOT: | ||
cmd = exec.Command("reboot") | ||
case STOP: | ||
cmd = exec.Command("shutdown") | ||
} | ||
return cmd.Run() | ||
case "syscall": | ||
var cmd int | ||
switch op { | ||
case REBOOT: | ||
cmd = syscall.LINUX_REBOOT_CMD_RESTART | ||
case STOP: | ||
cmd = syscall.LINUX_REBOOT_CMD_POWER_OFF | ||
} | ||
return syscall.Reboot(cmd) | ||
default: | ||
return errors.New(fmt.Sprintf("Invalid sysCmdPkg : %s", config.sysCmdPkg)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
) | ||
|
||
func performOpOnSelf(config *Config, op ServiceOperationType) error { | ||
switch config.sysCmdPkg { | ||
case "exec": | ||
var cmd *exec.Cmd | ||
switch op { | ||
case REBOOT: | ||
cmd = exec.Command("shutdown", "/s") | ||
case STOP: | ||
cmd = exec.Command("shutdown", "/r") | ||
} | ||
return cmd.Run() | ||
case "syscall": | ||
return fmt.Errorf("sysCmdPkg not supported on this OS : %s", config.sysCmdPkg) | ||
default: | ||
return fmt.Errorf("Invalid sysCmdPkg : %s", config.sysCmdPkg) | ||
} | ||
} |