mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-01 09:52:23 -06:00
24 lines
531 B
Go
24 lines
531 B
Go
package checks
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/nats-io/nats.go"
|
|
)
|
|
|
|
// NewNatsCheck checks the reachability of a nats server.
|
|
func NewNatsCheck(natsCluster string, options ...nats.Option) func(context.Context) error {
|
|
return func(_ context.Context) error {
|
|
n, err := nats.Connect(natsCluster, options...)
|
|
if err != nil {
|
|
return fmt.Errorf("could not connect to nats server: %v", err)
|
|
}
|
|
defer n.Close()
|
|
if n.Status() != nats.CONNECTED {
|
|
return fmt.Errorf("nats server not connected")
|
|
}
|
|
return nil
|
|
}
|
|
}
|