forked from pmalhaire/xk6-mqtt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.go
44 lines (37 loc) · 966 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
39
40
41
42
43
44
package mqtt
import (
"go.k6.io/k6/js/common"
"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
metrics mqttMetrics
}
// NewModuleInstance implements the modules.Module interface and returns
// a new instance for each VU.
func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance {
m, err := registerMetrics(vu)
if err != nil {
common.Throw(vu.Runtime(), err)
}
return &MqttAPI{vu: vu, metrics: m}
}
// 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{}
)