Skip to content

Commit

Permalink
refactor: simplify addon API
Browse files Browse the repository at this point in the history
  • Loading branch information
szkiba committed Jun 12, 2023
1 parent b788376 commit 80ad15f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
21 changes: 11 additions & 10 deletions g0/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@ import (
)

func registerBuiltins() {
RegisterExports(stdlib.Exports)
RegisterExports(logrus.Exports)
RegisterExports(resty.Exports)
RegisterExports(testify.Exports)
RegisterExports(goquery.Exports)
RegisterExports(gjson.Exports)
RegisterExports(jsonpath.Exports)
RegisterExports(jsonschema.Exports)
RegisterExports(gofakeit.Exports)
registerExports(stdlib.Exports)
registerExports(logrus.Exports)
registerExports(resty.Exports)
registerExports(testify.Exports)
registerExports(goquery.Exports)
registerExports(gjson.Exports)
registerExports(jsonpath.Exports)
registerExports(jsonschema.Exports)
registerExports(gofakeit.Exports)
}

func registerExtension() {
modules.Register("k6/x/g0", New())
}

func Bootstrap() {
func Bootstrap(addons ...ExportsFunc) {
registerBuiltins()
registerExports(addons...)
redirectStdin()
registerExtension()
}
8 changes: 4 additions & 4 deletions g0/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

type ExportsFunc func(modules.VU) interp.Exports

func RegisterExports(fn ExportsFunc) {
registry.register(fn)
func registerExports(fn ...ExportsFunc) {
registry.register(fn...)
}

type exportsRegistry struct {
Expand All @@ -25,11 +25,11 @@ type exportsRegistry struct {

var registry exportsRegistry

func (r *exportsRegistry) register(fn ExportsFunc) {
func (r *exportsRegistry) register(fn ...ExportsFunc) {
r.mu.Lock()
defer r.mu.Unlock()

r.exports = append(r.exports, fn)
r.exports = append(r.exports, fn...)
}

func (r *exportsRegistry) merge(vu modules.VU) (interp.Exports, error) { //nolint:varnamelen
Expand Down

0 comments on commit 80ad15f

Please sign in to comment.