From 23f077ce7598ee3e8d5f02afb0d72bec013b6fdd Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Wed, 11 Dec 2024 12:26:48 -0500 Subject: [PATCH] refactor: move Wasm related code to pkg/common/wasm --- cmd/motr/main.go | 11 ++++++----- internal/vault/routes.go | 4 ++-- {internal/vault => pkg/common/wasm}/fetch.go | 2 +- {internal/vault => pkg/common/wasm}/wasm.go | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) rename {internal/vault => pkg/common/wasm}/fetch.go (99%) rename {internal/vault => pkg/common/wasm}/wasm.go (89%) diff --git a/cmd/motr/main.go b/cmd/motr/main.go index 96c9ad6c7..e368eb866 100644 --- a/cmd/motr/main.go +++ b/cmd/motr/main.go @@ -9,13 +9,14 @@ import ( "github.com/labstack/echo/v4" "github.com/onsonr/sonr/internal/vault" - "github.com/onsonr/sonr/internal/vault/types" + "github.com/onsonr/sonr/pkg/common/wasm" + "github.com/onsonr/sonr/pkg/config/motr" "github.com/onsonr/sonr/pkg/didauth/controller" ) var ( - env *types.Environment - config *types.Config + env *motr.Environment + config *motr.Config err error ) @@ -47,8 +48,8 @@ func main() { js.Global().Set("processConfig", js.FuncOf(processConfig)) e := echo.New() - e.Use(vault.WasmContextMiddleware) + e.Use(wasm.ContextMiddleware) e.Use(controller.Middleware(nil)) vault.RegisterRoutes(e, config) - vault.ServeFetch(e) + wasm.ServeFetch(e) } diff --git a/internal/vault/routes.go b/internal/vault/routes.go index f50cdc646..30467938e 100644 --- a/internal/vault/routes.go +++ b/internal/vault/routes.go @@ -8,10 +8,10 @@ import ( "github.com/labstack/echo/v4" "github.com/onsonr/sonr/internal/vault/context" - "github.com/onsonr/sonr/internal/vault/types" + "github.com/onsonr/sonr/pkg/config/motr" ) // RegisterRoutes registers the Decentralized Web Node API routes. -func RegisterRoutes(e *echo.Echo, config *types.Config) { +func RegisterRoutes(e *echo.Echo, config *motr.Config) { e.Use(context.Middleware(config)) } diff --git a/internal/vault/fetch.go b/pkg/common/wasm/fetch.go similarity index 99% rename from internal/vault/fetch.go rename to pkg/common/wasm/fetch.go index c26d3b972..ff6af6833 100644 --- a/internal/vault/fetch.go +++ b/pkg/common/wasm/fetch.go @@ -1,7 +1,7 @@ //go:build js && wasm // +build js,wasm -package vault +package wasm import ( "bytes" diff --git a/internal/vault/wasm.go b/pkg/common/wasm/wasm.go similarity index 89% rename from internal/vault/wasm.go rename to pkg/common/wasm/wasm.go index 041264420..6ef8f91a1 100644 --- a/internal/vault/wasm.go +++ b/pkg/common/wasm/wasm.go @@ -1,7 +1,7 @@ //go:build js && wasm // +build js,wasm -package vault +package wasm import ( "encoding/base64" @@ -10,7 +10,7 @@ import ( "github.com/labstack/echo/v4" ) -func WasmContextMiddleware(next echo.HandlerFunc) echo.HandlerFunc { +func ContextMiddleware(next echo.HandlerFunc) echo.HandlerFunc { return func(c echo.Context) error { // Extract WASM context from headers if wasmCtx := c.Request().Header.Get("X-Wasm-Context"); wasmCtx != "" {