From 3a4eb6c8724daf058e6d50108810bcbdbb590235 Mon Sep 17 00:00:00 2001 From: Piotr Icikowski Date: Sun, 6 Mar 2022 23:36:03 +0100 Subject: [PATCH] Refactor functions & types names - `NewKubeprobe` -> `New` - `kubeprobesOption` -> `option` --- README.md | 10 +++++----- probes.go | 10 +++++----- probes_test.go | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 33e1d4f..313697a 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ go get -u github.com/Icikowski/kubeprobes ## Usage -The package provides `kubeprobes.NewKubeprobes` function which returns a probes handler compliant with `http.Handler` interface. +The package provides `kubeprobes.New` function which returns a probes handler compliant with `http.Handler` interface. The handler serves two endpoints, which are used to implement liveness and readiness probes by returning either `200` (healthy) or `503` (unhealthy) status: @@ -25,7 +25,7 @@ The handler serves two endpoints, which are used to implement liveness and readi Accessing any other endpoint will return `404` status. In order to provide maximum performance, no body is ever returned. -The `kubeprobes.NewKubeprobes` function accepts following options-applying functions as arguments: +The `kubeprobes.New` function accepts following options-applying functions as arguments: - `kubeprobes.WithLivenessProbes(/* ... */)` - adds particular [probes](#probes) to the list of liveness probes; - `kubeprobes.WithReadinessProbes(/* ... */)` - adds particular [probes](#probes) to the list of readiness probes. @@ -53,7 +53,7 @@ someOtherProbe := func() error { } // Use functions in probes handler -kp := kubeprobes.NewKubeprobes( +kp := kubeprobes.New( kubeprobes.WithLivenessProbes(someOtherProbe), kubeprobes.WithReadinessProbes(someProbe), ) @@ -69,7 +69,7 @@ someProbe := kubeprobes.NewStatefulProbe() someOtherProbe := kubeprobes.NewStatefulProbe() // Use it in probes handler -kp := kubeprobes.NewKubeprobes( +kp := kubeprobes.New( kubeprobes.WithLivenessProbes(someProbe.GetProbeFunction()), kubeprobes.WithReadinessProbes(someOtherProbe.GetProbeFunction()), ) @@ -83,7 +83,7 @@ live := kubeprobes.NewStatefulProbe() ready := kubeprobes.NewStatefulProbe() // Prepare handler -kp := kubeprobes.NewKubeprobes( +kp := kubeprobes.New( kubeprobes.WithLivenessProbes(live.GetProbeFunction()), kubeprobes.WithReadinessProbes(ready.GetProbeFunction()), ) diff --git a/probes.go b/probes.go index 8160f7a..27d8802 100644 --- a/probes.go +++ b/probes.go @@ -31,10 +31,10 @@ func (kp *kubeprobes) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } -type kubeprobesOption func(*kubeprobes) +type option func(*kubeprobes) -// NewKubeprobes returns a new instance of a Kubernetes probes -func NewKubeprobes(options ...kubeprobesOption) *kubeprobes { +// New returns a new instance of a Kubernetes probes +func New(options ...option) *kubeprobes { kp := &kubeprobes{ livenessProbes: []ProbeFunction{}, readinessProbes: []ProbeFunction{}, @@ -48,14 +48,14 @@ func NewKubeprobes(options ...kubeprobesOption) *kubeprobes { } // WithLivenessProbes adds given liveness probes to the set of probes -func WithLivenessProbes(probes ...ProbeFunction) kubeprobesOption { +func WithLivenessProbes(probes ...ProbeFunction) option { return func(kp *kubeprobes) { kp.livenessProbes = append(kp.livenessProbes, probes...) } } // WithReadinessProbes adds given readiness probes to the set of probes -func WithReadinessProbes(probes ...ProbeFunction) kubeprobesOption { +func WithReadinessProbes(probes ...ProbeFunction) option { return func(kp *kubeprobes) { kp.readinessProbes = append(kp.readinessProbes, probes...) } diff --git a/probes_test.go b/probes_test.go index a55a591..ef8c3af 100644 --- a/probes_test.go +++ b/probes_test.go @@ -50,7 +50,7 @@ func TestKubeprobes(t *testing.T) { }, } - kp := NewKubeprobes( + kp := New( WithLivenessProbes(live.GetProbeFunction()), WithReadinessProbes(ready.GetProbeFunction()), )