determineStorage returns the top-level storage module from the given config. It may return nil even if no error.
(configFile string, configAdapter string)
| 36 | // determineStorage returns the top-level storage module from the given config. |
| 37 | // It may return nil even if no error. |
| 38 | func determineStorage(configFile string, configAdapter string) (*storVal, error) { |
| 39 | cfg, _, _, err := LoadConfig(configFile, configAdapter) |
| 40 | if err != nil { |
| 41 | return nil, err |
| 42 | } |
| 43 | |
| 44 | // storage defaults to FileStorage if not explicitly |
| 45 | // defined in the config, so the config can be valid |
| 46 | // json but unmarshaling will fail. |
| 47 | if !json.Valid(cfg) { |
| 48 | return nil, &json.SyntaxError{} |
| 49 | } |
| 50 | var tmpStruct storVal |
| 51 | err = json.Unmarshal(cfg, &tmpStruct) |
| 52 | if err != nil { |
| 53 | // default case, ignore the error |
| 54 | var jsonError *json.SyntaxError |
| 55 | if errors.As(err, &jsonError) { |
| 56 | return nil, nil |
| 57 | } |
| 58 | return nil, err |
| 59 | } |
| 60 | |
| 61 | return &tmpStruct, nil |
| 62 | } |
| 63 | |
| 64 | func cmdImportStorage(fl Flags) (int, error) { |
| 65 | importStorageCmdConfigFlag := fl.String("config") |
no test coverage detected