-
Notifications
You must be signed in to change notification settings - Fork 853
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package javascript | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/dop251/goja" | ||
) | ||
|
||
func getMapFromValue(val goja.Value) (map[string]interface{}, error) { | ||
outVal := val.Export() | ||
v, ok := outVal.(map[string]interface{}) | ||
if !ok { | ||
return nil, errors.New("value is not of type map") | ||
} | ||
return v, nil | ||
} | ||
|
||
func getSliceFromValue(val goja.Value) ([]interface{}, error) { | ||
outVal := val.Export() | ||
v, ok := outVal.([]interface{}) | ||
if !ok { | ||
return nil, errors.New("value is not of type slice") | ||
} | ||
return v, nil | ||
} | ||
|
||
func getMapSliceFromValue(val goja.Value) ([]map[string]interface{}, error) { | ||
outVal := val.Export() | ||
if v, ok := outVal.([]map[string]interface{}); ok { | ||
return v, nil | ||
} | ||
vSlice, ok := outVal.([]interface{}) | ||
if !ok { | ||
return nil, errors.New("value is not of type map slice") | ||
} | ||
v := make([]map[string]interface{}, len(vSlice)) | ||
for i, e := range vSlice { | ||
v[i], ok = e.(map[string]interface{}) | ||
if !ok { | ||
return nil, errors.New("value is not of type map slice") | ||
} | ||
} | ||
return v, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package javascript | ||
|
||
import "github.com/benthosdev/benthos/v4/public/service" | ||
|
||
// Logger wraps the service.Logger so that we can define the below methods. | ||
type Logger struct { | ||
l *service.Logger | ||
} | ||
|
||
// Log will be used for "console.log()" in JS | ||
func (l *Logger) Log(message string) { | ||
l.l.Info(message) | ||
} | ||
|
||
// Warn will be used for "console.warn()" in JS | ||
func (l *Logger) Warn(message string) { | ||
l.l.Warn(message) | ||
} | ||
|
||
// Error will be used for "console.error()" in JS | ||
func (l *Logger) Error(message string) { | ||
l.l.Error(message) | ||
} |