Golang - Dependency Verification

Asked

Viewed 100 times

0

I need to change the get answer below:

    router.GET("/health", func(context *gin.Context) {
    context.JSON(http.StatusOK, gin.H{
        "message": "OK",
    })
})

I need to create a dependency checker. A request must follow the following template:

{
    "status": "OK",
    "message": "Nenhum problema encontrado",
    "dependencies": [
        {
            "name": "DEPENDENCIA",
            "status": "OK",
        }
    ]
}
  • 1

    I do not understand what the problem is, try to describe better where you want to get.

  • Daniel, you need to create a struct with the fields you want, populate them with the information and return as JSON

1 answer

0

Buddy, there are two ways to do this.

Solution 1

Create a structure with everything that needs to be transported, facilitating even handling information within the system.

type Control struct {
    Status string
    Message string
    Dependencies []Dependency
}

type Dependency struct {
    Name string
    Status string
}

myVar := Control{
    Status: "OK",
    Message: "Nenhum problema encontrado",
    Dependencies: [
        Dependency{
            Name: "DEPENDENCIA",
            Status: "OK",
        }
    ]
}

Solution 2

context.JSON(http.StatusOK, gin.H{
    "status": "OK",
    "message": "Nenhum problema encontrado",
    "dependencies": gin.H{
        "name": "DEPENDENCIA",
        "status": "OK",
    }
})

Browser other questions tagged

You are not signed in. Login or sign up in order to post.