Skip to content
This repository has been archived by the owner on Jul 22, 2023. It is now read-only.

Commit

Permalink
Refactor functions & types names
Browse files Browse the repository at this point in the history
- `NewKubeprobe` -> `New`
- `kubeprobesOption` -> `option`
  • Loading branch information
Icikowski committed Mar 6, 2022
1 parent 1b1a9b8 commit 3a4eb6c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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.
Expand Down Expand Up @@ -53,7 +53,7 @@ someOtherProbe := func() error {
}

// Use functions in probes handler
kp := kubeprobes.NewKubeprobes(
kp := kubeprobes.New(
kubeprobes.WithLivenessProbes(someOtherProbe),
kubeprobes.WithReadinessProbes(someProbe),
)
Expand All @@ -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()),
)
Expand All @@ -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()),
)
Expand Down
10 changes: 5 additions & 5 deletions probes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand All @@ -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...)
}
Expand Down
2 changes: 1 addition & 1 deletion probes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestKubeprobes(t *testing.T) {
},
}

kp := NewKubeprobes(
kp := New(
WithLivenessProbes(live.GetProbeFunction()),
WithReadinessProbes(ready.GetProbeFunction()),
)
Expand Down

0 comments on commit 3a4eb6c

Please sign in to comment.