Possibility to register app without creating the container

This commit is contained in:
Adam Štrauch 2020-08-18 22:48:09 +02:00
parent 865a9a187e
commit 6d0f6ca130
Signed by: cx
GPG Key ID: 018304FFA8988F8D
1 changed files with 15 additions and 10 deletions

25
main.go
View File

@ -96,7 +96,10 @@ func main() {
})
// Create a new app
// If you add register=1 into query string, it won't start or create any container, just adds record into the database.
e.POST("/v1/apps", func(c echo.Context) error {
registerOnly := c.QueryParam("register") == "1"
app := apps.App{}
err := c.Bind(&app)
if err != nil {
@ -111,18 +114,20 @@ func main() {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
container := docker.Container{
App: &app,
}
if !registerOnly {
container := docker.Container{
App: &app,
}
err = container.Create()
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
err = container.Create()
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
err = container.Start()
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
err = container.Start()
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
}
return c.JSON(http.StatusOK, Message{Message: "ok"})