4343 defaultcacheBucketsNum = 256
4444 defaultCacheMaxMemorySize = GB // default is 1 GB
4545 defaultRedisConnectionSetting = "localhost:6379 0"
46- defaultCacheKeyTemplate = "{http.request.method} {http.request.host}{http.request.uri.path} {http.request.uri.query}"
46+ defaultCacheKeyTemplate = "{http.request.method} {http.request.host}{http.request.uri.path}? {http.request.uri.query}"
4747 // Note: prevent character space in the key
4848 // the key is refereced from github.com/caddyserver/caddy/v2/modules/caddyhttp.addHTTPVarsToReplacer
4949)
@@ -63,7 +63,9 @@ const (
6363 // format: addr db password or addr db or addr
6464 // ex.
6565 // localhost:6789 0 => connect without password. only index and host:port provided
66+ // the following are keys for extensions
6667 keyDistributed = "distributed"
68+ keyInfluxLog = "influxlog"
6769)
6870
6971func init () {
@@ -190,23 +192,23 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
190192 }
191193
192194 cacheRule := & HeaderRuleMatcher {Header : args [0 ], Value : args [1 :]}
193- d , _ := json .Marshal (cacheRule )
195+ data , _ := json .Marshal (cacheRule )
194196
195197 config .RuleMatchersRaws = append (config .RuleMatchersRaws , RuleMatcherRawWithType {
196198 Type : MatcherTypeHeader ,
197- Data : d ,
199+ Data : data ,
198200 })
199201
200202 case keyMatchPath :
201203 if len (args ) != 1 {
202204 return d .Err ("Invalid usage of match_path in cache config." )
203205 }
204206 cacheRule := & PathRuleMatcher {Path : args [0 ]}
205- d , _ := json .Marshal (cacheRule )
207+ data , _ := json .Marshal (cacheRule )
206208
207209 config .RuleMatchersRaws = append (config .RuleMatchersRaws , RuleMatcherRawWithType {
208210 Type : MatcherTypePath ,
209- Data : d ,
211+ Data : data ,
210212 })
211213
212214 case keyCacheKey :
@@ -238,7 +240,7 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
238240
239241 unm , ok := mod .New ().(caddyfile.Unmarshaler )
240242 if ! ok {
241- return d .Errf ("distributed module '%s' is not a Caddfile unmarshaler" , mod )
243+ return d .Errf ("distributed module '%s' is not a Caddyfile unmarshaler" , mod )
242244 }
243245
244246 err = unm .UnmarshalCaddyfile (d .NewFromNextSegment ())
@@ -248,6 +250,13 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
248250
249251 h .DistributedRaw = caddyconfig .JSONModuleObject (unm , "distributed" , "consul" , nil )
250252
253+ // case keyInfluxLog:
254+ // raw, err := setupInfluxLog(keyInfluxLog, d, args)
255+ // if err != nil {
256+ // return err
257+ // }
258+ // h.InfluxLogRaw = raw
259+
251260 default :
252261 return d .Err ("Unknown cache parameter: " + parameter )
253262 }
@@ -259,6 +268,28 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
259268 return nil
260269}
261270
271+ func setupInfluxLog (key string , d * caddyfile.Dispenser , args []string ) (json.RawMessage , error ) {
272+
273+ mod , err := caddy .GetModule ("caddy.logging.writers." + key )
274+ if err != nil {
275+ return nil , d .Errf ("getting influxlog module '%s': '%v'" , mod , err )
276+ }
277+
278+ unm , ok := mod .New ().(caddyfile.Unmarshaler )
279+ if ! ok {
280+ return nil , d .Errf ("influxlog module '%s' is not a Caddyfile unmarshaler" , mod )
281+ }
282+
283+ err = unm .UnmarshalCaddyfile (d .NewFromNextSegment ())
284+ if err != nil {
285+ return nil , err
286+ }
287+
288+ raw := caddyconfig .JSONModuleObject (unm , "mylog" , "influxlog" , nil )
289+
290+ return raw , nil
291+ }
292+
262293// Interface guards
263294var (
264295 _ caddyfile.Unmarshaler = (* Handler )(nil )
0 commit comments