Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Pathfinder
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Libraries
Go
Utilities
Pathfinder
Compare revisions
v0.3.0 to v0.3.1
You need to sign in or sign up before continuing.
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
oss/libraries/go/utilities/pathfinder
Select target project
No results found
v0.3.1
Select Git revision
Swap
Target
oss/libraries/go/utilities/pathfinder
Select target project
oss/libraries/go/utilities/pathfinder
1 result
v0.3.0
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (3)
fix secure access to structure with a constraint
· b2d96812
Volker Schukai
authored
2 years ago
b2d96812
Bump version to 0.3.1
· 236cceae
Volker Schukai
authored
2 years ago
236cceae
Update changelog
· da76851d
Volker Schukai
authored
2 years ago
da76851d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
CHANGELOG.md
+7
-0
7 additions, 0 deletions
CHANGELOG.md
get.go
+51
-0
51 additions, 0 deletions
get.go
release.json
+1
-1
1 addition, 1 deletion
release.json
set.go
+3
-39
3 additions, 39 deletions
set.go
set_test.go
+0
-0
0 additions, 0 deletions
set_test.go
with
62 additions
and
40 deletions
CHANGELOG.md
View file @
da76851d
<a
name=
"v0.3.1"
></a>
## [v0.3.1] - 2022-10-16
### Bug Fixes
-
fix secure access to structure with a constraint
<a
name=
"v0.3.0"
></a>
## [v0.3.0] - 2022-10-15
### Code Refactoring
...
...
@@ -11,4 +17,5 @@
-
feat takeover from other project
[
v0.3.1
]:
https://gitlab.schukai.com/oss/libraries/go/utilities/pathfinder/compare/v0.3.0...v0.3.1
[
v0.3.0
]:
https://gitlab.schukai.com/oss/libraries/go/utilities/pathfinder/compare/v0.2.0...v0.3.0
This diff is collapsed.
Click to expand it.
get.go
0 → 100644
View file @
da76851d
// Copyright 2022 schukai GmbH
// SPDX-License-Identifier: AGPL-3.0
package
pathfinder
import
(
"reflect"
"strings"
)
// This function returns the value of a field in a struct, given a path to the field.
func
GetValue
[
D
any
](
obj
D
,
keyWithDots
string
)
(
any
,
error
)
{
keySlice
:=
strings
.
Split
(
keyWithDots
,
"."
)
v
:=
reflect
.
ValueOf
(
obj
)
for
_
,
key
:=
range
keySlice
[
0
:
len
(
keySlice
)
-
1
]
{
for
v
.
Kind
()
==
reflect
.
Ptr
{
if
v
.
Kind
()
==
reflect
.
Invalid
{
return
nil
,
newInvalidPathError
(
keyWithDots
)
}
v
=
v
.
Elem
()
}
if
v
.
Kind
()
!=
reflect
.
Struct
{
return
nil
,
newUnsupportedTypePathError
(
keyWithDots
,
v
.
Type
())
}
v
=
v
.
FieldByName
(
key
)
}
if
v
.
Kind
()
==
reflect
.
Invalid
{
return
nil
,
newInvalidPathError
(
keyWithDots
)
}
for
v
.
Kind
()
==
reflect
.
Ptr
{
v
=
v
.
Elem
()
}
// non-supporter type at the top of the path
if
v
.
Kind
()
!=
reflect
.
Struct
{
return
nil
,
newUnsupportedTypeAtTopOfPathError
(
keyWithDots
,
v
.
Type
())
}
v
=
v
.
FieldByName
(
keySlice
[
len
(
keySlice
)
-
1
])
if
!
v
.
IsValid
()
{
return
nil
,
newInvalidPathError
(
keyWithDots
)
}
return
v
.
Interface
(),
nil
}
This diff is collapsed.
Click to expand it.
release.json
View file @
da76851d
{
"version"
:
"0.3.
0
"
}
{
"version"
:
"0.3.
1
"
}
This diff is collapsed.
Click to expand it.
pathfind
.go
→
set
.go
View file @
da76851d
...
...
@@ -10,45 +10,6 @@ import (
"strings"
)
// This function returns the value of a field in a struct, given a path to the field.
func
GetValue
[
D
any
](
obj
D
,
keyWithDots
string
)
(
any
,
error
)
{
keySlice
:=
strings
.
Split
(
keyWithDots
,
"."
)
v
:=
reflect
.
ValueOf
(
obj
)
for
_
,
key
:=
range
keySlice
[
0
:
len
(
keySlice
)
-
1
]
{
for
v
.
Kind
()
==
reflect
.
Ptr
{
v
=
v
.
Elem
()
}
if
v
.
Kind
()
!=
reflect
.
Struct
{
return
nil
,
newUnsupportedTypePathError
(
keyWithDots
,
v
.
Type
())
}
v
=
v
.
FieldByName
(
key
)
}
if
v
.
Kind
()
==
reflect
.
Invalid
{
return
nil
,
newInvalidPathError
(
keyWithDots
)
}
for
v
.
Kind
()
==
reflect
.
Ptr
{
v
=
v
.
Elem
()
}
// non-supporter type at the top of the path
if
v
.
Kind
()
!=
reflect
.
Struct
{
return
nil
,
newUnsupportedTypeAtTopOfPathError
(
keyWithDots
,
v
.
Type
())
}
v
=
v
.
FieldByName
(
keySlice
[
len
(
keySlice
)
-
1
])
if
!
v
.
IsValid
()
{
return
nil
,
newInvalidPathError
(
keyWithDots
)
}
return
v
.
Interface
(),
nil
}
// This function sets the value of a field in a struct, given a path to the field.
func
SetValue
[
D
any
](
obj
D
,
keyWithDots
string
,
newValue
any
)
error
{
...
...
@@ -57,6 +18,9 @@ func SetValue[D any](obj D, keyWithDots string, newValue any) error {
for
_
,
key
:=
range
keySlice
[
0
:
len
(
keySlice
)
-
1
]
{
for
v
.
Kind
()
!=
reflect
.
Ptr
{
if
v
.
Kind
()
==
reflect
.
Invalid
{
return
newInvalidPathError
(
keyWithDots
)
}
v
=
v
.
Addr
()
}
...
...
This diff is collapsed.
Click to expand it.
pathfind
_test.go
→
set
_test.go
View file @
da76851d
File moved
This diff is collapsed.
Click to expand it.