-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from vshn/mariadb-fix-settings
Fix custom mariadb settings
- Loading branch information
Showing
5 changed files
with
217 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package common | ||
|
||
import "fmt" | ||
|
||
// SetNestedObjectValue is necessary as unstructured can't handle anything except basic values and maps. | ||
// this is a recursive function, it will traverse the map until it reaches the last element of the path. | ||
// If it encounters any non-map values while traversing, it will throw an error. | ||
func SetNestedObjectValue(values map[string]interface{}, path []string, val interface{}) error { | ||
|
||
if len(path) == 1 { | ||
source, isSlice := values[path[0]].([]interface{}) | ||
if !isSlice { | ||
values[path[0]] = val | ||
return nil | ||
} | ||
toArrayValue, isSlice := val.([]interface{}) | ||
if !isSlice { | ||
values[path[0]] = append(source, val) | ||
return nil | ||
} | ||
values[path[0]] = append(source, toArrayValue...) | ||
return nil | ||
} | ||
|
||
tmpVals, ok := values[path[0]].(map[string]interface{}) | ||
if !ok { | ||
return fmt.Errorf("cannot traverse map, value at field %s is not a map", path[0]) | ||
} | ||
|
||
return SetNestedObjectValue(tmpVals, path[1:], val) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters