Skip to content

Commit

Permalink
refactor(go): use 'os/exec' instead of go-memexec (#7)
Browse files Browse the repository at this point in the history
* feat(go): use 'os/exec' instead of go-memexec

* add go tests to github action

* ci: fix go test action

* fix(go): better error handling if slangroom-exec not found

* fix(go): remove linux-x64 binary
  • Loading branch information
FilippoTrotter authored Oct 15, 2024
1 parent b6e7958 commit 8d450e8
Show file tree
Hide file tree
Showing 298 changed files with 26 additions and 161,188 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ jobs:
- uses: ./.github/actions/setup
- run: make tests


- uses: actions/setup-go@v5
with:
go-version: '1.22'

- name: Build slangroom-exec
run: make slangroom-exec
working-directory: bindings/go

- name: Add slangroom-exec to PATH
run: echo "${{ github.workspace }}/bindings/go" >> $GITHUB_PATH
working-directory: bindings/go

- name: Go Tests
run: go test ./...
working-directory: bindings/go

release:
needs: test
if: github.ref == 'refs/heads/main'
Expand Down
6 changes: 1 addition & 5 deletions bindings/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ module github.com/dyne/slangroom-exec/bindings/go

go 1.22

require (
github.com/amenzhinsky/go-memexec v0.7.1
github.com/stretchr/testify v1.9.0
)
require github.com/stretchr/testify v1.9.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.0.0-20210903071746-97244b99971b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 0 additions & 4 deletions bindings/go/go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
github.com/amenzhinsky/go-memexec v0.7.1 h1:DVm4cXzklaNWZoTJgZUi/dlXtelhC7QBtX4luKjl1qk=
github.com/amenzhinsky/go-memexec v0.7.1/go.mod h1:ApTO9/i2bcii7kvIXi74gum+/zYDzkiOXtuBZoYOKVE=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sys v0.0.0-20210903071746-97244b99971b h1:3Dq0eVHn0uaQJmPO+/aYPI/fRMqdrVDbu7MQcku54gg=
golang.org/x/sys v0.0.0-20210903071746-97244b99971b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
Binary file removed bindings/go/slangroom-exec
Binary file not shown.
22 changes: 8 additions & 14 deletions bindings/go/slangroom.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
package slangroom

import (
_ "embed"
"fmt"
"io"
"log"
"os/exec"
"strings"

b64 "encoding/base64"

"github.com/amenzhinsky/go-memexec"
)

// Embedding Zenroom binary using go:embed
//
//go:embed slangroom-exec
var slangroomBinary []byte

type SlangResult struct {
Output string
Logs string
}

func SlangroomExec(conf string, contract string, data string, keys string, extra string, context string) (SlangResult, error) {
exec, err := memexec.New(slangroomBinary)
if err != nil {
log.Fatalf("Failed to load Slangroom executable from memory: %v", err)
}
defer exec.Close()

if _, err := exec.LookPath("slangroom-exec"); err != nil {
return SlangResult{}, fmt.Errorf(
"slangroom-exec command not found. Please install it by running:\n\n" +
"wget https://github.com/dyne/slangroom-exec/releases/latest/download/slangroom-exec-$(uname)-$(uname -m) \\\n" +
"-O ~/.local/bin/slangroom-exec && chmod +x ~/.local/bin/slangroom-exec",
)
}
execCmd := exec.Command("slangroom-exec")

stdout, err := execCmd.StdoutPipe()
if err != nil {
log.Fatalf("Failed to create stdout pipe: %v", err)
Expand Down
201 changes: 0 additions & 201 deletions bindings/go/vendor/github.com/amenzhinsky/go-memexec/LICENSE

This file was deleted.

61 changes: 0 additions & 61 deletions bindings/go/vendor/github.com/amenzhinsky/go-memexec/README.md

This file was deleted.

Loading

0 comments on commit 8d450e8

Please sign in to comment.