-
Notifications
You must be signed in to change notification settings - Fork 38
/
module.go
38 lines (31 loc) · 818 Bytes
/
module.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
package mqtt
import (
"go.k6.io/k6/js/modules"
)
// RootModule is the root module for the mqtt API
type RootModule struct{}
func init() {
modules.Register("k6/x/mqtt", new(RootModule))
}
// MqttAPI is the k6 extension implementing the Mqtt api
type MqttAPI struct { //nolint:revive
vu modules.VU
}
// NewModuleInstance implements the modules.Module interface and returns
// a new instance for each VU.
func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance {
return &MqttAPI{vu: vu}
}
// Exports exposes the given object in ts
func (m *MqttAPI) Exports() modules.Exports {
return modules.Exports{
Named: map[string]interface{}{
"Client": m.client,
},
}
}
// Ensure the interfaces are implemented correctly.
var (
_ modules.Instance = &MqttAPI{}
_ modules.Module = &RootModule{}
)