UnmarshalModule instantiates a module with the given ID and invokes UnmarshalCaddyfile on the new value using the immediate next segment of d as input. In other words, d's next token should be the first token of the module's Caddyfile input. This function is used when the next segment of Caddyfile
(d *Dispenser, moduleID string)
| 125 | // type-asserted to the module's associated type for practical use |
| 126 | // when setting up a config. |
| 127 | func UnmarshalModule(d *Dispenser, moduleID string) (Unmarshaler, error) { |
| 128 | mod, err := caddy.GetModule(moduleID) |
| 129 | if err != nil { |
| 130 | return nil, d.Errf("getting module named '%s': %v", moduleID, err) |
| 131 | } |
| 132 | inst := mod.New() |
| 133 | unm, ok := inst.(Unmarshaler) |
| 134 | if !ok { |
| 135 | return nil, d.Errf("module %s is not a Caddyfile unmarshaler; is %T", mod.ID, inst) |
| 136 | } |
| 137 | err = unm.UnmarshalCaddyfile(d.NewFromNextSegment()) |
| 138 | if err != nil { |
| 139 | return nil, err |
| 140 | } |
| 141 | return unm, nil |
| 142 | } |
| 143 | |
| 144 | // Interface guard |
| 145 | var _ caddyconfig.Adapter = (*Adapter)(nil) |
no test coverage detected