-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add settings to system * fix: test for bios * fix: linter for settings
- Loading branch information
Showing
4 changed files
with
121 additions
and
44 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
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,49 @@ | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
|
||
package redfish | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// SettingsAttributes handles the settings attribute values that may be any of several | ||
// types and adds some basic helper methods to make accessing values easier. | ||
type SettingsAttributes map[string]interface{} | ||
|
||
// String gets the string representation of the attribute value. | ||
func (ba SettingsAttributes) String(name string) string { | ||
if val, ok := ba[name]; ok { | ||
return fmt.Sprintf("%v", val) | ||
} | ||
|
||
return "" | ||
} | ||
|
||
// Float64 gets the value as a float64 or 0 if that is not possible. | ||
func (ba SettingsAttributes) Float64(name string) float64 { | ||
if val, ok := ba[name]; ok { | ||
return val.(float64) | ||
} | ||
|
||
return 0 | ||
} | ||
|
||
// Int gets the value as an integer or 0 if that is not possible. | ||
func (ba SettingsAttributes) Int(name string) int { | ||
// Integer values may be interpeted as float64, so get it as that first, | ||
// then coerce down to int. | ||
floatVal := int(ba.Float64(name)) | ||
return (floatVal) | ||
} | ||
|
||
// Bool gets the value as a boolean or returns false. | ||
func (ba SettingsAttributes) Bool(name string) bool { | ||
maybeBool := ba.String(name) | ||
maybeBool = strings.ToLower(maybeBool) | ||
return (maybeBool == "true" || | ||
maybeBool == "1" || | ||
maybeBool == "enabled") | ||
} |