Skip to content

Commit

Permalink
Proto WebUI
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Nov 28, 2023
1 parent 9fbbce5 commit cad958f
Show file tree
Hide file tree
Showing 12 changed files with 672 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ image:
install: $(NAME)
sudo install -Dm755 $(NAME) $(DESTDIR)$(PREFIX)/bin/$(NAME)

webui:

run: clean $(NAME)
./$(NAME)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/bahner/go-ma-actor
go 1.21

require (
github.com/bahner/go-ma v0.0.6-0.20231126211854-c1323073bd64
github.com/bahner/go-ma v0.0.5
github.com/c-bata/go-prompt v0.2.6
github.com/gdamore/tcell/v2 v2.6.0
github.com/libp2p/go-libp2p v0.32.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/bahner/go-ma v0.0.6-0.20231126211854-c1323073bd64 h1:dBGw1zZm46xJWUnVDT9BAbL8GUu8AwjWbP5Ddc7yRS4=
github.com/bahner/go-ma v0.0.6-0.20231126211854-c1323073bd64/go.mod h1:l9ty9QbOZfRUtovECXES7a01Su7xBYIBphFak1TOjVs=
github.com/bahner/go-ma v0.0.5 h1:RgQrINqn6zU4avHDwoYfPCtMnpU9OpTkOUaFcTsS0MM=
github.com/bahner/go-ma v0.0.5/go.mod h1:l9ty9QbOZfRUtovECXES7a01Su7xBYIBphFak1TOjVs=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
Expand Down
1 change: 1 addition & 0 deletions webui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.cid
5 changes: 5 additions & 0 deletions webui/.publish
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

CID=$(2>/dev/null ipfs add -r static | tail -n1 | awk '{print $2}')

echo ${CID}
27 changes: 27 additions & 0 deletions webui/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/make -ef

CID = .cid
WASM = static/main.wasm
export GOOS=js
export GOARCH=wasm

default: clean tidy $(WASM) publish

$(WASM):
go build -o $(WASM) main.go

publish: $(CID)

$(CID): $(WASM)
./.publish > $(CID)

open: $(CID)
echo $$(cat $(CID)| xargs -I{} xdg-open ipfs://{})

clean:
rm -f $(WASM)

tidy:
go mod tidy

.PHONY: publish open clean tidy
7 changes: 7 additions & 0 deletions webui/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module webui

go 1.21.4

require github.com/sirupsen/logrus v1.9.3

require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
15 changes: 15 additions & 0 deletions webui/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
25 changes: 25 additions & 0 deletions webui/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"crypto"
_ "crypto/sha512"
"encoding/hex"
"syscall/js"

log "github.com/sirupsen/logrus"
)

func main() {
log.SetLevel(log.DebugLevel)
done := make(chan struct{})
js.Global().Set("wasmHash", js.FuncOf(hash))
<-done
}

func hash(this js.Value, args []js.Value) interface{} {
log.Debugf("hashing: %s", args[0].String())
h := crypto.SHA512.New()
h.Write([]byte(args[0].String()))

return hex.EncodeToString(h.Sum(nil))
}
26 changes: 26 additions & 0 deletions webui/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<html>
<head>
<meta charset="utf-8"/>
<script src="wasm_exec.js"></script>
<script>
const go = new Go();
WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => {
go.run(result.instance);
});
</script>
</head>
<body>
<div>
<label for="inputField">Enter value</label>
<input id="inputField" name="Hash" type="text">
<div id="outputHash" style="font-size: 20px"></div>
</div>
<script>
var inputField = document.querySelector('#inputField')
var outputHash = document.querySelector('#outputHash')
inputField.addEventListener('keyup', function() {
outputHash.innerHTML = wasmHash(inputField.value) // The function 'wasmHash' is defined in the Go code
});
</script>
</body>
</html>
Binary file added webui/static/main.wasm
Binary file not shown.
Loading

0 comments on commit cad958f

Please sign in to comment.