Example #1
0
func goFilesToJs(goFiles []string) (jsCode string, err error) {
	started := time.Now()
	defer func() { fmt.Println("goFilesToJs taken:", time.Since(started)) }()
	gopherjslibLock.Lock()
	defer gopherjslibLock.Unlock()

	var out bytes.Buffer
	builder := gopherjslib.NewBuilder(&out, nil)

	for _, goFile := range goFiles {
		file, err := os.Open(goFile)
		if err != nil {
			return "", err
		}
		defer file.Close()

		builder.Add(goFile, file)
	}

	err = builder.Build()
	if err != nil {
		return "", err
	}

	return out.String(), nil
}
Example #2
0
func goReadersToJs(names []string, goReaders []io.Reader) (jsCode string, err error) {
	started := time.Now()
	defer func() { fmt.Println("goReadersToJs taken:", time.Since(started)) }()
	gopherjslibLock.Lock()
	defer gopherjslibLock.Unlock()

	var out bytes.Buffer
	builder := gopherjslib.NewBuilder(&out, &gopherjslib.Options{Minify: true})

	for i, goReader := range goReaders {
		builder.Add(names[i], goReader)
	}

	err = builder.Build()
	if err != nil {
		return "", err
	}

	return out.String(), nil
}