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

Method Adapt

caddyconfig/caddyfile/adapter.go:32–64  ·  view source on GitHub ↗

Adapt converts the Caddyfile config in body to Caddy JSON.

(body []byte, options map[string]any)

Source from the content-addressed store, hash-verified

30
31// Adapt converts the Caddyfile config in body to Caddy JSON.
32func (a Adapter) Adapt(body []byte, options map[string]any) ([]byte, []caddyconfig.Warning, error) {
33 if a.ServerType == nil {
34 return nil, nil, fmt.Errorf("no server type")
35 }
36 if options == nil {
37 options = make(map[string]any)
38 }
39
40 filename, _ := options["filename"].(string)
41 if filename == "" {
42 filename = "Caddyfile"
43 }
44
45 serverBlocks, err := Parse(filename, body)
46 if err != nil {
47 return nil, nil, err
48 }
49
50 cfg, warnings, err := a.ServerType.Setup(serverBlocks, options)
51 if err != nil {
52 return nil, warnings, err
53 }
54
55 // lint check: see if input was properly formatted; sometimes messy files parse
56 // successfully but result in logical errors (the Caddyfile is a bad format, I'm sorry)
57 if warning, different := FormattingDifference(filename, body); different {
58 warnings = append(warnings, warning)
59 }
60
61 result, err := json.Marshal(cfg)
62
63 return result, warnings, err
64}
65
66// FormattingDifference returns a warning and true if the formatted version
67// is any different from the input; empty warning and false otherwise.

Implementers 1

Adaptercaddyconfig/caddyfile/adapter.go

Calls 3

ParseFunction · 0.85
FormattingDifferenceFunction · 0.85
SetupMethod · 0.65