mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-09 19:32:24 +08:00
move utility method
This commit is contained in:
@ -2,9 +2,11 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -205,3 +207,15 @@ func Marshal(value interface{}) ([]byte, error) {
|
||||
// need to prettyprint, hence MarshalIndent, instead of Encoder
|
||||
return json.MarshalIndent(value, "", " ")
|
||||
}
|
||||
|
||||
func FromMap(v map[string]interface{}) (*Config, error) {
|
||||
var buf bytes.Buffer
|
||||
if err := json.NewEncoder(&buf).Encode(v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var conf Config
|
||||
if err := json.NewDecoder(&buf).Decode(&conf); err != nil {
|
||||
return nil, fmt.Errorf("Failure to decode config: %s", err)
|
||||
}
|
||||
return &conf, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user