36 lines
767 B
Go
36 lines
767 B
Go
package rudder
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
type ModulesService struct {
|
|
transport *transport
|
|
}
|
|
|
|
type CallParameters struct {
|
|
Module string
|
|
Fn string
|
|
Args any
|
|
DryRun bool
|
|
}
|
|
|
|
type CallResult struct {
|
|
Result any `json:"result"`
|
|
Error string `json:"error"`
|
|
Log []any `json:"log"`
|
|
Console []string `json:"console"`
|
|
}
|
|
|
|
func (s *ModulesService) Call(ctx context.Context, parameters CallParameters) (*CallResult, error) {
|
|
var result CallResult
|
|
path := fmt.Sprintf("/modules/%s/%s", parameters.Module, parameters.Fn)
|
|
body := map[string]any{"args": parameters.Args, "dryRun": parameters.DryRun}
|
|
if err := s.transport.do(ctx, http.MethodPost, path, nil, body, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|