MCPcopy
hub / github.com/caddyserver/caddy / determineStorage

Function determineStorage

cmd/storagefuncs.go:38–62  ·  view source on GitHub ↗

determineStorage returns the top-level storage module from the given config. It may return nil even if no error.

(configFile string, configAdapter string)

Source from the content-addressed store, hash-verified

36// determineStorage returns the top-level storage module from the given config.
37// It may return nil even if no error.
38func 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
64func cmdImportStorage(fl Flags) (int, error) {
65 importStorageCmdConfigFlag := fl.String("config")

Callers 2

cmdImportStorageFunction · 0.85
cmdExportStorageFunction · 0.85

Calls 1

LoadConfigFunction · 0.85

Tested by

no test coverage detected