mirror of
https://github.com/xinliangnote/go-gin-api.git
synced 2024-04-21 12:31:46 +00:00
40 lines
732 B
Go
40 lines
732 B
Go
package install_handler
|
|
|
|
import (
|
|
"bytes"
|
|
"os/exec"
|
|
"runtime"
|
|
|
|
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
|
)
|
|
|
|
func (h *handler) Restart() core.HandlerFunc {
|
|
return func(c core.Context) {
|
|
shellPath := "./scripts/restart.sh"
|
|
|
|
command := new (exec.Cmd)
|
|
|
|
if runtime.GOOS == "windows" {
|
|
command = exec.Command("cmd", "/C", shellPath)
|
|
} else {
|
|
// runtime.GOOS = linux or darwin
|
|
command = exec.Command("/bin/bash", "-c", shellPath)
|
|
}
|
|
|
|
var stderr bytes.Buffer
|
|
command.Stderr = &stderr
|
|
outPutString := ""
|
|
|
|
output, err := command.Output()
|
|
if err != nil {
|
|
outPutString += stderr.String()
|
|
c.Payload(outPutString)
|
|
return
|
|
}
|
|
|
|
outPutString += string(output)
|
|
|
|
c.Payload(outPutString)
|
|
}
|
|
}
|