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

Function configFileWithRespectToDefault

cmd/commandfuncs.go:908–929  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
908func 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
931type moduleInfo struct {
932 caddyModuleID string

Callers 2

cmdAdaptConfigFunction · 0.85
cmdValidateConfigFunction · 0.85

Calls 2

GetAdapterFunction · 0.92
StatMethod · 0.80

Tested by

no test coverage detected