5. JSON vs. Caddyfile

现在我们已经知道Caddyfile会被转换为JSON格式。实际上Caddyfile的配置方式对人来说更友好、更简单一些。具体是使用JSON还是Caddyfile,要取决于具体的场景。caddy的官方网站有一张表格,可以供参考:

表 2.1. JSON vs. Caddyfile

JSONCaddyfile
Full range of Caddy functionalityMost common parts of Caddy functionality
Easy to generateEasy to craft by hand
Easily programmableDifficult to automate
Extremely expressiveModerately expressive
Allows config traversalCannot traverse within Caddyfile
Partial config changesWhole config changes only
Can be exportedCannot be exported
Compatible with all API endpointsCompatible with some API endpoints
Documentation generated automaticallyDocumentation is hand-written
UbiquitousNiche
More efficientMore computational
Kind of boringKind of fun

其实,从上面的表格可以看出,如果比较精通JSON配置的话,似乎使用JSON还是更好的。