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.2.0 to v0.3.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.3.0
Select Git revision
Swap
Target
oss/libraries/go/utilities/pathfinder
Select target project
oss/libraries/go/utilities/pathfinder
1 result
v0.2.0
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (3)
refactor change function signatur
· bf7301b9
Volker Schukai
authored
2 years ago
bf7301b9
Bump version to 0.3.0
· 41cda102
Volker Schukai
authored
2 years ago
41cda102
Update changelog
· 39dc25f9
Volker Schukai
authored
2 years ago
39dc25f9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
CHANGELOG.md
+7
-0
7 additions, 0 deletions
CHANGELOG.md
README.md
+12
-0
12 additions, 0 deletions
README.md
pathfind.go
+2
-2
2 additions, 2 deletions
pathfind.go
pathfind_test.go
+26
-26
26 additions, 26 deletions
pathfind_test.go
release.json
+1
-1
1 addition, 1 deletion
release.json
with
48 additions
and
29 deletions
CHANGELOG.md
View file @
39dc25f9
<a
name=
"v0.3.0"
></a>
## [v0.3.0] - 2022-10-15
### Code Refactoring
-
refactor change function signatur
<a
name=
"v0.2.0"
></a>
## v0.2.0 - 2022-10-15
### Add Features
-
feat takeover from other project
[
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.
README.md
View file @
39dc25f9
...
...
@@ -19,7 +19,19 @@ go get gitlab.schukai.com/oss/libraries/go/utilities/pathfinder
## Usage
### Set values
```
go
s
:=
&
StructA
{}
err
:=
GetValue
[
*
StructA
](
s
,
"my.key"
)
```
### Get values
```
go
s
:=
&
StructA
{}
err
:=
SetValue
[
*
StructA
](
s
,
"my.key"
,
"value"
)
```
## Contributing
...
...
This diff is collapsed.
Click to expand it.
pathfind.go
View file @
39dc25f9
...
...
@@ -11,7 +11,7 @@ import (
)
// This function returns the value of a field in a struct, given a path to the field.
func
GetValue
From
[
D
any
](
obj
D
,
keyWithDots
string
)
(
any
,
error
)
{
func
GetValue
[
D
any
](
obj
D
,
keyWithDots
string
)
(
any
,
error
)
{
keySlice
:=
strings
.
Split
(
keyWithDots
,
"."
)
v
:=
reflect
.
ValueOf
(
obj
)
...
...
@@ -50,7 +50,7 @@ func GetValueFrom[D any](obj D, keyWithDots string) (any, error) {
}
// This function sets the value of a field in a struct, given a path to the field.
func
SetValue
UsingPath
[
D
any
](
obj
D
,
keyWithDots
string
,
newValue
any
)
error
{
func
SetValue
[
D
any
](
obj
D
,
keyWithDots
string
,
newValue
any
)
error
{
keySlice
:=
strings
.
Split
(
keyWithDots
,
"."
)
v
:=
reflect
.
ValueOf
(
obj
)
...
...
This diff is collapsed.
Click to expand it.
pathfind_test.go
View file @
39dc25f9
...
...
@@ -32,7 +32,7 @@ func TestPathFindError(t *testing.T) {
s
:=
PathfindTestStruct1
{}
_
,
err
:=
GetValue
From
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.XX"
)
_
,
err
:=
GetValue
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.XX"
)
if
err
==
nil
{
t
.
Error
(
"err == nil"
)
}
...
...
@@ -58,7 +58,7 @@ func TestPathFindSetValueString(t *testing.T) {
for
k
,
v
:=
range
testData
{
s
:=
&
PathfindTestStruct1
{}
err
:=
SetValue
UsingPath
[
*
PathfindTestStruct1
](
s
,
k
,
v
)
err
:=
SetValue
[
*
PathfindTestStruct1
](
s
,
k
,
v
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -74,7 +74,7 @@ func TestPathFindGetValueFrom(t *testing.T) {
s
.
Sub1
.
Bs
=
"3"
s
.
Sub1
.
Bf
=
4.0
v
,
err
:=
GetValue
From
[
PathfindTestStruct1
](
s
,
"Sub1.B"
)
v
,
err
:=
GetValue
[
PathfindTestStruct1
](
s
,
"Sub1.B"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -83,7 +83,7 @@ func TestPathFindGetValueFrom(t *testing.T) {
t
.
Error
(
"v != true"
)
}
v
,
err
=
GetValue
From
[
PathfindTestStruct1
](
s
,
"Sub1.Bi"
)
v
,
err
=
GetValue
[
PathfindTestStruct1
](
s
,
"Sub1.Bi"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -92,7 +92,7 @@ func TestPathFindGetValueFrom(t *testing.T) {
t
.
Error
(
"v != 2"
)
}
v
,
err
=
GetValue
From
[
PathfindTestStruct1
](
s
,
"Sub1.Bs"
)
v
,
err
=
GetValue
[
PathfindTestStruct1
](
s
,
"Sub1.Bs"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -101,7 +101,7 @@ func TestPathFindGetValueFrom(t *testing.T) {
t
.
Error
(
"v != 3"
)
}
v
,
err
=
GetValue
From
[
PathfindTestStruct1
](
s
,
"Sub1.Bf"
)
v
,
err
=
GetValue
[
PathfindTestStruct1
](
s
,
"Sub1.Bf"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -115,7 +115,7 @@ func TestPathFindGetValueFrom(t *testing.T) {
s
.
Sub1
.
Sub2
.
Cs
=
"3"
s
.
Sub1
.
Sub2
.
Cf
=
4.0
v
,
err
=
GetValue
From
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.C"
)
v
,
err
=
GetValue
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.C"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -124,7 +124,7 @@ func TestPathFindGetValueFrom(t *testing.T) {
t
.
Error
(
"v != true"
)
}
v
,
err
=
GetValue
From
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Ci"
)
v
,
err
=
GetValue
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Ci"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -133,7 +133,7 @@ func TestPathFindGetValueFrom(t *testing.T) {
t
.
Error
(
"v != 2"
)
}
v
,
err
=
GetValue
From
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Cs"
)
v
,
err
=
GetValue
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Cs"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -142,7 +142,7 @@ func TestPathFindGetValueFrom(t *testing.T) {
t
.
Error
(
"v != 3"
)
}
v
,
err
=
GetValue
From
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Cf"
)
v
,
err
=
GetValue
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Cf"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -156,7 +156,7 @@ func TestPathFindGetValueFrom(t *testing.T) {
s
.
Sub1
.
Sub2
.
Sub3
.
Ds
=
"3"
s
.
Sub1
.
Sub2
.
Sub3
.
Df
=
4.0
v
,
err
=
GetValue
From
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.D"
)
v
,
err
=
GetValue
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.D"
)
if
err
!=
nil
{
t
.
Error
(
err
)
...
...
@@ -166,7 +166,7 @@ func TestPathFindGetValueFrom(t *testing.T) {
t
.
Error
(
"v != true"
)
}
v
,
err
=
GetValue
From
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.Di"
)
v
,
err
=
GetValue
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.Di"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -175,7 +175,7 @@ func TestPathFindGetValueFrom(t *testing.T) {
t
.
Error
(
"v != 2"
)
}
v
,
err
=
GetValue
From
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.Ds"
)
v
,
err
=
GetValue
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.Ds"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -184,7 +184,7 @@ func TestPathFindGetValueFrom(t *testing.T) {
t
.
Error
(
"v != 3"
)
}
v
,
err
=
GetValue
From
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.Df"
)
v
,
err
=
GetValue
[
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.Df"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -198,10 +198,10 @@ func TestPathFindGetValueFrom(t *testing.T) {
func
TestPathFindSetValueFrom
(
t
*
testing
.
T
)
{
s
:=
&
PathfindTestStruct1
{}
SetValue
UsingPath
[
*
PathfindTestStruct1
](
s
,
"Sub1.B"
,
"true"
)
SetValue
UsingPath
[
*
PathfindTestStruct1
](
s
,
"Sub1.Bi"
,
"2"
)
SetValue
UsingPath
[
*
PathfindTestStruct1
](
s
,
"Sub1.Bs"
,
"3"
)
SetValue
UsingPath
[
*
PathfindTestStruct1
](
s
,
"Sub1.Bf"
,
"4.0"
)
SetValue
[
*
PathfindTestStruct1
](
s
,
"Sub1.B"
,
"true"
)
SetValue
[
*
PathfindTestStruct1
](
s
,
"Sub1.Bi"
,
"2"
)
SetValue
[
*
PathfindTestStruct1
](
s
,
"Sub1.Bs"
,
"3"
)
SetValue
[
*
PathfindTestStruct1
](
s
,
"Sub1.Bf"
,
"4.0"
)
if
s
.
Sub1
.
B
!=
true
{
t
.
Error
(
"s.Sub1.B != true"
)
...
...
@@ -220,10 +220,10 @@ func TestPathFindSetValueFrom(t *testing.T) {
t
.
Error
(
"s.Sub1.Bf != 4.0"
)
}
SetValue
UsingPath
[
*
PathfindTestStruct1
](
s
,
"Sub1.Sub2.C"
,
"true"
)
SetValue
UsingPath
[
*
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Ci"
,
"2"
)
SetValue
UsingPath
[
*
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Cs"
,
"3"
)
SetValue
UsingPath
[
*
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Cf"
,
"4.0"
)
SetValue
[
*
PathfindTestStruct1
](
s
,
"Sub1.Sub2.C"
,
"true"
)
SetValue
[
*
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Ci"
,
"2"
)
SetValue
[
*
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Cs"
,
"3"
)
SetValue
[
*
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Cf"
,
"4.0"
)
if
s
.
Sub1
.
Sub2
.
C
!=
true
{
t
.
Error
(
"s.Sub1.Sub2.C != true"
)
...
...
@@ -250,10 +250,10 @@ func TestPathFindSetValueFrom(t *testing.T) {
}
SetValue
UsingPath
[
*
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.D"
,
"true"
)
SetValue
UsingPath
[
*
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.Di"
,
"2"
)
SetValue
UsingPath
[
*
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.Ds"
,
"3"
)
SetValue
UsingPath
[
*
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.Df"
,
"4.0"
)
SetValue
[
*
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.D"
,
"true"
)
SetValue
[
*
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.Di"
,
"2"
)
SetValue
[
*
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.Ds"
,
"3"
)
SetValue
[
*
PathfindTestStruct1
](
s
,
"Sub1.Sub2.Sub3.Df"
,
"4.0"
)
if
s
.
Sub1
.
Sub2
.
Sub3
.
D
!=
true
{
t
.
Error
(
"s.Sub1.Sub2.Sub3.D != true"
)
...
...
This diff is collapsed.
Click to expand it.
release.json
View file @
39dc25f9
{
"version"
:
"0.
2
.0"
}
{
"version"
:
"0.
3
.0"
}
This diff is collapsed.
Click to expand it.