Skip to content

Commit

Permalink
fix:wasm build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
LinceMathew committed Sep 8, 2024
1 parent 514cc88 commit d467d1d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
10 changes: 7 additions & 3 deletions cmdexec/cmdexec.wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"os"
"strings"
"time"

"github.com/HexmosTech/httpie-go"
)
Expand All @@ -21,15 +22,18 @@ import (
// to stdout.
// Once execution finishes, previous CWD is restored,
// and the command output is returned as a string
func ExecCommand(cmdSlice []string, stdinBody string, apiDir string) (httpie.ExResponse, error) {
func ExecCommand(cmdSlice []string, stdinBody string, apiDir string) (httpie.ExResponse, int64, error) {
proxyURL := os.Getenv("PROXY_URL")
proxyUserName := os.Getenv("PROXY_USERNAME")
proxyUserPassword := os.Getenv("PROXY_PASSWORD")
allowRedirects := true
start := time.Now()
resp, err := httpie.Lama2Entry(cmdSlice, strings.NewReader(stdinBody), proxyURL, proxyUserName, proxyUserPassword, allowRedirects)
elapsed := time.Since(start)
responseTime := elapsed.Milliseconds()
if err != nil {
fmt.Println("Got error while executing", err)
return httpie.ExResponse{}, errors.New("Error from API executor: " + err.Error())
return httpie.ExResponse{}, 0, errors.New("Error from API executor: " + err.Error())
}
return resp, nil
return resp, responseTime, nil
}
11 changes: 6 additions & 5 deletions controller/controller.wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ import (
"github.com/HexmosTech/lama2/parser"

"github.com/HexmosTech/lama2/cmdexec"
outputmanager "github.com/HexmosTech/lama2/outputManager"
preprocess "github.com/HexmosTech/lama2/preprocess"
)

var worker js.Value

func HandleParsedFile(parsedAPI *gabs.Container) (httpie.ExResponse, *lama2cmd.Opts) {
func HandleParsedFile(parsedAPI *gabs.Container) (httpie.ExResponse, *lama2cmd.Opts, []outputmanager.ResponseTime, []outputmanager.StatusCode, []outputmanager.ContentSize, error) {
fmt.Println("HandleParsedFile:")
fmt.Println("HandleParsedFile:", parsedAPI)
return HandleParsedFileHelper(parsedAPI)
}

func ProcessWasmInput(data string) (httpie.ExResponse, *lama2cmd.Opts) {
func ProcessWasmInput(data string) (httpie.ExResponse, *lama2cmd.Opts, []outputmanager.ResponseTime, []outputmanager.StatusCode, []outputmanager.ContentSize, error) {
apiContent := data
p := parser.NewLama2Parser()
fmt.Printf("apicontent %+v\n", apiContent)
Expand Down Expand Up @@ -74,7 +75,7 @@ func ExecuteRequestorBlockHelper(resp httpie.ExResponse, headersString string, e
return resp
}

func processBlocks(parsedAPIblocks []*gabs.Container, o *lama2cmd.Opts, dir string) (httpie.ExResponse, *lama2cmd.Opts) {
func processBlocks(parsedAPIblocks []*gabs.Container, o *lama2cmd.Opts, dir string) (httpie.ExResponse, *lama2cmd.Opts, []outputmanager.ResponseTime, []outputmanager.StatusCode, []outputmanager.ContentSize) {
worker = preprocess.InitWebWorker() // Initialize the web worker
var resp httpie.ExResponse
for i, block := range parsedAPIblocks {
Expand All @@ -85,10 +86,10 @@ func processBlocks(parsedAPIblocks []*gabs.Container, o *lama2cmd.Opts, dir stri
case "processor":
ExecuteProcessorBlock(block)
case "Lama2File":
resp = processLama2FileBlock(block, worker, o, dir)
resp, _ = processLama2FileBlock(block, worker, o, dir)
}
}
return resp, o
return resp, o, nil, nil, nil
}

func ExecuteProcessorBlock(block *gabs.Container) {
Expand Down
2 changes: 1 addition & 1 deletion l2.wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func wasmLamaPromise() js.Func {
handler := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
resolve := args[0]
go func() {
result, _ := controller.ProcessWasmInput(inputdata)
result, _, _, _, _, _ := controller.ProcessWasmInput(inputdata)
resultJSON, err := json.Marshal(result)
if err != nil {
fmt.Println("Error:", err)
Expand Down

0 comments on commit d467d1d

Please sign in to comment.