Files
sonr/cmd/motr/main.go
T

74 lines
1.6 KiB
Go
Raw Normal View History

//go:build js && wasm
// +build js,wasm
package main
import (
2024-12-18 15:53:45 -05:00
"context"
"database/sql"
"encoding/json"
"syscall/js"
"github.com/labstack/echo/v4"
2024-12-18 15:53:45 -05:00
_ "github.com/ncruces/go-sqlite3/driver"
_ "github.com/ncruces/go-sqlite3/embed"
2024-12-16 15:29:54 -05:00
"github.com/onsonr/sonr/cmd/motr/wasm"
2024-12-19 00:48:42 +00:00
sink "github.com/onsonr/sonr/deploy/sink"
2024-12-16 15:29:54 -05:00
"github.com/onsonr/sonr/internal/config/motr"
2024-12-18 15:53:45 -05:00
vault "github.com/onsonr/sonr/pkg/vault/routes"
)
var (
env *motr.Environment
config *motr.Config
err error
)
func broadcastTx(this js.Value, args []js.Value) interface{} {
return nil
}
func simulateTx(this js.Value, args []js.Value) interface{} {
return nil
}
2024-12-16 15:29:54 -05:00
func syncData(this js.Value, args []js.Value) interface{} {
if len(args) < 1 {
return nil
}
configString := args[0].String()
if err := json.Unmarshal([]byte(configString), &config); err != nil {
println("Error parsing config:", err.Error())
return nil
}
return nil
}
func main() {
// Load dwn config
js.Global().Set("broadcastTx", js.FuncOf(broadcastTx))
js.Global().Set("simulateTx", js.FuncOf(simulateTx))
2024-12-16 15:29:54 -05:00
js.Global().Set("syncData", js.FuncOf(syncData))
e := echo.New()
e.Use(wasm.ContextMiddleware)
// e.Use(controller.Middleware(nil))
2024-12-05 20:36:58 -05:00
vault.RegisterRoutes(e, config)
wasm.ServeFetch(e)
}
2024-12-18 15:53:45 -05:00
2024-12-19 00:48:42 +00:00
// createDB initializes and returns a configured database connection
func createDB() (*sql.DB, error) {
2024-12-18 15:53:45 -05:00
db, err := sql.Open("sqlite3", ":memory:")
if err != nil {
return nil, err
}
// create tables
2024-12-19 00:48:42 +00:00
if _, err := db.ExecContext(context.Background(), sink.SchemaVaultSQL); err != nil {
2024-12-18 15:53:45 -05:00
return nil, err
}
return db, nil
}