-
-
Notifications
You must be signed in to change notification settings - Fork 319
/
Copy pathlocal.go
60 lines (46 loc) · 1.47 KB
/
local.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package caddy
import (
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/dunglas/mercure"
)
type localTransportKeyStruct struct{}
var localTransportKey = localTransportKeyStruct{} //nolint:gochecknoglobals
func init() { //nolint:gochecknoinits
caddy.RegisterModule(Local{})
}
type Local struct {
transport *mercure.LocalTransport
}
// CaddyModule returns the Caddy module information.
func (Local) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: "http.handlers.mercure.local",
New: func() caddy.Module { return new(Local) },
}
}
func (l *Local) GetTransport() mercure.Transport { //nolint:ireturn
return l.transport
}
// Provision provisions l's configuration.
func (l *Local) Provision(_ caddy.Context) error {
destructor, _, _ := TransportUsagePool.LoadOrNew(localTransportKey, func() (caddy.Destructor, error) {
return TransportDestructor[*mercure.LocalTransport]{Transport: mercure.NewLocalTransport()}, nil
})
l.transport = destructor.(TransportDestructor[*mercure.LocalTransport]).Transport
return nil
}
//nolint:wrapcheck
func (l *Local) Cleanup() error {
_, err := TransportUsagePool.Delete(localTransportKey)
return err
}
// UnmarshalCaddyfile sets up the handler from Caddyfile tokens.
func (l *Local) UnmarshalCaddyfile(_ *caddyfile.Dispenser) error {
return nil
}
var (
_ caddy.Provisioner = (*Bolt)(nil)
_ caddy.CleanerUpper = (*Bolt)(nil)
_ caddyfile.Unmarshaler = (*Bolt)(nil)
)