mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
a78defcd26
* Move to keymanager/keymanageropts command line parameters * Add help for individual keymanagers * gazelle Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
33 lines
667 B
Go
33 lines
667 B
Go
package keymanager
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"strings"
|
|
)
|
|
|
|
// decodeOpts decodes a value in to an options container.
|
|
// The input can be either JSON data or a path to a file containing JSON.
|
|
// This function returns an error if there is a problem decoding the input.
|
|
func decodeOpts(input string, res interface{}) error {
|
|
if input == "" {
|
|
// Empty input is okay.
|
|
return nil
|
|
}
|
|
|
|
var data []byte
|
|
if strings.HasPrefix(input, "{") {
|
|
// Looks like straight JSON.
|
|
data = []byte(input)
|
|
} else {
|
|
// Assume it's a path.
|
|
file, err := ioutil.ReadFile(input)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
data = file
|
|
}
|
|
|
|
return json.Unmarshal(data, res)
|
|
}
|