start server

This commit is contained in:
Fran Jurmanović
2024-07-11 19:07:55 +02:00
parent 8307a60913
commit 475a2bb4c4
6 changed files with 83 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package service
import (
"acc-server-manager/local/utl/configs"
"os/exec"
"github.com/gofiber/fiber/v2"
)
@@ -26,3 +27,19 @@ Gets first row from API table.
func (as ApiService) GetFirst(ctx *fiber.Ctx) string {
return configs.Version
}
func (as ApiService) StartServer(ctx *fiber.Ctx) (string, error) {
service, ok := ctx.Locals("service").(string)
print(service)
if !ok {
return "", fiber.NewError(400)
}
cmd := exec.Command("sc", "start", service)
output, err := cmd.CombinedOutput()
print(string(output[:]))
if err != nil {
return "", fiber.NewError(500)
}
return string(output[:]), nil
}