Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
altitude committed Jul 27, 2021
2 parents e5a44f0 + e8b8fb8 commit 5f59b2e
Showing 4 changed files with 61 additions and 5 deletions.
17 changes: 16 additions & 1 deletion api/http.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,10 @@ package api
import (
"context"
_ "embed"
"encoding/base64"
"encoding/json"
"fmt"
"log"
"strings"

"github.com/gin-contrib/cors"
@@ -118,7 +122,18 @@ func NewHttpAPI(lc fx.Lifecycle, resolver *ledger.Resolver) *HttpAPI {
}

if err != nil {
res["err"] = err.Error()
err_str := err.Error()
err_str = strings.ReplaceAll(err_str, "\n", "\r\n")
payload, err := json.Marshal(gin.H{
"error": err_str,
})
if err != nil {
log.Fatal(err)
}
payload_b64 := base64.StdEncoding.EncodeToString([]byte(payload))
link := fmt.Sprintf("https://play.numscript.org/?payload=%v", payload_b64)
res["err"] = err_str
res["details"] = link
}

c.JSON(200, res)
41 changes: 38 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ import (
"github.com/numary/ledger/config"
"github.com/numary/ledger/ledger"
"github.com/numary/ledger/storage"
"github.com/numary/machine/script/compiler"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/fx"
@@ -91,7 +92,7 @@ func Execute() {
},
})

script := &cobra.Command{
script_exec := &cobra.Command{
Use: "exec [ledger] [script]",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
@@ -135,15 +136,49 @@ func Execute() {
log.Fatal(err)
}

fmt.Println(res.StatusCode, string(b))
var result struct {
Err string `json:"err,omitempty"`
Ok bool `json:"ok"`
}
err = json.Unmarshal(b, &result)
if err != nil {
log.Fatal(err)
}
if result.Ok {
fmt.Println("Script ran successfully ✅")
} else {
log.Fatal(result.Err)
}
},
}

script_check := &cobra.Command{
Use: "check [script]",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
config.Init()

b, err := ioutil.ReadFile(args[0])

if err != nil {
log.Fatal(err)
}

_, err = compiler.Compile(string(b))
if err != nil {
log.Fatal(err)
} else {
fmt.Println("Script is correct ✅")
}
},
}

root.AddCommand(server)
root.AddCommand(conf)
root.AddCommand(UICmd)
root.AddCommand(store)
root.AddCommand(script)
root.AddCommand(script_exec)
root.AddCommand(script_check)

if err := root.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ require (
github.com/huandu/go-sqlbuilder v1.12.1
github.com/jackc/pgx/v4 v4.11.0
github.com/mattn/go-sqlite3 v1.14.7
github.com/numary/machine v0.0.0-20210721174107-2596ca4e5b60
github.com/numary/machine v0.0.0-20210726090747-5853ebec28f0
github.com/pkg/errors v0.8.1
github.com/spf13/cobra v1.1.3
github.com/spf13/viper v1.8.1
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -365,6 +365,8 @@ github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU=
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
@@ -416,6 +418,10 @@ github.com/numary/machine v0.0.0-20210719124351-aad80bd74032 h1:/0PgX+JYoyHa776k
github.com/numary/machine v0.0.0-20210719124351-aad80bd74032/go.mod h1:dvm8ZK8ywVDLDCKX8RyVT5bnD5/9A2RRmK8ZdJ9OvSM=
github.com/numary/machine v0.0.0-20210721174107-2596ca4e5b60 h1:qUYxAdLEOSbBR9l5Vse9kde3dwZgkHdwfuAfGHmriJ0=
github.com/numary/machine v0.0.0-20210721174107-2596ca4e5b60/go.mod h1:dvm8ZK8ywVDLDCKX8RyVT5bnD5/9A2RRmK8ZdJ9OvSM=
github.com/numary/machine v0.0.0-20210723112905-42b29a92fe8d h1:YfQ7urinEfBDyDGijNer3aYaNhHV7xhy5mE/XdYyHms=
github.com/numary/machine v0.0.0-20210723112905-42b29a92fe8d/go.mod h1:azMZte4ywWM0ISNMgMII4IS9XJ0N3ZAB7TfQ2Ay3dL0=
github.com/numary/machine v0.0.0-20210726090747-5853ebec28f0 h1:TM2r/u2KwZBipmd6s5q/mzlzWfNCFwEadH9xyYbvZAw=
github.com/numary/machine v0.0.0-20210726090747-5853ebec28f0/go.mod h1:azMZte4ywWM0ISNMgMII4IS9XJ0N3ZAB7TfQ2Ay3dL0=
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=

0 comments on commit 5f59b2e

Please sign in to comment.