Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
41
pkg/health/kafka.go
Normal file
41
pkg/health/kafka.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package health
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type GetKafkaConsumerFunc func() (KafkaConnCheckInterface, error)
|
||||
|
||||
func NewKafkaCheck(fn GetKafkaConsumerFunc) CheckFunc {
|
||||
return func(ctx context.Context) error {
|
||||
conn, err := fn()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return conn.Check(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
type KafkaConnCheckInterface interface {
|
||||
Check(ctx context.Context) error
|
||||
}
|
||||
|
||||
type GetMultiKafkaConsumerFunc func() ([]KafkaConnCheckInterface, error)
|
||||
|
||||
func NewKafkaMultiCheck(fn GetMultiKafkaConsumerFunc) CheckFunc {
|
||||
return func(ctx context.Context) error {
|
||||
conns, err := fn()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, connection := range conns {
|
||||
err = connection.Check(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user