mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 18:01:39 +00:00
59 lines
1.0 KiB
Go
59 lines
1.0 KiB
Go
package files
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
_ "embed"
|
||
|
|
"os"
|
||
|
|
)
|
||
|
|
|
||
|
|
//go:embed vault.wasm
|
||
|
|
var vaultWasmData []byte
|
||
|
|
|
||
|
|
func writeServiceWorkerJS(path string) error {
|
||
|
|
// Create the service worker file
|
||
|
|
file, err := os.Create(path)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
defer file.Close()
|
||
|
|
|
||
|
|
// Write the service worker file to the specified path
|
||
|
|
err = VaultServiceWorker(kVaultFileName).Render(context.Background(), file)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func writeVaultWASM(path string) error {
|
||
|
|
// Create the vault file
|
||
|
|
file, err := os.Create(path)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
defer file.Close()
|
||
|
|
|
||
|
|
// Write the embedded vault file to the specified path
|
||
|
|
err = os.WriteFile(file.Name(), vaultWasmData, 0o644)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func writeIndexHTML(path string) error {
|
||
|
|
// create the index file
|
||
|
|
file, err := os.Create(path)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
defer file.Close()
|
||
|
|
|
||
|
|
// write the index file to the specified path
|
||
|
|
err = IndexHTML().Render(context.Background(), file)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|