mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-10-06 08:19:07 +00:00
Merge pull request #19 from DeBrosOfficial/convert-gitdebros
replaced git.debros.io with github.com
This commit is contained in:
commit
44498ff381
@ -11,7 +11,7 @@ Thanks for helping improve the network! This guide covers setup, local dev, test
|
|||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://git.debros.io/DeBros/network.git
|
git clone https://github.com/DeBrosOfficial/network.git
|
||||||
cd network
|
cd network
|
||||||
make deps
|
make deps
|
||||||
```
|
```
|
||||||
|
2
Makefile
2
Makefile
@ -33,7 +33,7 @@ build: deps
|
|||||||
go build -ldflags "$(LDFLAGS)" -o bin/node ./cmd/node
|
go build -ldflags "$(LDFLAGS)" -o bin/node ./cmd/node
|
||||||
go build -ldflags "$(LDFLAGS)" -o bin/network-cli cmd/cli/main.go
|
go build -ldflags "$(LDFLAGS)" -o bin/network-cli cmd/cli/main.go
|
||||||
# Inject gateway build metadata via pkg path variables
|
# Inject gateway build metadata via pkg path variables
|
||||||
go build -ldflags "$(LDFLAGS) -X 'git.debros.io/DeBros/network/pkg/gateway.BuildVersion=$(VERSION)' -X 'git.debros.io/DeBros/network/pkg/gateway.BuildCommit=$(COMMIT)' -X 'git.debros.io/DeBros/network/pkg/gateway.BuildTime=$(DATE)'" -o bin/gateway ./cmd/gateway
|
go build -ldflags "$(LDFLAGS) -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildVersion=$(VERSION)' -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildCommit=$(COMMIT)' -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildTime=$(DATE)'" -o bin/gateway ./cmd/gateway
|
||||||
@echo "Build complete! Run ./bin/network-cli version"
|
@echo "Build complete! Run ./bin/network-cli version"
|
||||||
|
|
||||||
# Clean build artifacts
|
# Clean build artifacts
|
||||||
|
@ -94,7 +94,7 @@ A robust, decentralized peer-to-peer network built in Go, providing distributed
|
|||||||
### 1. Clone and Setup
|
### 1. Clone and Setup
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://git.debros.io/DeBros/network.git
|
git clone https://github.com/DeBrosOfficial/network.git
|
||||||
cd network
|
cd network
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ go run ./cmd/node --config configs/node.yaml
|
|||||||
Run the install script for a secure, production-ready setup:
|
Run the install script for a secure, production-ready setup:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -sSL https://git.debros.io/DeBros/network/raw/branch/main/scripts/install-debros-network.sh | sudo bash
|
curl -sSL https://github.com/DeBrosOfficial/network/raw/branch/main/scripts/install-debros-network.sh | sudo bash
|
||||||
```
|
```
|
||||||
|
|
||||||
**What the Script Does:**
|
**What the Script Does:**
|
||||||
|
@ -12,9 +12,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/anyoneproxy"
|
"github.com/DeBrosOfficial/network/pkg/anyoneproxy"
|
||||||
"git.debros.io/DeBros/network/pkg/auth"
|
"github.com/DeBrosOfficial/network/pkg/auth"
|
||||||
"git.debros.io/DeBros/network/pkg/client"
|
"github.com/DeBrosOfficial/network/pkg/client"
|
||||||
"github.com/libp2p/go-libp2p/core/crypto"
|
"github.com/libp2p/go-libp2p/core/crypto"
|
||||||
"github.com/libp2p/go-libp2p/core/peer"
|
"github.com/libp2p/go-libp2p/core/peer"
|
||||||
)
|
)
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/gateway"
|
"github.com/DeBrosOfficial/network/pkg/gateway"
|
||||||
"git.debros.io/DeBros/network/pkg/logging"
|
"github.com/DeBrosOfficial/network/pkg/logging"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/gateway"
|
"github.com/DeBrosOfficial/network/pkg/gateway"
|
||||||
"git.debros.io/DeBros/network/pkg/logging"
|
"github.com/DeBrosOfficial/network/pkg/logging"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,10 +11,10 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/anyoneproxy"
|
"github.com/DeBrosOfficial/network/pkg/anyoneproxy"
|
||||||
"git.debros.io/DeBros/network/pkg/config"
|
"github.com/DeBrosOfficial/network/pkg/config"
|
||||||
"git.debros.io/DeBros/network/pkg/logging"
|
"github.com/DeBrosOfficial/network/pkg/logging"
|
||||||
"git.debros.io/DeBros/network/pkg/node"
|
"github.com/DeBrosOfficial/network/pkg/node"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/client"
|
"github.com/DeBrosOfficial/network/pkg/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getenv(k, def string) string {
|
func getenv(k, def string) string {
|
||||||
@ -42,7 +42,9 @@ func TestClient_Database_CreateQueryMigrate(t *testing.T) {
|
|||||||
var peers []string
|
var peers []string
|
||||||
for _, p := range parts {
|
for _, p := range parts {
|
||||||
p = strings.TrimSpace(p)
|
p = strings.TrimSpace(p)
|
||||||
if p != "" { peers = append(peers, p) }
|
if p != "" {
|
||||||
|
peers = append(peers, p)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cfg.BootstrapPeers = peers
|
cfg.BootstrapPeers = peers
|
||||||
}
|
}
|
||||||
@ -52,9 +54,13 @@ func TestClient_Database_CreateQueryMigrate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c, err := client.NewClient(cfg)
|
c, err := client.NewClient(cfg)
|
||||||
if err != nil { t.Fatalf("new client: %v", err) }
|
if err != nil {
|
||||||
if err := c.Connect(); err != nil { t.Fatalf("connect: %v", err) }
|
t.Fatalf("new client: %v", err)
|
||||||
t.Cleanup(func(){ _ = c.Disconnect() })
|
}
|
||||||
|
if err := c.Connect(); err != nil {
|
||||||
|
t.Fatalf("connect: %v", err)
|
||||||
|
}
|
||||||
|
t.Cleanup(func() { _ = c.Disconnect() })
|
||||||
|
|
||||||
// Unique table per run
|
// Unique table per run
|
||||||
table := fmt.Sprintf("e2e_items_client_%d", time.Now().UnixNano())
|
table := fmt.Sprintf("e2e_items_client_%d", time.Now().UnixNano())
|
||||||
@ -78,6 +84,10 @@ func TestClient_Database_CreateQueryMigrate(t *testing.T) {
|
|||||||
ctx3, cancel3 := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx3, cancel3 := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel3()
|
defer cancel3()
|
||||||
res, err := c.Database().Query(ctx3, fmt.Sprintf("SELECT name FROM %s ORDER BY id", table))
|
res, err := c.Database().Query(ctx3, fmt.Sprintf("SELECT name FROM %s ORDER BY id", table))
|
||||||
if err != nil { t.Fatalf("query: %v", err) }
|
if err != nil {
|
||||||
if res.Count < 2 { t.Fatalf("expected at least 2 rows, got %d", res.Count) }
|
t.Fatalf("query: %v", err)
|
||||||
|
}
|
||||||
|
if res.Count < 2 {
|
||||||
|
t.Fatalf("expected at least 2 rows, got %d", res.Count)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/client"
|
"github.com/DeBrosOfficial/network/pkg/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
|||||||
module git.debros.io/DeBros/network
|
module github.com/DeBrosOfficial/network
|
||||||
|
|
||||||
go 1.23.8
|
go 1.23.8
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
|
|
||||||
libp2ppubsub "github.com/libp2p/go-libp2p-pubsub"
|
libp2ppubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/anyoneproxy"
|
"github.com/DeBrosOfficial/network/pkg/anyoneproxy"
|
||||||
"git.debros.io/DeBros/network/pkg/pubsub"
|
"github.com/DeBrosOfficial/network/pkg/pubsub"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client implements the NetworkClient interface
|
// Client implements the NetworkClient interface
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/pubsub"
|
"github.com/DeBrosOfficial/network/pkg/pubsub"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MakeJWT creates a minimal JWT-like token with a json payload
|
// MakeJWT creates a minimal JWT-like token with a json payload
|
||||||
|
@ -3,7 +3,7 @@ package client
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/pubsub"
|
"github.com/DeBrosOfficial/network/pkg/pubsub"
|
||||||
)
|
)
|
||||||
|
|
||||||
// contextKey for internal operations
|
// contextKey for internal operations
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/config"
|
"github.com/DeBrosOfficial/network/pkg/config"
|
||||||
"github.com/multiformats/go-multiaddr"
|
"github.com/multiformats/go-multiaddr"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/anyoneproxy"
|
"github.com/DeBrosOfficial/network/pkg/anyoneproxy"
|
||||||
"github.com/libp2p/go-libp2p/core/peer"
|
"github.com/libp2p/go-libp2p/core/peer"
|
||||||
"github.com/multiformats/go-multiaddr"
|
"github.com/multiformats/go-multiaddr"
|
||||||
"github.com/rqlite/gorqlite"
|
"github.com/rqlite/gorqlite"
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/pubsub"
|
"github.com/DeBrosOfficial/network/pkg/pubsub"
|
||||||
)
|
)
|
||||||
|
|
||||||
// pubSubBridge bridges between our PubSubClient interface and the pubsub package
|
// pubSubBridge bridges between our PubSubClient interface and the pubsub package
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
"github.com/rqlite/gorqlite"
|
"github.com/rqlite/gorqlite"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/config"
|
"github.com/DeBrosOfficial/network/pkg/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RQLiteManager manages an RQLite node instance
|
// RQLiteManager manages an RQLite node instance
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/storage"
|
"github.com/DeBrosOfficial/network/pkg/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// appsHandler implements minimal CRUD for apps within a namespace.
|
// appsHandler implements minimal CRUD for apps within a namespace.
|
||||||
@ -29,7 +29,9 @@ func (g *Gateway) appsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
ns = s
|
ns = s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if strings.TrimSpace(ns) == "" { ns = "default" }
|
if strings.TrimSpace(ns) == "" {
|
||||||
|
ns = "default"
|
||||||
|
}
|
||||||
db := g.client.Database()
|
db := g.client.Database()
|
||||||
nsID, err := g.resolveNamespaceID(ctx, ns)
|
nsID, err := g.resolveNamespaceID(ctx, ns)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -11,8 +11,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/client"
|
"github.com/DeBrosOfficial/network/pkg/client"
|
||||||
"git.debros.io/DeBros/network/pkg/storage"
|
"github.com/DeBrosOfficial/network/pkg/storage"
|
||||||
ethcrypto "github.com/ethereum/go-ethereum/crypto"
|
ethcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package gateway
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/client"
|
"github.com/DeBrosOfficial/network/pkg/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (g *Gateway) resolveNamespaceID(ctx context.Context, ns string) (interface{}, error) {
|
func (g *Gateway) resolveNamespaceID(ctx context.Context, ns string) (interface{}, error) {
|
||||||
|
@ -8,9 +8,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/DeBrosOfficial/network/pkg/client"
|
||||||
"git.debros.io/DeBros/network/pkg/client"
|
"github.com/DeBrosOfficial/network/pkg/logging"
|
||||||
"git.debros.io/DeBros/network/pkg/logging"
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,9 +9,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/client"
|
"github.com/DeBrosOfficial/network/pkg/client"
|
||||||
"git.debros.io/DeBros/network/pkg/logging"
|
"github.com/DeBrosOfficial/network/pkg/logging"
|
||||||
"git.debros.io/DeBros/network/pkg/storage"
|
"github.com/DeBrosOfficial/network/pkg/storage"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/client"
|
"github.com/DeBrosOfficial/network/pkg/client"
|
||||||
"git.debros.io/DeBros/network/pkg/logging"
|
"github.com/DeBrosOfficial/network/pkg/logging"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
package gateway
|
package gateway
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
|
||||||
"encoding/json"
|
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/client"
|
"github.com/DeBrosOfficial/network/pkg/client"
|
||||||
"git.debros.io/DeBros/network/pkg/storage"
|
"github.com/DeBrosOfficial/network/pkg/storage"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ func (g *Gateway) pubsubWebsocketHandler(w http.ResponseWriter, r *http.Request)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.Method != http.MethodGet {
|
if r.Method != http.MethodGet {
|
||||||
g.logger.ComponentWarn("gateway", "pubsub ws: method not allowed",)
|
g.logger.ComponentWarn("gateway", "pubsub ws: method not allowed")
|
||||||
writeError(w, http.StatusMethodNotAllowed, "method not allowed")
|
writeError(w, http.StatusMethodNotAllowed, "method not allowed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ func (g *Gateway) pubsubWebsocketHandler(w http.ResponseWriter, r *http.Request)
|
|||||||
}
|
}
|
||||||
conn, err := wsUpgrader.Upgrade(w, r, nil)
|
conn, err := wsUpgrader.Upgrade(w, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.logger.ComponentWarn("gateway", "pubsub ws: upgrade failed",)
|
g.logger.ComponentWarn("gateway", "pubsub ws: upgrade failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
@ -79,7 +79,7 @@ func (g *Gateway) pubsubWebsocketHandler(w http.ResponseWriter, r *http.Request)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := g.client.PubSub().Subscribe(ctx, topic, h); err != nil {
|
if err := g.client.PubSub().Subscribe(ctx, topic, h); err != nil {
|
||||||
g.logger.ComponentWarn("gateway", "pubsub ws: subscribe failed",)
|
g.logger.ComponentWarn("gateway", "pubsub ws: subscribe failed")
|
||||||
writeError(w, http.StatusInternalServerError, err.Error())
|
writeError(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/client"
|
"github.com/DeBrosOfficial/network/pkg/client"
|
||||||
"git.debros.io/DeBros/network/pkg/logging"
|
"github.com/DeBrosOfficial/network/pkg/logging"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -4,29 +4,32 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/client"
|
"github.com/DeBrosOfficial/network/pkg/client"
|
||||||
"git.debros.io/DeBros/network/pkg/pubsub"
|
"github.com/DeBrosOfficial/network/pkg/pubsub"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Database HTTP handlers
|
// Database HTTP handlers
|
||||||
func (g *Gateway) dbQueryHandler(w http.ResponseWriter, r *http.Request) {
|
func (g *Gateway) dbQueryHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if g.client == nil {
|
if g.client == nil {
|
||||||
writeError(w, http.StatusServiceUnavailable, "client not initialized");
|
writeError(w, http.StatusServiceUnavailable, "client not initialized")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
writeError(w, http.StatusMethodNotAllowed, "method not allowed");
|
writeError(w, http.StatusMethodNotAllowed, "method not allowed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var body struct{ SQL string `json:"sql"`; Args []any `json:"args"` }
|
var body struct {
|
||||||
|
SQL string `json:"sql"`
|
||||||
|
Args []any `json:"args"`
|
||||||
|
}
|
||||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil || body.SQL == "" {
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil || body.SQL == "" {
|
||||||
writeError(w, http.StatusBadRequest, "invalid body: {sql, args?}");
|
writeError(w, http.StatusBadRequest, "invalid body: {sql, args?}")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx := client.WithInternalAuth(r.Context())
|
ctx := client.WithInternalAuth(r.Context())
|
||||||
res, err := g.client.Database().Query(ctx, body.SQL, body.Args...)
|
res, err := g.client.Database().Query(ctx, body.SQL, body.Args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, err.Error());
|
writeError(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusOK, res)
|
writeJSON(w, http.StatusOK, res)
|
||||||
@ -34,39 +37,41 @@ func (g *Gateway) dbQueryHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func (g *Gateway) dbTransactionHandler(w http.ResponseWriter, r *http.Request) {
|
func (g *Gateway) dbTransactionHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if g.client == nil {
|
if g.client == nil {
|
||||||
writeError(w, http.StatusServiceUnavailable, "client not initialized");
|
writeError(w, http.StatusServiceUnavailable, "client not initialized")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
writeError(w, http.StatusMethodNotAllowed, "method not allowed");
|
writeError(w, http.StatusMethodNotAllowed, "method not allowed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var body struct{ Statements []string `json:"statements"` }
|
var body struct {
|
||||||
|
Statements []string `json:"statements"`
|
||||||
|
}
|
||||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil || len(body.Statements) == 0 {
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil || len(body.Statements) == 0 {
|
||||||
writeError(w, http.StatusBadRequest, "invalid body: {statements:[...]}");
|
writeError(w, http.StatusBadRequest, "invalid body: {statements:[...]}")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx := client.WithInternalAuth(r.Context())
|
ctx := client.WithInternalAuth(r.Context())
|
||||||
if err := g.client.Database().Transaction(ctx, body.Statements); err != nil {
|
if err := g.client.Database().Transaction(ctx, body.Statements); err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, err.Error());
|
writeError(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusOK, map[string]any{"status":"ok"})
|
writeJSON(w, http.StatusOK, map[string]any{"status": "ok"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Gateway) dbSchemaHandler(w http.ResponseWriter, r *http.Request) {
|
func (g *Gateway) dbSchemaHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if g.client == nil {
|
if g.client == nil {
|
||||||
writeError(w, http.StatusServiceUnavailable, "client not initialized");
|
writeError(w, http.StatusServiceUnavailable, "client not initialized")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.Method != http.MethodGet {
|
if r.Method != http.MethodGet {
|
||||||
writeError(w, http.StatusMethodNotAllowed, "method not allowed");
|
writeError(w, http.StatusMethodNotAllowed, "method not allowed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx := client.WithInternalAuth(r.Context())
|
ctx := client.WithInternalAuth(r.Context())
|
||||||
schema, err := g.client.Database().GetSchema(ctx)
|
schema, err := g.client.Database().GetSchema(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, err.Error());
|
writeError(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusOK, schema)
|
writeJSON(w, http.StatusOK, schema)
|
||||||
@ -74,46 +79,50 @@ func (g *Gateway) dbSchemaHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func (g *Gateway) dbCreateTableHandler(w http.ResponseWriter, r *http.Request) {
|
func (g *Gateway) dbCreateTableHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if g.client == nil {
|
if g.client == nil {
|
||||||
writeError(w, http.StatusServiceUnavailable, "client not initialized");
|
writeError(w, http.StatusServiceUnavailable, "client not initialized")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
writeError(w, http.StatusMethodNotAllowed, "method not allowed");
|
writeError(w, http.StatusMethodNotAllowed, "method not allowed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var body struct{ Schema string `json:"schema"` }
|
var body struct {
|
||||||
|
Schema string `json:"schema"`
|
||||||
|
}
|
||||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil || body.Schema == "" {
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil || body.Schema == "" {
|
||||||
writeError(w, http.StatusBadRequest, "invalid body: {schema}");
|
writeError(w, http.StatusBadRequest, "invalid body: {schema}")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx := client.WithInternalAuth(r.Context())
|
ctx := client.WithInternalAuth(r.Context())
|
||||||
if err := g.client.Database().CreateTable(ctx, body.Schema); err != nil {
|
if err := g.client.Database().CreateTable(ctx, body.Schema); err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, err.Error());
|
writeError(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusCreated, map[string]any{"status":"ok"})
|
writeJSON(w, http.StatusCreated, map[string]any{"status": "ok"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Gateway) dbDropTableHandler(w http.ResponseWriter, r *http.Request) {
|
func (g *Gateway) dbDropTableHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if g.client == nil {
|
if g.client == nil {
|
||||||
writeError(w, http.StatusServiceUnavailable, "client not initialized");
|
writeError(w, http.StatusServiceUnavailable, "client not initialized")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
writeError(w, http.StatusMethodNotAllowed, "method not allowed");
|
writeError(w, http.StatusMethodNotAllowed, "method not allowed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var body struct{ Table string `json:"table"` }
|
var body struct {
|
||||||
|
Table string `json:"table"`
|
||||||
|
}
|
||||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil || body.Table == "" {
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil || body.Table == "" {
|
||||||
writeError(w, http.StatusBadRequest, "invalid body: {table}");
|
writeError(w, http.StatusBadRequest, "invalid body: {table}")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx := client.WithInternalAuth(r.Context())
|
ctx := client.WithInternalAuth(r.Context())
|
||||||
if err := g.client.Database().DropTable(ctx, body.Table); err != nil {
|
if err := g.client.Database().DropTable(ctx, body.Table); err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, err.Error());
|
writeError(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusOK, map[string]any{"status":"ok"})
|
writeJSON(w, http.StatusOK, map[string]any{"status": "ok"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Gateway) networkStatusHandler(w http.ResponseWriter, r *http.Request) {
|
func (g *Gateway) networkStatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -22,11 +22,11 @@ import (
|
|||||||
"github.com/multiformats/go-multiaddr"
|
"github.com/multiformats/go-multiaddr"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/anyoneproxy"
|
"github.com/DeBrosOfficial/network/pkg/anyoneproxy"
|
||||||
"git.debros.io/DeBros/network/pkg/config"
|
"github.com/DeBrosOfficial/network/pkg/config"
|
||||||
"git.debros.io/DeBros/network/pkg/database"
|
"github.com/DeBrosOfficial/network/pkg/database"
|
||||||
"git.debros.io/DeBros/network/pkg/logging"
|
"github.com/DeBrosOfficial/network/pkg/logging"
|
||||||
"git.debros.io/DeBros/network/pkg/pubsub"
|
"github.com/DeBrosOfficial/network/pkg/pubsub"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Node represents a network node with RQLite database
|
// Node represents a network node with RQLite database
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.debros.io/DeBros/network/pkg/config"
|
"github.com/DeBrosOfficial/network/pkg/config"
|
||||||
"github.com/libp2p/go-libp2p"
|
"github.com/libp2p/go-libp2p"
|
||||||
"github.com/libp2p/go-libp2p/core/crypto"
|
"github.com/libp2p/go-libp2p/core/crypto"
|
||||||
"github.com/libp2p/go-libp2p/core/network"
|
"github.com/libp2p/go-libp2p/core/network"
|
||||||
|
@ -17,7 +17,7 @@ NOCOLOR='\033[0m'
|
|||||||
|
|
||||||
# Defaults
|
# Defaults
|
||||||
INSTALL_DIR="/opt/debros"
|
INSTALL_DIR="/opt/debros"
|
||||||
REPO_URL="https://git.debros.io/DeBros/network.git"
|
REPO_URL="https://github.com/DeBrosOfficial/network.git"
|
||||||
MIN_GO_VERSION="1.21"
|
MIN_GO_VERSION="1.21"
|
||||||
NODE_PORT="4001"
|
NODE_PORT="4001"
|
||||||
RQLITE_PORT="5001"
|
RQLITE_PORT="5001"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user