RestoreValue returns the value associated with the given key from the last preserved environment
(key string, val any)
| 104 | |
| 105 | // RestoreValue returns the value associated with the given key from the last preserved environment |
| 106 | func restoreInto(key string, val any) error { |
| 107 | b, err := loader(persistedFile) |
| 108 | if err != nil { |
| 109 | if os.IsNotExist(err) { |
| 110 | return nil |
| 111 | } |
| 112 | |
| 113 | return err |
| 114 | } |
| 115 | |
| 116 | var j map[string]json.RawMessage |
| 117 | |
| 118 | if err = json.Unmarshal(b, &j); err != nil { |
| 119 | return err |
| 120 | } |
| 121 | |
| 122 | if err = json.Unmarshal(j[key], &val); err != nil { |
| 123 | return err |
| 124 | } |
| 125 | |
| 126 | return nil |
| 127 | } |
| 128 | |
| 129 | // WithState marks a struct that holds some state under a specific key |
| 130 | type WithState interface { |