现在我们已经知道Caddyfile会被转换为JSON格式。实际上Caddyfile的配置方式对人来说更友好、更简单一些。具体是使用JSON还是Caddyfile,要取决于具体的场景。caddy的官方网站有一张表格,可以供参考:
表 2.1. JSON vs. Caddyfile
JSON | Caddyfile |
---|---|
Full range of Caddy functionality | Most common parts of Caddy functionality |
Easy to generate | Easy to craft by hand |
Easily programmable | Difficult to automate |
Extremely expressive | Moderately expressive |
Allows config traversal | Cannot traverse within Caddyfile |
Partial config changes | Whole config changes only |
Can be exported | Cannot be exported |
Compatible with all API endpoints | Compatible with some API endpoints |
Documentation generated automatically | Documentation is hand-written |
Ubiquitous | Niche |
More efficient | More computational |
Kind of boring | Kind of fun |
其实,从上面的表格可以看出,如果比较精通JSON配置的话,似乎使用JSON还是更好的。