From 9c1c957e58f2e49c4ea4fe168db562c93d504beb Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Thu, 6 Jun 2024 15:08:45 +0200 Subject: [PATCH] Fix Typos --- auth/kubeconfig.go | 2 +- bus/doc.go | 2 +- bus/eventbus_test.go | 2 +- bus/functools.go | 10 ++--- bus/functools_test.go | 4 +- bus/testenv/README.md | 2 +- jwt/sec/plugin.go | 5 ++- pkg/genericcli/cmds.go | 4 +- pkg/genericcli/printers/csv.go | 2 +- pkg/genericcli/printers/table.go | 2 +- pkg/genericcli/truncate.go | 44 ++++++++++----------- pkg/genericcli/truncate_test.go | 68 ++++++++++++++++---------------- pkg/multisort/multisorter.go | 2 +- 13 files changed, 75 insertions(+), 74 deletions(-) diff --git a/auth/kubeconfig.go b/auth/kubeconfig.go index 07de3e3..9b7a3a6 100644 --- a/auth/kubeconfig.go +++ b/auth/kubeconfig.go @@ -12,7 +12,7 @@ import ( ) // -// kubeconfig provides methods to read and write kuberentes kubectl-config-files. +// kubeconfig provides methods to read and write kubernetes kubectl-config-files. // It must not depend on the k8s.io-client due to the dependency-hell surrounding it. // So we tried to be generic and structure agnostic, so that we can read a config, // modify just the parts we need and write it back and do not loose anything, diff --git a/bus/doc.go b/bus/doc.go index 1b0f38d..cbd73eb 100644 --- a/bus/doc.go +++ b/bus/doc.go @@ -13,7 +13,7 @@ parameters as JSON and invoke the corresponding function with nsq. You can start many services which implement the same function (identified by its name), so you will have something like a balancing. Note: As the functions are asynchronuous, you cannot return a result. Only errors - are used to signal if the function was successfull. + are used to signal if the function was successful. When you create a function with `Unique` the consumer will be connected to a unique, ephemeral topic and channel. Create unique functions if you want your services to respond with values. You diff --git a/bus/eventbus_test.go b/bus/eventbus_test.go index 5a439dd..b9d4187 100644 --- a/bus/eventbus_test.go +++ b/bus/eventbus_test.go @@ -65,7 +65,7 @@ func TestTimeoutWrapper_FailTimeoutWithTimeoutFunc(t *testing.T) { err := twTimeout.handleWithTimeout(messageFromQueue) if err != nil { - t.Errorf("no error expected because the onTimeout retuns nil") + t.Errorf("no error expected because the onTimeout returns nil") } if !handlerCalled { t.Errorf("timeoutfunction expected ") diff --git a/bus/functools.go b/bus/functools.go index 4a2f1f7..e0d5eb7 100644 --- a/bus/functools.go +++ b/bus/functools.go @@ -75,7 +75,7 @@ func (e *Endpoints) Client(name string) (*Function, Func, error) { return e.function(name, "function", nil) } -// Unique uses an unique, ephemeral topic so the topic will be deregisted when there is no +// Unique uses an unique, ephemeral topic so the topic will be deregistered when there is no // consumer any more for this function. Use this function to create a unique receiver, so function // invocations will not be distributed and the topic only exists as long as the registration // process is active. The computed unique name of this function is returned so it can be used with the @@ -164,20 +164,20 @@ func (f *Function) receive(par interface{}) error { pkind = f.fn.Type().In(0).Kind() } - parms := []reflect.Value{v} + params := []reflect.Value{v} if vkind != pkind { if pkind == reflect.Ptr { // function wants a ptr but we got a value // --> copy value and pass pointer to this copy nv := reflect.New(reflect.TypeOf(par)) nv.Elem().Set(v) - parms = []reflect.Value{nv} + params = []reflect.Value{nv} } else if vkind == reflect.Ptr { // function wants value - parms = []reflect.Value{v.Elem()} + params = []reflect.Value{v.Elem()} } } - res := f.fn.Call(parms) + res := f.fn.Call(params) if res[0].IsNil() { return nil } diff --git a/bus/functools_test.go b/bus/functools_test.go index def12d0..6dec089 100644 --- a/bus/functools_test.go +++ b/bus/functools_test.go @@ -135,7 +135,7 @@ func TestTwoProcessesFunctionHelloWorld(t *testing.T) { cmd.Env = append([]string{"PUBLISH=1", "NO_NSQD_START=1"}, os.Environ()...) out, err := cmd.CombinedOutput() if err != nil { - log.Fatalf("error occured: %s", string(out)) + log.Fatalf("error occurred: %s", string(out)) } }() var wg sync.WaitGroup @@ -191,7 +191,7 @@ func TestUniqueTargetFunctionWithResponse(t *testing.T) { cmd.Env = append([]string{"PRODUCER=1", "NO_NSQD_START=1"}, os.Environ()...) out, err := cmd.CombinedOutput() if err != nil { - log.Fatalf("error occured: %s", string(out)) + log.Fatalf("error occurred: %s", string(out)) } }() var wg sync.WaitGroup diff --git a/bus/testenv/README.md b/bus/testenv/README.md index aea26fd..622539a 100644 --- a/bus/testenv/README.md +++ b/bus/testenv/README.md @@ -31,7 +31,7 @@ We can now connect to NSQD and create a test topic: curl -v -X POST --key client_key.pem --cert client_cert.pem --cacert server_cert.pem --resolve metal-control-plane-nsqd:4152:127.0.0.1 https://metal-control-plane-nsqd:4152/topic/create?topic=test ``` -Verifiy with +Verify with ``` curl -v --key client_key.pem --cert client_cert.pem --cacert server_cert.pem --resolve metal-control-plane-nsqd:4152:127.0.0.1 https://metal-control-plane-nsqd:4152/stats?format=json&topic=test diff --git a/jwt/sec/plugin.go b/jwt/sec/plugin.go index 99e8a28..1b608c6 100644 --- a/jwt/sec/plugin.go +++ b/jwt/sec/plugin.go @@ -2,9 +2,10 @@ package sec import ( "errors" + "strings" + "github.com/metal-stack/metal-lib/jwt/grp" "github.com/metal-stack/security" - "strings" ) const OidcDirectory = "oidc.metal-stack.io/directory" @@ -160,7 +161,7 @@ func (p *Plugin) HasGroupExpression(user *security.User, resourceTenant string, continue } - // check if group maches for any of the tenants + // check if group matches for any of the tenants if resourceTenant == grp.Any { if groupExpression.Matches(*grpCtx) { return true diff --git a/pkg/genericcli/cmds.go b/pkg/genericcli/cmds.go index cbbb3d3..7774201 100644 --- a/pkg/genericcli/cmds.go +++ b/pkg/genericcli/cmds.go @@ -61,9 +61,9 @@ type CmdsConfig[C any, U any, R any] struct { // Aliases provides additional aliases for the root cmd. Aliases []string - // DescribePrinter is the printer that is used for describing the entity. It's a function because printers potentially get intialized later in the game. + // DescribePrinter is the printer that is used for describing the entity. It's a function because printers potentially get initialized later in the game. DescribePrinter func() printers.Printer - // ListPrinter is the printer that is used for listing multiple entities. It's a function because printers potentially get intialized later in the game. + // ListPrinter is the printer that is used for listing multiple entities. It's a function because printers potentially get initialized later in the game. ListPrinter func() printers.Printer // CreateRequestFromCLI if not nil, this function uses the returned create request to create the entity. diff --git a/pkg/genericcli/printers/csv.go b/pkg/genericcli/printers/csv.go index b7a62ee..bedf534 100644 --- a/pkg/genericcli/printers/csv.go +++ b/pkg/genericcli/printers/csv.go @@ -16,7 +16,7 @@ type CSVPrinter struct { type CSVPrinterConfig struct { // ToHeaderAndRows is called during print to obtain the headers and rows for the given data. ToHeaderAndRows func(data any) ([]string, [][]string, error) - // NoHeaders will omit headers during pring when set to true + // NoHeaders will omit headers during print when set to true NoHeaders bool // Out defines the output writer for the printer, will default to os.stdout Out io.Writer diff --git a/pkg/genericcli/printers/table.go b/pkg/genericcli/printers/table.go index 1db9e3b..01f079a 100644 --- a/pkg/genericcli/printers/table.go +++ b/pkg/genericcli/printers/table.go @@ -23,7 +23,7 @@ type TablePrinterConfig struct { Wide bool // Markdown will print the table in Markdown format Markdown bool - // NoHeaders will omit headers during pring when set to true + // NoHeaders will omit headers during print when set to true NoHeaders bool // Out defines the output writer for the printer, will default to os.stdout Out io.Writer diff --git a/pkg/genericcli/truncate.go b/pkg/genericcli/truncate.go index fa7d080..48860d7 100644 --- a/pkg/genericcli/truncate.go +++ b/pkg/genericcli/truncate.go @@ -6,23 +6,23 @@ type Truncatable interface { ~string } -const TruncateElipsis = "..." +const TruncateEllipsis = "..." // TruncateMiddle will trim a string in the middle. func TruncateMiddle[T Truncatable](input T, maxlength int) T { - return TruncateMiddleElipsis(input, TruncateElipsis, maxlength) + return TruncateMiddleEllipsis(input, TruncateEllipsis, maxlength) } -// TruncateMiddleElipsis will trim a string in the middle and replace it with elipsis. -func TruncateMiddleElipsis[T Truncatable](input T, elipsis T, maxlength int) T { - if elipsis == "" { - elipsis = TruncateElipsis +// TruncateMiddleEllipsis will trim a string in the middle and replace it with ellipsis. +func TruncateMiddleEllipsis[T Truncatable](input T, ellipsis T, maxlength int) T { + if ellipsis == "" { + ellipsis = TruncateEllipsis } if maxlength < 0 || len(input) <= maxlength { return input } - finalLength := float64(maxlength - len(elipsis)) + finalLength := float64(maxlength - len(ellipsis)) if finalLength <= 0 { return input[:maxlength] } @@ -31,49 +31,49 @@ func TruncateMiddleElipsis[T Truncatable](input T, elipsis T, maxlength int) T { start = int(math.Ceil(finalLength / 2)) end = int(math.Floor(finalLength / 2)) ) - return input[:start] + elipsis + input[len(input)-end:] + return input[:start] + ellipsis + input[len(input)-end:] } // TruncateEnd will trim a string at the end. func TruncateEnd[T Truncatable](input T, maxlength int) T { - return TruncateEndElipsis(input, TruncateElipsis, maxlength) + return TruncateEndEllipsis(input, TruncateEllipsis, maxlength) } -// TruncateEndElipsis will trim a string at the end and replace it with elipsis. -func TruncateEndElipsis[T Truncatable](input T, elipsis T, maxlength int) T { - if elipsis == "" { - elipsis = TruncateElipsis +// TruncateEndEllipsis will trim a string at the end and replace it with ellipsis. +func TruncateEndEllipsis[T Truncatable](input T, ellipsis T, maxlength int) T { + if ellipsis == "" { + ellipsis = TruncateEllipsis } if maxlength < 0 || len(input) <= maxlength { return input } - finalLength := maxlength - len(elipsis) + finalLength := maxlength - len(ellipsis) if finalLength <= 0 { return input[:maxlength] } - return input[:finalLength] + elipsis + return input[:finalLength] + ellipsis } // TruncateStart will trim a string at the start. func TruncateStart[T Truncatable](input T, maxlength int) T { - return TruncateStartElipsis(input, TruncateElipsis, maxlength) + return TruncateStartEllipsis(input, TruncateEllipsis, maxlength) } -// TruncateStartElipsis will trim a string at the start and replace it with elipsis. -func TruncateStartElipsis[T Truncatable](input T, elipsis T, maxlength int) T { - if elipsis == "" { - elipsis = TruncateElipsis +// TruncateStartEllipsis will trim a string at the start and replace it with ellipsis. +func TruncateStartEllipsis[T Truncatable](input T, ellipsis T, maxlength int) T { + if ellipsis == "" { + ellipsis = TruncateEllipsis } if maxlength < 0 || len(input) <= maxlength { return input } - finalLength := maxlength - len(elipsis) + finalLength := maxlength - len(ellipsis) if finalLength <= 0 { return input[len(input)-maxlength:] } - return elipsis + input[len(input)-finalLength:] + return ellipsis + input[len(input)-finalLength:] } diff --git a/pkg/genericcli/truncate_test.go b/pkg/genericcli/truncate_test.go index 7e5f2a4..6bf5bb3 100644 --- a/pkg/genericcli/truncate_test.go +++ b/pkg/genericcli/truncate_test.go @@ -6,53 +6,53 @@ import ( "github.com/google/go-cmp/cmp" ) -func TestTruncateMiddleElipsis(t *testing.T) { +func TestTruncateMiddleEllipsis(t *testing.T) { tests := []struct { name string input string - elipsis string + ellipsis string maxlength int want string }{ { name: "no trunc on short enough input", input: "0123456789", - elipsis: TruncateElipsis, + ellipsis: TruncateEllipsis, maxlength: 10, want: "0123456789", }, { - name: "even elipsis is in the middle on even length", + name: "even ellipsis is in the middle on even length", input: "0123456789", - elipsis: "..", + ellipsis: "..", maxlength: 6, want: "01..89", }, { - name: "even elipsis is slightly to the right on odd length", + name: "even ellipsis is slightly to the right on odd length", input: "0123456789", - elipsis: "..", + ellipsis: "..", maxlength: 7, want: "012..89", }, { - name: "odd elipsis is in the middle on odd length", + name: "odd ellipsis is in the middle on odd length", input: "0123456789", - elipsis: TruncateElipsis, + ellipsis: TruncateEllipsis, maxlength: 7, want: "01...89", }, { - name: "odd elipsis is slightly on the right on even length", + name: "odd ellipsis is slightly on the right on even length", input: "0123456789", - elipsis: TruncateElipsis, + ellipsis: TruncateEllipsis, maxlength: 6, want: "01...9", }, { - name: "too long elipsis does not increase final length", + name: "too long ellipsis does not increase final length", input: "0123456789", - elipsis: "..........", + ellipsis: "..........", maxlength: 6, want: "012345", }, @@ -60,7 +60,7 @@ func TestTruncateMiddleElipsis(t *testing.T) { for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { - got := TruncateMiddleElipsis(tt.input, tt.elipsis, tt.maxlength) + got := TruncateMiddleEllipsis(tt.input, tt.ellipsis, tt.maxlength) if diff := cmp.Diff(tt.want, got); diff != "" { t.Errorf("diff (+got -want):\n %s", diff) } @@ -68,39 +68,39 @@ func TestTruncateMiddleElipsis(t *testing.T) { } } -func TestTruncateEndElipsis(t *testing.T) { +func TestTruncateEndellipsis(t *testing.T) { tests := []struct { name string input string - elipsis string + ellipsis string maxlength int want string }{ { name: "no trunc on short enough input", input: "0123456789", - elipsis: TruncateElipsis, + ellipsis: TruncateEllipsis, maxlength: 10, want: "0123456789", }, { - name: "even elipsis", + name: "even ellipsis", input: "0123456789", - elipsis: "..", + ellipsis: "..", maxlength: 6, want: "0123..", }, { - name: "odd elipsis", + name: "odd ellipsis", input: "0123456789", - elipsis: "...", + ellipsis: "...", maxlength: 7, want: "0123...", }, { - name: "too long elipsis does not increase final length", + name: "too long ellipsis does not increase final length", input: "0123456789", - elipsis: "..........", + ellipsis: "..........", maxlength: 6, want: "012345", }, @@ -108,7 +108,7 @@ func TestTruncateEndElipsis(t *testing.T) { for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { - got := TruncateEndElipsis(tt.input, tt.elipsis, tt.maxlength) + got := TruncateEndEllipsis(tt.input, tt.ellipsis, tt.maxlength) if diff := cmp.Diff(tt.want, got); diff != "" { t.Errorf("diff (+got -want):\n %s", diff) } @@ -116,39 +116,39 @@ func TestTruncateEndElipsis(t *testing.T) { } } -func TestTruncateStartElipsis(t *testing.T) { +func TestTruncateStartellipsis(t *testing.T) { tests := []struct { name string input string - elipsis string + ellipsis string maxlength int want string }{ { name: "no trunc on short enough input", input: "0123456789", - elipsis: TruncateElipsis, + ellipsis: TruncateEllipsis, maxlength: 10, want: "0123456789", }, { - name: "even elipsis", + name: "even ellipsis", input: "0123456789", - elipsis: "..", + ellipsis: "..", maxlength: 6, want: "..6789", }, { - name: "odd elipsis", + name: "odd ellipsis", input: "0123456789", - elipsis: "...", + ellipsis: "...", maxlength: 7, want: "...6789", }, { - name: "too long elipsis does not increase final length", + name: "too long ellipsis does not increase final length", input: "0123456789", - elipsis: "..........", + ellipsis: "..........", maxlength: 6, want: "456789", }, @@ -156,7 +156,7 @@ func TestTruncateStartElipsis(t *testing.T) { for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { - got := TruncateStartElipsis(tt.input, tt.elipsis, tt.maxlength) + got := TruncateStartEllipsis(tt.input, tt.ellipsis, tt.maxlength) if diff := cmp.Diff(tt.want, got); diff != "" { t.Errorf("diff (+got -want):\n %s", diff) } diff --git a/pkg/multisort/multisorter.go b/pkg/multisort/multisorter.go index 15212b9..930e85f 100644 --- a/pkg/multisort/multisorter.go +++ b/pkg/multisort/multisorter.go @@ -12,7 +12,7 @@ type Sorter[E any] struct { fields FieldMap[E] } -// FieldMap defines the fields that the sorter is capable to sort and provides the corresponsing compare funcs. +// FieldMap defines the fields that the sorter is capable to sort and provides the corresponding compare funcs. type FieldMap[E any] map[string]CompareFn[E] // Key is the key that will be sorted by.