<commit_before>package http

import (
	"context"
	"net/http"

	"github.com/vardius/golog"
	"github.com/vardius/gorouter"
	"google.golang.org/grpc"
	healthpb "google.golang.org/grpc/health/grpc_health_v1"
	"google.golang.org/grpc/status"
)

// AddHealthCheckRoutes adds health checks route
func AddHealthCheckRoutes(router gorouter.Router, log golog.Logger, ac *grpc.ClientConn, uc *grpc.ClientConn) {
	// Liveness probes are to indicate that your application is running
	router.GET("/healthz", buildLivenessHandler(log))
	// Readiness is meant to check if your application is ready to serve traffic
	router.GET("/readiness", buildReadinessHandler(log, ac, uc))
}

func buildLivenessHandler(log golog.Logger) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(200)
		w.Write([]byte("ok"))
	}

	return http.HandlerFunc(fn)
}

func buildReadinessHandler(log golog.Logger, ac *grpc.ClientConn, uc *grpc.ClientConn) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {
		status := getStatusCodeFromGRPConnectionHealthCheck(r.Context(), log, ac)
		if status != 200 {
			w.WriteHeader(status)
			return
		}

		status = getStatusCodeFromGRPConnectionHealthCheck(r.Context(), log, uc)
		if status != 200 {
			w.WriteHeader(status)
			return
		}

		w.WriteHeader(200)
		w.Write([]byte("ok"))
	}

	return http.HandlerFunc(fn)
}

func getStatusCodeFromGRPConnectionHealthCheck(ctx context.Context, log golog.Logger, conn *grpc.ClientConn) int {
	resp, err := healthpb.NewHealthClient(conn).Check(ctx, &healthpb.HealthCheckRequest{Service: "auth"})
	if err != nil {
		if stat, ok := status.FromError(err); ok {<commit_msg>Pass service name<commit_after>package http

import (
	"context"
	"net/http"

	"github.com/vardius/golog"
	"github.com/vardius/gorouter"
	"google.golang.org/grpc"
	healthpb "google.golang.org/grpc/health/grpc_health_v1"
	"google.golang.org/grpc/status"
)

// AddHealthCheckRoutes adds health checks route
func AddHealthCheckRoutes(router gorouter.Router, log golog.Logger, ac *grpc.ClientConn, uc *grpc.ClientConn) {
	// Liveness probes are to indicate that your application is running
	router.GET("/healthz", buildLivenessHandler(log))
	// Readiness is meant to check if your application is ready to serve traffic
	router.GET("/readiness", buildReadinessHandler(log, ac, uc))
}

func buildLivenessHandler(log golog.Logger) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(200)
		w.Write([]byte("ok"))
	}

	return http.HandlerFunc(fn)
}

func buildReadinessHandler(log golog.Logger, ac *grpc.ClientConn, uc *grpc.ClientConn) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {
		status := getStatusCodeFromGRPConnectionHealthCheck(r.Context(), log, ac, "auth")
		if status != 200 {
			w.WriteHeader(status)
			return
		}

		status = getStatusCodeFromGRPConnectionHealthCheck(r.Context(), log, uc, "user")
		if status != 200 {
			w.WriteHeader(status)
			return
		}

		w.WriteHeader(200)
		w.Write([]byte("ok"))
	}

	return http.HandlerFunc(fn)
}

func getStatusCodeFromGRPConnectionHealthCheck(ctx context.Context, log golog.Logger, conn *grpc.ClientConn, service string) int {
	resp, err := healthpb.NewHealthClient(conn).Check(ctx, &healthpb.HealthCheckRequest{Service: service})
	if err != nil {
		if stat, ok := status.FromError(err); ok {
{'fraction_non_alphanumeric': 0.1284649776453055, 'fraction_numerical': 0.007749627421758569, 'mean_word_length': 5.003577817531306, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1991149', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1118, 'n_words': 252}