start service through api
This commit is contained in:
11
docs/docs.go
11
docs/docs.go
@@ -40,6 +40,17 @@ const docTemplate = `{
|
|||||||
"api"
|
"api"
|
||||||
],
|
],
|
||||||
"summary": "Return API",
|
"summary": "Return API",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "required",
|
||||||
|
"name": "name",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "OK",
|
||||||
|
|||||||
@@ -29,6 +29,17 @@
|
|||||||
"api"
|
"api"
|
||||||
],
|
],
|
||||||
"summary": "Return API",
|
"summary": "Return API",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "required",
|
||||||
|
"name": "name",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "OK",
|
||||||
|
|||||||
@@ -16,6 +16,13 @@ paths:
|
|||||||
- api
|
- api
|
||||||
post:
|
post:
|
||||||
description: Return API
|
description: Return API
|
||||||
|
parameters:
|
||||||
|
- description: required
|
||||||
|
in: body
|
||||||
|
name: name
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
|
|||||||
@@ -46,14 +46,23 @@ func (ac *ApiController) getFirst(c *fiber.Ctx) error {
|
|||||||
//
|
//
|
||||||
// @Summary Return API
|
// @Summary Return API
|
||||||
// @Description Return API
|
// @Description Return API
|
||||||
|
// @Param name body string true "required"
|
||||||
// @Tags api
|
// @Tags api
|
||||||
// @Success 200 {array} string
|
// @Success 200 {array} string
|
||||||
// @Router /v1/api [post]
|
// @Router /v1/api [post]
|
||||||
func (ac *ApiController) startServer(c *fiber.Ctx) error {
|
func (ac *ApiController) startServer(c *fiber.Ctx) error {
|
||||||
c.Locals("service", "ACC-Server")
|
model := new(Service)
|
||||||
|
if err := c.BodyParser(model); err != nil {
|
||||||
|
c.SendStatus(400)
|
||||||
|
}
|
||||||
|
c.Locals("service", model.Name)
|
||||||
apiModel, err := ac.service.ApiStartServer(c)
|
apiModel, err := ac.service.ApiStartServer(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.SendStatus(400)
|
return c.SendStatus(400)
|
||||||
}
|
}
|
||||||
return c.SendString(apiModel)
|
return c.SendString(apiModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Service struct {
|
||||||
|
Name string `json:"name" xml:"name" form:"name"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -58,10 +58,11 @@ func Find[T any](lst *[]T, callback func(item *T) bool) *T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RunElevatedCommand(command string, service string) (string, error) {
|
func RunElevatedCommand(command string, service string) (string, error) {
|
||||||
cmd := exec.Command("powershell", "-File", "run_sc.ps1", command, service)
|
cmd := exec.Command("powershell", "-nologo", "-noprofile", "-File", "run_sc.ps1", command, service)
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error: %v, output: %s", err, output)
|
log.Panic("error: %v, output: %s", err, string(output))
|
||||||
|
return "", fmt.Errorf("error: %v, output: %s", err, string(output))
|
||||||
}
|
}
|
||||||
return string(output), nil
|
return string(output), nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user