Пример #1
0
func goToJs(goCode string) (jsCode string, err error) {
	started := time.Now()
	defer func() { fmt.Println("goToJs taken:", time.Since(started)) }()
	gopherjslibLock.Lock()
	defer gopherjslibLock.Unlock()

	code := strings.NewReader(goCode)

	var out bytes.Buffer
	err = gopherjslib.Build(code, &out, nil)
	if err != nil {
		return "", err
	}

	return out.String(), nil
}
Пример #2
0
func (f *file) compile() error {
	if f.r != nil {
		return nil
	}

	Log.Println("Compiling…")
	defer Log.Println("Compilation finished")

	buf := new(bytes.Buffer)
	err := gopherjslib.Build(f.f, buf, &gopherjslib.Options{Minify: true})
	if err != nil {
		Log.Printf("Compilation failed: %v", err)
		return err
	}
	f.r = bytes.NewReader(buf.Bytes())
	f.size = int64(len(buf.Bytes()))
	return nil
}