diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-11-03 10:52:40 +0100 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-11-03 10:52:40 +0100 |
commit | 2d6e12fd0260f8bf0f466e47767c5e68330e2bf1 (patch) | |
tree | 68d79a771e2fce6447acec038adbdd1fd053f1e5 /server | |
parent | e12192cafe7395b621e5224c95a01f27425d2118 (diff) |
added helper to load log operators from file
Diffstat (limited to 'server')
-rw-r--r-- | server/descriptor/descriptor.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/server/descriptor/descriptor.go b/server/descriptor/descriptor.go index 016d1cc..6e46790 100644 --- a/server/descriptor/descriptor.go +++ b/server/descriptor/descriptor.go @@ -6,6 +6,8 @@ import ( "crypto/tls" "encoding/base64" + "encoding/json" + "io/ioutil" ) const ( @@ -40,3 +42,16 @@ func FindLog(ops []Operator, logId []byte) (*Log, error) { } return nil, fmt.Errorf("no such log: %s", base64.StdEncoding.EncodeToString(logId)) } + +// LoadOperators loads a list of json-encoded log operators from a given path +func LoadOperators(path string) ([]Operator, error) { + blob, err := ioutil.ReadFile(path) + if err != nil { + return nil, fmt.Errorf("failed reading log operators: %v", err) + } + var ops []Operator + if err := json.Unmarshal(blob, &ops); err != nil { + return nil, fmt.Errorf("failed decoding log operators: %v", err) + } + return ops, nil +} |