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.1 to v0.4.0
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.4.0
Select Git revision
Swap
Target
oss/libraries/go/utilities/pathfinder
Select target project
oss/libraries/go/utilities/pathfinder
1 result
v0.3.1
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (3)
feat: support maps
· b5e9a534
Volker Schukai
authored
2 years ago
b5e9a534
Bump version to 0.4.0
· 318792ff
Volker Schukai
authored
2 years ago
318792ff
Update changelog
· 5d54f927
Volker Schukai
authored
2 years ago
5d54f927
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.md
+4
-0
4 additions, 0 deletions
CHANGELOG.md
get.go
+19
-1
19 additions, 1 deletion
get.go
get_test.go
+81
-0
81 additions, 0 deletions
get_test.go
release.json
+1
-1
1 addition, 1 deletion
release.json
with
105 additions
and
2 deletions
CHANGELOG.md
View file @
5d54f927
<a
name=
"v0.4.0"
></a>
## [v0.4.0] - 2022-12-17
<a
name=
"v0.3.1"
></a>
## [v0.3.1] - 2022-10-16
### Bug Fixes
...
...
@@ -17,5 +20,6 @@
-
feat takeover from other project
[
v0.4.0
]:
https://gitlab.schukai.com/oss/libraries/go/utilities/pathfinder/compare/v0.3.1...v0.4.0
[
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
View file @
5d54f927
...
...
@@ -21,7 +21,16 @@ func GetValue[D any](obj D, keyWithDots string) (any, error) {
v
=
v
.
Elem
()
}
if
v
.
Kind
()
!=
reflect
.
Struct
{
if
v
.
Kind
()
==
reflect
.
Map
{
switch
v
.
Type
()
.
Key
()
.
Kind
()
{
case
reflect
.
String
:
v
=
v
.
MapIndex
(
reflect
.
ValueOf
(
key
))
.
Elem
()
continue
default
:
return
nil
,
newUnsupportedTypePathError
(
keyWithDots
,
v
.
Type
())
}
}
else
if
v
.
Kind
()
!=
reflect
.
Struct
{
return
nil
,
newUnsupportedTypePathError
(
keyWithDots
,
v
.
Type
())
}
...
...
@@ -36,6 +45,15 @@ func GetValue[D any](obj D, keyWithDots string) (any, error) {
v
=
v
.
Elem
()
}
if
v
.
Kind
()
==
reflect
.
Map
{
switch
v
.
Type
()
.
Key
()
.
Kind
()
{
case
reflect
.
String
:
return
v
.
MapIndex
(
reflect
.
ValueOf
(
keySlice
[
len
(
keySlice
)
-
1
]))
.
Interface
(),
nil
default
:
return
nil
,
newUnsupportedTypePathError
(
keyWithDots
,
v
.
Type
())
}
}
// non-supporter type at the top of the path
if
v
.
Kind
()
!=
reflect
.
Struct
{
return
nil
,
newUnsupportedTypeAtTopOfPathError
(
keyWithDots
,
v
.
Type
())
...
...
This diff is collapsed.
Click to expand it.
get_test.go
0 → 100644
View file @
5d54f927
// Copyright 2022 schukai GmbH
// SPDX-License-Identifier: AGPL-3.0
package
pathfinder
import
(
"github.com/stretchr/testify/assert"
"testing"
)
func
TestGetValueFrom
(
t
*
testing
.
T
)
{
m
:=
map
[
string
]
string
{
"KeyA"
:
"true"
,
"KeyB"
:
"2"
,
"KeyC"
:
"3"
,
"KeyD"
:
"4.0"
,
}
v
,
err
:=
GetValue
[
map
[
string
]
string
](
m
,
"KeyA"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
assert
.
Equal
(
t
,
v
,
"true"
)
}
func
TestPathGetValueFromX
(
t
*
testing
.
T
)
{
m
:=
map
[
string
]
any
{
"A"
:
"true"
,
"B"
:
map
[
string
]
any
{
"C"
:
2
,
"D"
:
map
[
string
]
any
{
"E"
:
"3"
,
},
},
"X"
:
"3"
,
"Y"
:
"4.0"
,
}
v
,
err
:=
GetValue
[
map
[
string
]
any
](
m
,
"B.D.E"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
assert
.
Equal
(
t
,
"3"
,
v
)
v
,
err
=
GetValue
[
map
[
string
]
any
](
m
,
"B.C"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
assert
.
Equal
(
t
,
2
,
v
)
}
func
TestPathGetValueFrom
(
t
*
testing
.
T
)
{
type
PathfindTestStruct1
struct
{
A
bool
Sub1
struct
{
B
int
Sub2
struct
{
C
bool
}
D
int
}
}
var
testData
PathfindTestStruct1
testData
.
A
=
true
testData
.
Sub1
.
B
=
2
testData
.
Sub1
.
Sub2
.
C
=
true
testData
.
Sub1
.
D
=
4
GetValue
[
PathfindTestStruct1
](
testData
,
"Sub1.B"
)
GetValue
[
PathfindTestStruct1
](
testData
,
"Sub1.Sub2.C"
)
GetValue
[
PathfindTestStruct1
](
testData
,
"Sub1.D"
)
}
This diff is collapsed.
Click to expand it.
release.json
View file @
5d54f927
{
"version"
:
"0.
3.1
"
}
{
"version"
:
"0.
4.0
"
}
This diff is collapsed.
Click to expand it.