File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ package compose
2
+
3
+ import "fmt"
4
+
5
+ const CaddyExtensionKey = "x-caddy"
6
+
7
+ type Caddy struct {
8
+ Config string `yaml:"config" json:"config"`
9
+ }
10
+
11
+ // DecodeMapstructure decodes x-caddy extension from either a string or an object.
12
+ // When x-caddy is a string, it's mapped directly to the Config field.
13
+ func (c * Caddy ) DecodeMapstructure (value any ) error {
14
+ switch v := value .(type ) {
15
+ case * Caddy :
16
+ // Already decoded, happens when mapstructure is called after initial parsing.
17
+ * c = * v
18
+ return nil
19
+ case string :
20
+ // Handle x-caddy: "caddyfile config"
21
+ * c = Caddy {Config : v }
22
+ case map [string ]any :
23
+ // Handle the long syntax with a config key.
24
+ if config , ok := v ["config" ]; ok {
25
+ configStr , ok := config .(string )
26
+ if ! ok {
27
+ return fmt .Errorf ("x-caddy.config must be a string, got %T" , config )
28
+ }
29
+ * c = Caddy {Config : configStr }
30
+ }
31
+ default :
32
+ return fmt .Errorf ("invalid type %T for x-caddy extension: expected string or object" , value )
33
+ }
34
+ return nil
35
+ }
You can’t perform that action at this time.
0 commit comments