Skip to content

Instantly share code, notes, and snippets.

@kentquirk
Created June 28, 2018 02:15
Show Gist options
  • Save kentquirk/9b425794b4e1eedc3c8f434c54df8e8f to your computer and use it in GitHub Desktop.
Save kentquirk/9b425794b4e1eedc3c8f434c54df8e8f to your computer and use it in GitHub Desktop.
Simple gopherjs module demo
package main
//go:generate gopherjs build --minify
// This is an experiment to see if gopherjs can reasonably generate js code from go source
// so that we can have a single-source solution for keys and addresses.
// Use "go generate" to build this.
import (
"crypto/sha256"
"github.com/gopherjs/gopherjs/js"
)
func main() {
js.Module.Get("exports").Set("hashit", hashit)
}
func hashit(s string) []byte {
h := sha256.New()
h.Write([]byte(s))
return h.Sum(nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment