Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
da75e92d
Commit
da75e92d
authored
Aug 14, 2015
by
Juan Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1570 from rht/config-null
Config: allow to set maps on null value
parents
c1380f12
c0a0cde9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
3 deletions
+14
-3
repo/common/common.go
repo/common/common.go
+11
-3
test/sharness/t0021-config.sh
test/sharness/t0021-config.sh
+3
-0
No files found.
repo/common/common.go
View file @
da75e92d
...
...
@@ -7,12 +7,20 @@ import (
func
MapGetKV
(
v
map
[
string
]
interface
{},
key
string
)
(
interface
{},
error
)
{
var
ok
bool
var
mcursor
map
[
string
]
interface
{}
var
cursor
interface
{}
=
v
parts
:=
strings
.
Split
(
key
,
"."
)
for
i
,
part
:=
range
parts
{
cursor
,
ok
=
cursor
.
(
map
[
string
]
interface
{})[
part
]
sofar
:=
strings
.
Join
(
parts
[
:
i
],
"."
)
mcursor
,
ok
=
cursor
.
(
map
[
string
]
interface
{})
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"%s key is not a map"
,
sofar
)
}
cursor
,
ok
=
mcursor
[
part
]
if
!
ok
{
sofar
:=
strings
.
Join
(
parts
[
:
i
],
"."
)
return
nil
,
fmt
.
Errorf
(
"%s key has no attributes"
,
sofar
)
}
}
...
...
@@ -39,7 +47,7 @@ func MapSetKV(v map[string]interface{}, key string, value interface{}) error {
}
cursor
,
ok
=
mcursor
[
part
]
if
!
ok
{
// create map if this is empty
if
!
ok
||
cursor
==
nil
{
// create map if this is empty
or is null
mcursor
[
part
]
=
map
[
string
]
interface
{}{}
cursor
=
mcursor
[
part
]
}
...
...
test/sharness/t0021-config.sh
View file @
da75e92d
...
...
@@ -57,6 +57,9 @@ test_config_cmd() {
test_config_cmd_set
"--json"
"beep3"
"true"
test_config_cmd_set
"--json"
"beep3"
"false"
test_config_cmd_set
"--json"
"Discovery"
"
$CONFIG_SET_JSON_TEST
"
test_config_cmd_set
"--json"
"deep-not-defined.prop"
"true"
test_config_cmd_set
"--json"
"deep-null"
"null"
test_config_cmd_set
"--json"
"deep-null.prop"
"true"
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment