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

Function isCaddyfile

cmd/main.go:112–144  ·  view source on GitHub ↗
(configFile, adapterName string)

Source from the content-addressed store, hash-verified

110}
111
112func isCaddyfile(configFile, adapterName string) (bool, error) {
113 if adapterName == "caddyfile" {
114 return true, nil
115 }
116
117 // as a special case, if a config file starts with "caddyfile" or
118 // has a ".caddyfile" extension, and no adapter is specified, and
119 // no adapter module name matches the extension, assume
120 // caddyfile adapter for convenience
121 baseConfig := strings.ToLower(filepath.Base(configFile))
122 baseConfigExt := filepath.Ext(baseConfig)
123 startsOrEndsInCaddyfile := strings.HasPrefix(baseConfig, "caddyfile") || strings.HasSuffix(baseConfig, ".caddyfile")
124
125 if baseConfigExt == ".json" {
126 return false, nil
127 }
128
129 // If the adapter is not specified,
130 // the config file starts with "caddyfile",
131 // the config file has an extension,
132 // and isn't a JSON file (e.g. Caddyfile.yaml),
133 // then we don't know what the config format is.
134 if adapterName == "" && startsOrEndsInCaddyfile {
135 return true, nil
136 }
137
138 // adapter is not empty,
139 // adapter is not "caddyfile",
140 // extension is not ".json",
141 // extension is not ".caddyfile"
142 // file does not start with "Caddyfile"
143 return false, nil
144}
145
146func loadConfigWithLogger(logger *zap.Logger, configFile, adapterName string) ([]byte, string, string, error) {
147 // if no logger is provided, use a nop logger

Callers 2

Test_isCaddyfileFunction · 0.85
loadConfigWithLoggerFunction · 0.85

Calls

no outgoing calls

Tested by 1

Test_isCaddyfileFunction · 0.68