GOLang - Dependency Check

0

I need to change the get response 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 should follow the following template:

{
    "status": "OK",
    "message": "Nenhum problema encontrado",
    "dependencies": [
        {
            "name": "DEPENDENCIA",
            "status": "OK",
        }
    ]
}
    
asked by anonymous 20.05.2016 / 21:27

1 answer

0

Friend, there are two ways to do this.

Solution 1

Create a structure with everything that needs to be transported, making it even easier to manipulate the information inside 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",
    }
})
    
12.01.2017 / 22:42