LoadOrGenNodeKey attempts to load the NodeKey from the given filePath. If the file does not exist, it generates and saves a new NodeKey.
(filePath string)
| 39 | // LoadOrGenNodeKey attempts to load the NodeKey from the given filePath. If |
| 40 | // the file does not exist, it generates and saves a new NodeKey. |
| 41 | func LoadOrGenNodeKey(filePath string) (NodeKey, error) { |
| 42 | if tmos.FileExists(filePath) { |
| 43 | nodeKey, err := LoadNodeKey(filePath) |
| 44 | if err != nil { |
| 45 | return NodeKey{}, err |
| 46 | } |
| 47 | return nodeKey, nil |
| 48 | } |
| 49 | |
| 50 | nodeKey := GenNodeKey() |
| 51 | |
| 52 | if err := nodeKey.SaveAs(filePath); err != nil { |
| 53 | return NodeKey{}, err |
| 54 | } |
| 55 | |
| 56 | return nodeKey, nil |
| 57 | } |
| 58 | |
| 59 | // GenNodeKey generates a new node key. |
| 60 | func GenNodeKey() NodeKey { |
searching dependent graphs…