Skip to content

Commit

Permalink
Updated status api
Browse files Browse the repository at this point in the history
  • Loading branch information
MaartendeKruijf committed Jun 18, 2024
1 parent 34149ea commit e41afc7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"soarca/internal/controller"
"soarca/logger"
"soarca/routes/status"
"soarca/swaggerdocs"
"soarca/utils"

Expand Down Expand Up @@ -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)
Expand Down
38 changes: 38 additions & 0 deletions routes/status/status_api.go
Original file line number Diff line number Diff line change
@@ -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)
}
28 changes: 8 additions & 20 deletions routes/status/status_endpoints.go
Original file line number Diff line number Diff line change
@@ -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)

}
}

0 comments on commit e41afc7

Please sign in to comment.