diff --git a/main.go b/main.go index cd5ac380..8c95ebae 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "soarca/internal/controller" "soarca/logger" + "soarca/routes/status" "soarca/swaggerdocs" "soarca/utils" @@ -49,6 +50,8 @@ func main() { Host = "localhost:" + utils.GetEnv("PORT", "8080") swaggerdocs.SwaggerInfo.Host = Host + // Version is only available here + status.SetVersion(Version) errinit := controller.Initialize() if errinit != nil { log.Fatal("Something Went wrong with setting-up the app, msg: ", errinit) diff --git a/routes/status/status_api.go b/routes/status/status_api.go new file mode 100644 index 00000000..347aecd9 --- /dev/null +++ b/routes/status/status_api.go @@ -0,0 +1,38 @@ +package status + +import ( + "net/http" + "runtime" + "soarca/models/api" + "soarca/utils" + "time" + + "github.com/gin-gonic/gin" +) + +var status = api.Status{Uptime: api.Uptime{Since: time.Now(), Milliseconds: 0}, + Mode: utils.GetEnv("LOG_MODE", "production"), + Runtime: runtime.GOOS} + +func SetVersion(version string) { + status.Version = version +} + +// /Status GET handler for handling status api calls +// Returns the status model object for SOARCA +// +// @Summary gets the SOARCA status +// @Schemes +// @Description return SOARCA status +// @Tags status +// @Produce json +// @success 200 {object} api.Status +// @failure 400 {object} api.Error +// @Router /status [GET] +func Api(g *gin.Context) { + + status.Uptime.Milliseconds = uint64(time.Since(status.Uptime.Since).Milliseconds()) + status.Time = time.Now() + + g.JSON(http.StatusOK, status) +} diff --git a/routes/status/status_endpoints.go b/routes/status/status_endpoints.go index 294afe0c..ff64c802 100644 --- a/routes/status/status_endpoints.go +++ b/routes/status/status_endpoints.go @@ -1,34 +1,22 @@ -package coa +package status import ( - "fmt" "net/http" "github.com/gin-gonic/gin" ) -func Helloworld(g *gin.Context) { - g.JSON(http.StatusOK, "helloworld from /status") -} - -func id_tester(g *gin.Context) { - // Get the value of the 'id' parameter from the URL - id := g.Param("id") - fmt.Println(id) +func Pong(g *gin.Context) { + g.Data(http.StatusOK, "text/plain", []byte("pong")) } // GET /status -// GET /status/playbook -// GET /status/playbook/id -// GET /status/coa/id -// GET /status/history +// GET /status/ping func Routes(route *gin.Engine) { - coa := route.Group("/status") + router := route.Group("/status") { - coa.GET("/", Helloworld) - coa.GET("/playbook/:id", id_tester) - coa.GET("/coa/:id", id_tester) - coa.GET("/history", Helloworld) - // workflow.POST() + router.GET("/", Api) + router.GET("/ping", Pong) + } }