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

Function parseApp

modules/caddyevents/eventsconfig/caddyfile.go:42–82  ·  view source on GitHub ↗

parseApp configures the "events" global option from Caddyfile to set up the events app. Syntax: events { on <event> <handler_module...> } If <event> is *, then it will bind to all events.

(d *caddyfile.Dispenser, _ any)

Source from the content-addressed store, hash-verified

40//
41// If <event> is *, then it will bind to all events.
42func parseApp(d *caddyfile.Dispenser, _ any) (any, error) {
43 d.Next() // consume option name
44 app := new(caddyevents.App)
45 for d.NextBlock(0) {
46 switch d.Val() {
47 case "on":
48 if !d.NextArg() {
49 return nil, d.ArgErr()
50 }
51 eventName := d.Val()
52 if eventName == "*" {
53 eventName = ""
54 }
55
56 if !d.NextArg() {
57 return nil, d.ArgErr()
58 }
59 handlerName := d.Val()
60 modID := "events.handlers." + handlerName
61 unm, err := caddyfile.UnmarshalModule(d, modID)
62 if err != nil {
63 return nil, err
64 }
65
66 app.Subscriptions = append(app.Subscriptions, &caddyevents.Subscription{
67 Events: []string{eventName},
68 HandlersRaw: []json.RawMessage{
69 caddyconfig.JSONModuleObject(unm, "handler", handlerName, nil),
70 },
71 })
72
73 default:
74 return nil, d.ArgErr()
75 }
76 }
77
78 return httpcaddyfile.App{
79 Name: "events",
80 Value: caddyconfig.JSON(app, nil),
81 }, nil
82}

Callers

nothing calls this directly

Calls 8

UnmarshalModuleFunction · 0.92
JSONModuleObjectFunction · 0.92
JSONFunction · 0.92
NextBlockMethod · 0.80
ValMethod · 0.80
NextArgMethod · 0.80
ArgErrMethod · 0.80
NextMethod · 0.65

Tested by

no test coverage detected