configFileWithRespectToDefault returns the filename to use for loading the config, based on whether a config file is already specified and a supported default config file exists.
(logger *zap.Logger, configFile string)
| 906 | // configFileWithRespectToDefault returns the filename to use for loading the config, based |
| 907 | // on whether a config file is already specified and a supported default config file exists. |
| 908 | func configFileWithRespectToDefault(logger *zap.Logger, configFile string) (string, error) { |
| 909 | const defaultCaddyfile = "Caddyfile" |
| 910 | |
| 911 | // if no input file was specified, try a default Caddyfile if the Caddyfile adapter is plugged in |
| 912 | if configFile == "" && caddyconfig.GetAdapter("caddyfile") != nil { |
| 913 | _, err := os.Stat(defaultCaddyfile) |
| 914 | if err == nil { |
| 915 | // default Caddyfile exists |
| 916 | if logger != nil { |
| 917 | logger.Info("using adjacent Caddyfile") |
| 918 | } |
| 919 | return defaultCaddyfile, nil |
| 920 | } |
| 921 | if !errors.Is(err, fs.ErrNotExist) { |
| 922 | // problem checking |
| 923 | return configFile, fmt.Errorf("checking if default Caddyfile exists: %v", err) |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | // default config file does not exist or is irrelevant |
| 928 | return configFile, nil |
| 929 | } |
| 930 | |
| 931 | type moduleInfo struct { |
| 932 | caddyModuleID string |
no test coverage detected