View Javadoc
1   package lv.id.jc.piglatin.actuator;
2   
3   import java.util.function.IntFunction;
4   
5   import org.springframework.boot.actuate.health.Health;
6   import org.springframework.http.HttpStatus;
7   import org.springframework.stereotype.Component;
8   
9   
10  @Component
11  public class HealthFunction implements IntFunction<Health> {
12  
13      /**
14       * Converts an HTTP status code into a Health object that represents the health of a service.
15       *
16       * @param statusCode the HTTP status code to be converted
17       * @return a Health object representing the health of the service
18       */
19      @Override
20      public Health apply(int statusCode) {
21          if (statusCode == HttpStatus.OK.value()) {
22              return Health.up().build();
23          }
24          return Health.down()
25              .withDetail("HTTP Status Code", statusCode)
26              .build();
27      }
28  }