mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-22 10:14:15 +08:00
cmd: Assume Caddyfile based on filename prefix and suffix (#5919)
This can be helpful if editors only consider file extensions for certain features. * added special case support for caddyfile suffix, case insensitive * Update cmd/main.go Co-authored-by: Matt Holt <mholt@users.noreply.github.com> * skip caddyfile adapter for registered file extensions --------- Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
This commit is contained in:
parent
4a0492f3e1
commit
185ed6fe7c
15
cmd/main.go
15
cmd/main.go
|
@ -157,11 +157,16 @@ func loadConfigWithLogger(logger *zap.Logger, configFile, adapterName string) ([
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// as a special case, if a config file called "Caddyfile" was
|
// as a special case, if a config file starts with "caddyfile" or
|
||||||
// specified, and no adapter is specified, assume caddyfile adapter
|
// has a ".caddyfile" extension, and no adapter is specified, and
|
||||||
// for convenience
|
// no adapter module name matches the extension, assume
|
||||||
if strings.HasPrefix(filepath.Base(configFile), "Caddyfile") &&
|
// caddyfile adapter for convenience
|
||||||
filepath.Ext(configFile) != ".json" &&
|
baseConfig := strings.ToLower(filepath.Base(configFile))
|
||||||
|
baseConfigExt := filepath.Ext(baseConfig)
|
||||||
|
if (strings.HasPrefix(baseConfig, "caddyfile") ||
|
||||||
|
strings.HasSuffix(baseConfig, ".caddyfile")) &&
|
||||||
|
caddyconfig.GetAdapter(baseConfigExt[1:]) == nil &&
|
||||||
|
baseConfigExt != ".json" &&
|
||||||
adapterName == "" {
|
adapterName == "" {
|
||||||
adapterName = "caddyfile"
|
adapterName = "caddyfile"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user