Skip to content

Commit

Permalink
chore: remove reflection zero type when zero value is known
Browse files Browse the repository at this point in the history
Topic: rm-reflection

Relative: projquay-6620
Signed-off-by: Ross Bryan <[email protected]>
  • Loading branch information
arborite-rh committed Feb 28, 2024
1 parent c39e6d2 commit 7fd04c7
Show file tree
Hide file tree
Showing 3 changed files with 240 additions and 8 deletions.
5 changes: 2 additions & 3 deletions pkg/client/quay/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"io/ioutil"
"net/http"
"net/url"

"github.com/quay/quay-bridge-operator/pkg/utils"
"strings"
)

type QuayClient struct {
Expand Down Expand Up @@ -172,7 +171,7 @@ func (c *QuayClient) newRequest(method, path string, body interface{}) (*http.Re
}

req, err := http.NewRequest(method, u.String(), buf)
if !utils.IsZeroOfUnderlyingType(c.AuthToken) {
if !strings.EqualFold("", c.AuthToken) {
req.Header.Set("Authorization", "Bearer "+c.AuthToken)
}

Expand Down
238 changes: 238 additions & 0 deletions pkg/client/quay/mocks/client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ package utils

import (
"fmt"
"reflect"

"github.com/quay/quay-bridge-operator/pkg/constants"
"github.com/quay/quay-bridge-operator/pkg/logging"
corev1 "k8s.io/api/core/v1"
)

func IsZeroOfUnderlyingType(x interface{}) bool {
return reflect.DeepEqual(x, reflect.Zero(reflect.TypeOf(x)).Interface())
}

func RemoveItemsFromSlice(s []string, r []string) []string {

for i, v := range s {
Expand Down

0 comments on commit 7fd04c7

Please sign in to comment.