-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
508 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
order http_cache before reverse_proxy | ||
admin 0.0.0.0:7777 | ||
debug | ||
|
||
storage consul { | ||
addr "consul:9500" | ||
token "" | ||
key_prefix "caddy_https" | ||
} | ||
|
||
} | ||
|
||
:9991 { | ||
reverse_proxy { | ||
to localhost:9995 | ||
} | ||
|
||
http_cache { | ||
cache_type in_memory | ||
match_path / | ||
|
||
default_max_age 1m | ||
} | ||
|
||
} | ||
|
||
:9995 { | ||
header Cache-control "public" | ||
root * /tmp/caddy-benchmark | ||
file_server | ||
|
||
log { | ||
level info | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package mystorage | ||
|
||
import ( | ||
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile" | ||
) | ||
|
||
const ( | ||
keyAddr = "addr" | ||
keyToken = "token" | ||
keyKeyPrefix = "key_prefix" | ||
) | ||
|
||
// Config is the configuration for consul storage | ||
type Config struct { | ||
Addr string `json:"addr.omitempty"` | ||
Token string `json:"token,omitempty"` | ||
KeyPrefix string `json:"key_prefix,omitempty"` | ||
} | ||
|
||
func getDefaultConfig() *Config { | ||
return &Config{ | ||
KeyPrefix: "_consul_cert_", | ||
Addr: "localhost:8500", | ||
} | ||
} | ||
|
||
// UnmarshalCaddyfile deserialize Caddyfile tokens into consul storage's config | ||
// storage consul { | ||
// addr | ||
// token | ||
// key_prefix | ||
// } | ||
func (s *Storage) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { | ||
config := getDefaultConfig() | ||
|
||
for d.Next() { | ||
for d.NextBlock(0) { | ||
parameter := d.Val() | ||
args := d.RemainingArgs() | ||
|
||
switch parameter { | ||
case keyAddr: | ||
config.Addr = args[0] | ||
case keyToken: | ||
config.Token = args[0] | ||
case keyKeyPrefix: | ||
config.KeyPrefix = args[0] | ||
|
||
default: | ||
return d.Errf("unrecognized subdirective %s", parameter) | ||
|
||
} | ||
|
||
} | ||
} | ||
s.Config = config | ||
return nil | ||
} | ||
|
||
var ( | ||
_ caddyfile.Unmarshaler = (*Storage)(nil) | ||
) |
Oops, something went wrong.