Skip to content

Commit 3dc744e

Browse files
predicates/auth: fix array conversion (zalando#2788)
* fix array conversion that was necessary due to golang/go#46505 * preallocate slice Signed-off-by: Alexander Yastrebov <[email protected]>
1 parent 2239849 commit 3dc744e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

predicates/auth/headersha256.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ func (*headerSha256Spec) Create(args []interface{}) (routing.Predicate, error) {
3737
return nil, predicates.ErrInvalidPredicateParameters
3838
}
3939

40-
var hashes [][sha256.Size]byte
41-
for _, arg := range args[1:] {
40+
args = args[1:]
41+
42+
hashes := make([][sha256.Size]byte, 0, len(args))
43+
for _, arg := range args {
4244
hexHash, ok := arg.(string)
4345
if !ok {
4446
return nil, predicates.ErrInvalidPredicateParameters
@@ -50,7 +52,7 @@ func (*headerSha256Spec) Create(args []interface{}) (routing.Predicate, error) {
5052
if len(hash) != sha256.Size {
5153
return nil, predicates.ErrInvalidPredicateParameters
5254
}
53-
hashes = append(hashes, *(*[sha256.Size]byte)(hash)) // https://github.com/golang/go/issues/46505
55+
hashes = append(hashes, ([sha256.Size]byte)(hash))
5456
}
5557

5658
return &headerSha256Predicate{name, hashes}, nil

0 commit comments

Comments
 (0)