feat: introduce mutual service for cross-service functionalities

This commit is contained in:
2025-04-03 20:02:15 -04:00
parent d00fbab208
commit 1ed286ff5f
26 changed files with 166 additions and 4 deletions

106
.taskfiles/Docker.yml Normal file
View File

@@ -0,0 +1,106 @@
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"
silent: true
vars:
ROOT_DIR:
sh: git rev-parse --show-toplevel
tasks:
default:
cmds:
- task: test
- task: gen
- task: build
test:
desc: Runs tests
cmds:
- defer: task clean
- task: test:go
build:
desc: Builds code
cmds:
- rm -rf bin
- defer: rm -rf .task
- task: build:go
# - task: build:docker
gen:
desc: Generates code
cmds:
- defer: rm -rf .task
- task: gen:templ
- task: gen:sqlc
clean:
cmds:
- rm -rf bin
- rm -rf dist
- rm -rf .task
#
# Internal tasks
#
build:go:
desc: Builds Go code
dir: "{{.ROOT_DIR}}"
env:
GOOS: js
GOARCH: wasm
sources:
- "main.go"
- "**/*.go"
generates:
- bin/motr.wasm
cmds:
- go build -o bin/motr.wasm ./cmd/vault
build:docker:
desc: Builds Docker image
dir: "{{.ROOT_DIR}}"
env:
GOOS: js
GOARCH: wasm
sources:
- "main.go"
- "**/*.go"
generates:
- bin/motr.wasm
cmds:
- go build -o bin/motr.wasm .
gen:templ:
internal: true
dir: "{{.ROOT_DIR}}"
sources:
- "**/*.templ"
generates:
- "**/_templ.go"
cmds:
- templ generate
gen:sqlc:
internal: true
dir: "{{.ROOT_DIR}}/internal/sink"
sources:
- "**/query.sql"
- "**/schema.sql"
generates:
- "**/db.go"
- "**/querier.go"
- "**/models.go"
- "**/query.sql.go"
cmds:
- sqlc generate
test:go:
internal: true
dir: "{{.ROOT_DIR}}"
sources:
- "**/*.go"
cmds:
- go test -v ./...

View File

@@ -14,7 +14,7 @@ import (
"sync"
"syscall/js"
"github.com/onsonr/motr/pkg/resolver"
"github.com/onsonr/motr/services/resolver"
)
var (

View File

@@ -9,7 +9,7 @@ import (
"sync"
"syscall/js"
"github.com/onsonr/motr/pkg/controller"
"github.com/onsonr/motr/services/controller"
)
var (

10
internal/config/mutual.go Normal file
View File

@@ -0,0 +1,10 @@
package config
type MutualConfig struct {
MotrCID string `json:"motr_cid"`
MotrAddress string `json:"motr_address"`
IpfsGatewayURL string `json:"ipfs_gateway_url"`
SonrAPIURL string `json:"sonr_api_url"`
SonrRPCURL string `json:"sonr_rpc_url"`
SonrChainID string `json:"sonr_chain_id"`
}

View File

@@ -0,0 +1 @@
package middleware

View File

@@ -0,0 +1 @@
package middleware

View File

@@ -0,0 +1 @@
package middleware

View File

@@ -5,7 +5,7 @@ package controller
import (
"github.com/labstack/echo/v4"
echomiddleware "github.com/labstack/echo/v4/middleware"
"github.com/onsonr/motr/config"
"github.com/onsonr/motr/internal/config"
"github.com/onsonr/motr/internal/models"
)

View File

@@ -0,0 +1 @@
package handlers

38
services/mutual/server.go Normal file
View File

@@ -0,0 +1,38 @@
//go:build js && wasm
package mutual
import (
"github.com/labstack/echo/v4"
echomiddleware "github.com/labstack/echo/v4/middleware"
"github.com/onsonr/motr/internal/config"
"github.com/onsonr/motr/internal/models"
)
// New returns a new Vault instance
func New(config *config.MutualConfig, dbq *models.Queries, mdws ...echo.MiddlewareFunc) (*echo.Echo, error) {
e := echo.New()
// Override default behaviors
e.IPExtractor = echo.ExtractIPDirect()
e.HTTPErrorHandler = handleError()
// Built-in middleware
e.Use(echomiddleware.Logger())
e.Use(echomiddleware.Recover())
e.Use(mdws...)
registerRoutes(e)
return e, nil
}
func handleError() echo.HTTPErrorHandler {
return func(err error, c echo.Context) {
if he, ok := err.(*echo.HTTPError); ok {
// Log the error if needed
c.Logger().Errorf("Error: %v", he.Message)
}
}
}
// RegisterRoutes registers the Decentralized Web Node API routes.
func registerRoutes(e *echo.Echo) {
}

View File

@@ -0,0 +1 @@
package handlers

View File

@@ -0,0 +1 @@
package handlers

View File

@@ -0,0 +1 @@
package handlers

View File

@@ -0,0 +1 @@
package routes

View File

@@ -5,7 +5,7 @@ package resolver
import (
"github.com/labstack/echo/v4"
echomiddleware "github.com/labstack/echo/v4/middleware"
"github.com/onsonr/motr/config"
"github.com/onsonr/motr/internal/config"
"github.com/onsonr/motr/internal/models"
)