-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Different files for wasm and cli build
- Loading branch information
Showing
24 changed files
with
1,763 additions
and
405 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//go:build wasm | ||
|
||
// Package `cmdexec` provides a facility to execute | ||
// l2 commands, stream output to stdout, while also | ||
// providing ability to retrieve the command output as | ||
// a string. | ||
package cmdexec | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
// "os" | ||
"strings" | ||
|
||
"github.com/HexmosTech/httpie-go" | ||
// "github.com/HexmosTech/lama2/utils" | ||
// "github.com/rs/zerolog/log" | ||
// "github.com/HexmosTech/httpie-go" | ||
) | ||
|
||
// ExecCommand changes directory to the given `apiDir` | ||
// and then executes the command specified in `cmdStr` | ||
// During command execution, ExecCommand streams output | ||
// to stdout. | ||
// Once execution finishes, previous CWD is restored, | ||
// and the command output is returned as a string | ||
func ExecCommand(cmdSlice []string, stdinBody string) (httpie.ExResponse, error) { | ||
fmt.Println("Inside cmd exec code") | ||
fmt.Println("Inside cmd exec code httpie Integer", httpie.Int(24601)) | ||
proxyURL := "https://proxyserver.hexmos.com/" | ||
proxyUserName := "proxyServer" | ||
proxyUserPassword := "proxy22523146server" | ||
allowRedirects := true | ||
resp, err := httpie.Lama2Entry(cmdSlice, strings.NewReader(stdinBody), proxyURL, proxyUserName, proxyUserPassword, allowRedirects) | ||
// resp, err := httpie.Lama2Entry(cmdSlice, strings.NewReader(stdinBody), "", "", "", false) | ||
fmt.Println("error:", err) | ||
fmt.Println("Data Response:", resp) | ||
if err != nil { | ||
// log.Fatal().Str("Error from the API executor", err.Error()).Msg("") | ||
fmt.Println("Got error while executing", err) | ||
return httpie.ExResponse{}, errors.New("Error from API executor: " + err.Error()) | ||
} | ||
// log.Debug().Str("Response body from API executor", resp.Body).Msg("") | ||
// utils.ChangeWorkingDir(oldDir) | ||
// fmt.Println("Reponse fro httpie", resp) | ||
return resp, 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
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,55 @@ | ||
//go:build wasm | ||
|
||
package cmdexec | ||
|
||
import ( | ||
// "github.com/rs/zerolog/log" | ||
"fmt" | ||
"syscall/js" | ||
) | ||
|
||
// GetJSVm creates a new goja runtime instance | ||
// with console.log enabled | ||
|
||
// func GetJSVm() *goja.Runtime { | ||
// vm := goja.New() | ||
// new(require.Registry).Enable(vm) | ||
// console.Enable(vm) | ||
// return vm | ||
// } | ||
|
||
// RunVMCode takes in a JS snippet as a string, | ||
// executes the code in a JS VM, finally checks | ||
// whether there are any errors, and if yes, | ||
// logs the problem. | ||
// Note: the vm runtime remains modified; so if | ||
// you reuse the vm for other operations, the state | ||
// from previous invocations carry over | ||
func RunVMCode(jsCode string) { | ||
// log.Info().Str("Evaluated through syscall js:", jsCode).Msg("") | ||
js.Global().Call("eval", jsCode) | ||
// _, err := vm.RunString(jsCode) | ||
// if ex, ok := err.(*goja.Exception); ok { | ||
// log.Debug().Str("Error executing JS processor block", ex.String()).Msg("") | ||
// } | ||
} | ||
|
||
// GenerateChainCode takes in an HTTP response body | ||
// and comes up with some JS code to define the | ||
// "magic variable" result. What does the code do? | ||
// The result is stored as a JS object, if the input | ||
// value can be parsed as JSON. Otherwise the value is | ||
// stored as a simple string. | ||
func GenerateChainCode(httpRespBody string) string { | ||
code := `try { | ||
result = JSON.parse(String.raw` + "`" + httpRespBody + "`" + `) | ||
console.log("Stored as JSON") | ||
} catch (e) { | ||
result = String.raw` + "`" + httpRespBody + "`" + ` | ||
console.log(e) | ||
console.log("Stored as string") | ||
}` | ||
// log.Info().Str("Chain code generated", code).Msg("") | ||
fmt.Println("code:", code) | ||
return code | ||
} |
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
Oops, something went wrong.