[Go] use EqualFold instead instead of comparing strings in lower case (#12741)

* use EqualFold instead in the go client

* update samples
This commit is contained in:
William Cheng 2022-06-30 23:09:10 +08:00 committed by GitHub
parent 08108cc4ba
commit c982421495
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 6 additions and 6 deletions

View File

@ -111,7 +111,7 @@ func selectHeaderAccept(accepts []string) string {
// contains is a case insensitive match, finding needle in a haystack
func contains(haystack []string, needle string) bool {
for _, a := range haystack {
if strings.ToLower(a) == strings.ToLower(needle) {
if strings.EqualFold(a, needle) {
return true
}
}

View File

@ -136,7 +136,7 @@ func (h *HttpSignatureAuth) ContextWithValue(ctx context.Context) (context.Conte
}
m := make(map[string]bool)
for _, h := range h.SignedHeaders {
if strings.ToLower(h) == strings.ToLower(HttpHeaderAuthorization) {
if strings.EqualFold(h, HttpHeaderAuthorization) {
return nil, fmt.Errorf("Signed headers cannot include the 'Authorization' header")
}
m[h] = true

View File

@ -119,7 +119,7 @@ func selectHeaderAccept(accepts []string) string {
// contains is a case insensitive match, finding needle in a haystack
func contains(haystack []string, needle string) bool {
for _, a := range haystack {
if strings.ToLower(a) == strings.ToLower(needle) {
if strings.EqualFold(a, needle) {
return true
}
}

View File

@ -104,7 +104,7 @@ func selectHeaderAccept(accepts []string) string {
// contains is a case insensitive match, finding needle in a haystack
func contains(haystack []string, needle string) bool {
for _, a := range haystack {
if strings.ToLower(a) == strings.ToLower(needle) {
if strings.EqualFold(a, needle) {
return true
}
}

View File

@ -122,7 +122,7 @@ func selectHeaderAccept(accepts []string) string {
// contains is a case insensitive match, finding needle in a haystack
func contains(haystack []string, needle string) bool {
for _, a := range haystack {
if strings.ToLower(a) == strings.ToLower(needle) {
if strings.EqualFold(a, needle) {
return true
}
}

View File

@ -145,7 +145,7 @@ func (h *HttpSignatureAuth) ContextWithValue(ctx context.Context) (context.Conte
}
m := make(map[string]bool)
for _, h := range h.SignedHeaders {
if strings.ToLower(h) == strings.ToLower(HttpHeaderAuthorization) {
if strings.EqualFold(h, HttpHeaderAuthorization) {
return nil, fmt.Errorf("Signed headers cannot include the 'Authorization' header")
}
m[h] = true