Created
June 28, 2018 02:15
-
-
Save kentquirk/9b425794b4e1eedc3c8f434c54df8e8f to your computer and use it in GitHub Desktop.
Simple gopherjs module demo
This file contains hidden or 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
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