Skip to content

Commit

Permalink
[Experiment] try to bypass issues with go 1.21.x
Browse files Browse the repository at this point in the history
Co-authored-by: Jörn Dreyer <jfd@owncloud.com>

Signed-off-by: Christian Richter <crichter@owncloud.com>
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
dragonchaser authored and butonic committed Sep 25, 2023
1 parent 35d78c9 commit 75d27f4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/go-1.21-compatability.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: make appctx package compatible with go v1.21

Backported fix from edge. See https://tip.golang.org/doc/go1.21#reflect

https://github.com/cs3org/reva/pull/4214
30 changes: 17 additions & 13 deletions pkg/appctx/ctxmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,24 @@ func GetKeyValuesFromCtx(ctx context.Context) map[interface{}]interface{} {
}

func getKeyValue(ctx interface{}, m map[interface{}]interface{}) {
ctxVals := reflect.ValueOf(ctx).Elem()
ctxType := reflect.TypeOf(ctx).Elem()
// This is a dirty hack to run with go 1.21.x
reflectCtxValues := reflect.ValueOf(ctx)
if reflectCtxValues.Kind() != reflect.Struct {
ctxVals := reflectCtxValues.Elem()
ctxType := reflect.TypeOf(ctx).Elem()

if ctxType.Kind() == reflect.Struct {
for i := 0; i < ctxVals.NumField(); i++ {
currField, currIf := extractField(ctxVals, ctxType, i)
switch currField {
case "Context":
getKeyValue(currIf, m)
case "key":
nextField, nextIf := extractField(ctxVals, ctxType, i+1)
if nextField == "val" {
m[currIf] = nextIf
i++
if ctxType.Kind() == reflect.Struct {
for i := 0; i < ctxVals.NumField(); i++ {
currField, currIf := extractField(ctxVals, ctxType, i)
switch currField {
case "Context":
getKeyValue(currIf, m)
case "key":
nextField, nextIf := extractField(ctxVals, ctxType, i+1)
if nextField == "val" {
m[currIf] = nextIf
i++
}
}
}
}
Expand Down

0 comments on commit 75d27f4

Please sign in to comment.