Skip to content

Instantly share code, notes, and snippets.

@mayankshah1607
Created October 25, 2021 06:50
Show Gist options
  • Save mayankshah1607/b18db3178176c89fe3ee603e93ac0b34 to your computer and use it in GitHub Desktop.
Save mayankshah1607/b18db3178176c89fe3ee603e93ac0b34 to your computer and use it in GitHub Desktop.
RunOrDie
// RunOrDie starts a client with the provided config or panics if the config
// fails to validate. RunOrDie blocks until leader election loop is
// stopped by ctx or it has stopped holding the leader lease
func RunOrDie(ctx context.Context, lec LeaderElectionConfig) {
le, err := NewLeaderElector(lec)
if err != nil {
panic(err)
}
if lec.WatchDog != nil {
lec.WatchDog.SetLeaderElection(le)
}
le.Run(ctx)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment