Skip to content

Agent Mesh

make gofmt

Antonio Ojea8ed68abddb94
diff --git a/Makefile b/Makefile
index 6f5639af..24a172c9 100644
--- a/Makefile
+++ b/Makefile
@@ -52,8 +52,13 @@ test-e2e-container: build docker-build
@command -v bats >/dev/null 2>&1 || { echo "bats not found"; exit 1; }
bats --verbose-run tests/e2e/container_mesh.bats
+# code formatters
+.PHONY: fmt
+fmt:
+ go fmt ./...
+
# code linters
-lint:
+lint: fmt
hack/lint.sh
.PHONY: verify
diff --git a/cmd/sam-hub/admin.go b/cmd/sam-hub/admin.go
index 87d6de36..5d149526 100644
--- a/cmd/sam-hub/admin.go
+++ b/cmd/sam-hub/admin.go
@@ -37,7 +37,7 @@ func handleBan(admin HubAdmin) http.HandlerFunc {
}
peerID := r.URL.Query().Get("peer")
logger.Infof("[Admin API] Received ban request for peer: %s", peerID)
-
+
if peerID == "" {
http.Error(w, "Missing peer parameter", http.StatusBadRequest)
return
diff --git a/cmd/sam-hub/keyring.go b/cmd/sam-hub/keyring.go
index c6a4a3b6..13bc19f0 100644
--- a/cmd/sam-hub/keyring.go
+++ b/cmd/sam-hub/keyring.go
@@ -71,7 +71,7 @@ func NewKeyRing(dbPath string, gracePeriod time.Duration, initialSeed []byte) (*
}
priv := ed25519.NewKeyFromSeed(initialSeed)
pub := priv.Public().(ed25519.PublicKey)
-
+
if !bytes.Equal(kr.Current.Private, priv) {
if len(kr.Current.Private) > 0 {
kr.Current.Expiration = time.Now().Add(gracePeriod)
diff --git a/cmd/sam-hub/main.go b/cmd/sam-hub/main.go
index 9c942141..399dcdac 100644
--- a/cmd/sam-hub/main.go
+++ b/cmd/sam-hub/main.go
@@ -660,8 +660,6 @@ func main() {
handleBan(h)(w, r)
})
-
-
server := &http.Server{
Addr: bindAddress,
Handler: mux,
diff --git a/cmd/sam-hub/metrics.go b/cmd/sam-hub/metrics.go
index 4b195adb..7859f57b 100644
--- a/cmd/sam-hub/metrics.go
+++ b/cmd/sam-hub/metrics.go
@@ -6,7 +6,6 @@ import (
)
var (
-
samHubEnrollmentTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "sam_hub_enrollment_total",
Help: "Total enrollment requests, partitioned by status.",
diff --git a/cmd/sam-node/bridge_transport_test.go b/cmd/sam-node/bridge_transport_test.go
index 2e7c53b3..26abbf7d 100644
--- a/cmd/sam-node/bridge_transport_test.go
+++ b/cmd/sam-node/bridge_transport_test.go
@@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
package main
import (
diff --git a/cmd/sam-node/main_test.go b/cmd/sam-node/main_test.go
index dfbbd48a..ef4e9c2a 100644
--- a/cmd/sam-node/main_test.go
+++ b/cmd/sam-node/main_test.go
@@ -48,5 +48,3 @@ func TestGetOrGenerateKey(t *testing.T) {
t.Error("Expected retrieved key to match generated key")
}
}
-
-
diff --git a/cmd/sam-node/mcp_service.go b/cmd/sam-node/mcp_service.go
index 32d68110..61d9c02d 100644
--- a/cmd/sam-node/mcp_service.go
+++ b/cmd/sam-node/mcp_service.go
@@ -67,7 +67,7 @@ func (m *MCPService) Init(ctx context.Context) error {
}
client := mcp.NewClient(&mcp.Implementation{Name: "sam-node-aggregator", Version: "0.1.0"}, nil)
-
+
var s *mcp.ClientSession
var err error
diff --git a/cmd/sam-node/mcp_service_test.go b/cmd/sam-node/mcp_service_test.go
index f342d8de..3b50eafc 100644
--- a/cmd/sam-node/mcp_service_test.go
+++ b/cmd/sam-node/mcp_service_test.go
@@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/cmd/sam-node/middleware_test.go b/cmd/sam-node/middleware_test.go
index 32f94a66..78b280c0 100644
--- a/cmd/sam-node/middleware_test.go
+++ b/cmd/sam-node/middleware_test.go
@@ -29,8 +29,8 @@ import (
"github.com/biscuit-auth/biscuit-go/v2/parser"
"github.com/google/sam/api"
lru "github.com/hashicorp/golang-lru/v2"
- "github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/crypto"
+ "github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/libp2p/go-msgio"
@@ -42,21 +42,21 @@ type mockConn struct {
remotePeer peer.ID
}
-func (c *mockConn) RemotePeer() peer.ID { return c.remotePeer }
-func (c *mockConn) LocalPeer() peer.ID { return "" }
-func (c *mockConn) LocalMultiaddr() multiaddr.Multiaddr { return nil }
-func (c *mockConn) RemoteMultiaddr() multiaddr.Multiaddr { return nil }
-func (c *mockConn) Stat() network.ConnStats { return network.ConnStats{} }
-func (c *mockConn) Scope() network.ConnScope { return nil }
-func (c *mockConn) Close() error { return nil }
-func (c *mockConn) CloseWithError(network.ConnErrorCode) error { return nil }
-func (c *mockConn) ConnState() network.ConnectionState { return network.ConnectionState{} }
-func (c *mockConn) GetStreams() []network.Stream { return nil }
-func (c *mockConn) ID() string { return "" }
-func (c *mockConn) IsClosed() bool { return false }
+func (c *mockConn) RemotePeer() peer.ID { return c.remotePeer }
+func (c *mockConn) LocalPeer() peer.ID { return "" }
+func (c *mockConn) LocalMultiaddr() multiaddr.Multiaddr { return nil }
+func (c *mockConn) RemoteMultiaddr() multiaddr.Multiaddr { return nil }
+func (c *mockConn) Stat() network.ConnStats { return network.ConnStats{} }
+func (c *mockConn) Scope() network.ConnScope { return nil }
+func (c *mockConn) Close() error { return nil }
+func (c *mockConn) CloseWithError(network.ConnErrorCode) error { return nil }
+func (c *mockConn) ConnState() network.ConnectionState { return network.ConnectionState{} }
+func (c *mockConn) GetStreams() []network.Stream { return nil }
+func (c *mockConn) ID() string { return "" }
+func (c *mockConn) IsClosed() bool { return false }
func (c *mockConn) NewStream(context.Context) (network.Stream, error) { return nil, nil }
-func (c *mockConn) RemotePublicKey() crypto.PubKey { return nil }
-func (c *mockConn) As(interface{}) bool { return false }
+func (c *mockConn) RemotePublicKey() crypto.PubKey { return nil }
+func (c *mockConn) As(interface{}) bool { return false }
type mockStream struct {
r io.Reader
@@ -65,22 +65,22 @@ type mockStream struct {
conn network.Conn
}
-func (s *mockStream) Read(p []byte) (n int, err error) { return s.r.Read(p) }
-func (s *mockStream) Write(p []byte) (n int, err error) { return s.w.Write(p) }
-func (s *mockStream) Close() error { return nil }
-func (s *mockStream) Protocol() protocol.ID { return s.protocol }
-func (s *mockStream) ID() string { return "" }
-func (s *mockStream) SetProtocol(protocol.ID) error { return nil }
-func (s *mockStream) CloseRead() error { return nil }
-func (s *mockStream) CloseWrite() error { return nil }
-func (s *mockStream) Reset() error { return nil }
+func (s *mockStream) Read(p []byte) (n int, err error) { return s.r.Read(p) }
+func (s *mockStream) Write(p []byte) (n int, err error) { return s.w.Write(p) }
+func (s *mockStream) Close() error { return nil }
+func (s *mockStream) Protocol() protocol.ID { return s.protocol }
+func (s *mockStream) ID() string { return "" }
+func (s *mockStream) SetProtocol(protocol.ID) error { return nil }
+func (s *mockStream) CloseRead() error { return nil }
+func (s *mockStream) CloseWrite() error { return nil }
+func (s *mockStream) Reset() error { return nil }
func (s *mockStream) ResetWithError(network.StreamErrorCode) error { return nil }
-func (s *mockStream) SetDeadline(time.Time) error { return nil }
-func (s *mockStream) SetReadDeadline(time.Time) error { return nil }
-func (s *mockStream) SetWriteDeadline(time.Time) error { return nil }
-func (s *mockStream) Stat() network.Stats { return network.Stats{} }
-func (s *mockStream) Conn() network.Conn { return s.conn }
-func (s *mockStream) Scope() network.StreamScope { return nil }
+func (s *mockStream) SetDeadline(time.Time) error { return nil }
+func (s *mockStream) SetReadDeadline(time.Time) error { return nil }
+func (s *mockStream) SetWriteDeadline(time.Time) error { return nil }
+func (s *mockStream) Stat() network.Stats { return network.Stats{} }
+func (s *mockStream) Conn() network.Conn { return s.conn }
+func (s *mockStream) Scope() network.StreamScope { return nil }
func TestAuthorize(t *testing.T) {
dir, err := os.MkdirTemp("", "middleware-test")
diff --git a/cmd/sam-node/rate_limiter_test.go b/cmd/sam-node/rate_limiter_test.go
index c852016a..233809a2 100644
--- a/cmd/sam-node/rate_limiter_test.go
+++ b/cmd/sam-node/rate_limiter_test.go
@@ -48,7 +48,7 @@ func TestPeerRateLimiter(t *testing.T) {
}
}
t.Logf("Allowed %d more requests after burst loop", count)
-
+
if count > 0 {
t.Errorf("Expected requests exceeding burst to be rejected, but allowed %d more", count)
}
@@ -66,7 +66,7 @@ func TestPeerRateLimiter(t *testing.T) {
// Cache should have evicted peer1 or peer2 (LRU).
// Since we used peer1 and then peer2, peer1 is the oldest!
// So peer1 should be evicted!
-
+
// Let's verify peer1 was evicted by checking if it gets a new limiter (allowed again!)
if !prl.Allow(peer1) {
t.Error("Expected evicted peer1 to be allowed again with new limiter")
diff --git a/cmd/sam-node/service_registry_test.go b/cmd/sam-node/service_registry_test.go
index a6462553..13ffbaca 100644
--- a/cmd/sam-node/service_registry_test.go
+++ b/cmd/sam-node/service_registry_test.go
@@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/cmd/sam-node/sidecar.go b/cmd/sam-node/sidecar.go
index 2cc06c4c..3be941b7 100644
--- a/cmd/sam-node/sidecar.go
+++ b/cmd/sam-node/sidecar.go
@@ -29,8 +29,8 @@ import (
"time"
"github.com/google/sam/api"
- "google.golang.org/protobuf/encoding/protojson"
libp2phttp "github.com/libp2p/go-libp2p-http"
+ "google.golang.org/protobuf/encoding/protojson"
)
func startSidecarServer(node *SamNode, addr, token, certFile, keyFile, caFile string) error {
diff --git a/cmd/sam-node/stdio_bridge_test.go b/cmd/sam-node/stdio_bridge_test.go
index 6e125e01..5fca8289 100644
--- a/cmd/sam-node/stdio_bridge_test.go
+++ b/cmd/sam-node/stdio_bridge_test.go
@@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
package main
import (
diff --git a/cmd/sam-node/store_test.go b/cmd/sam-node/store_test.go
index cccccecc..ba3da2b5 100644
--- a/cmd/sam-node/store_test.go
+++ b/cmd/sam-node/store_test.go
@@ -13,7 +13,3 @@
// limitations under the License.
package main
-
-
-
-
diff --git a/tests/integration/fallback_test.go b/tests/integration/fallback_test.go
index 39b8bf85..42692562 100644
--- a/tests/integration/fallback_test.go
+++ b/tests/integration/fallback_test.go
@@ -17,8 +17,8 @@ package integration_test
import (
"bytes"
"context"
- "encoding/json"
"crypto/ed25519"
+ "encoding/json"
"fmt"
"os"
"os/exec"
@@ -28,21 +28,21 @@ import (
"testing"
"time"
- "io"
- "net/http"
- "net/http/httptest"
"github.com/biscuit-auth/biscuit-go/v2"
"github.com/biscuit-auth/biscuit-go/v2/parser"
"github.com/google/sam/api"
"github.com/libp2p/go-libp2p"
dht "github.com/libp2p/go-libp2p-kad-dht"
"github.com/libp2p/go-libp2p/core/crypto"
- "github.com/libp2p/go-libp2p/core/peer"
- "github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/host"
+ "github.com/libp2p/go-libp2p/core/network"
+ "github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-msgio"
"github.com/multiformats/go-multiaddr"
"google.golang.org/protobuf/proto"
+ "io"
+ "net/http"
+ "net/http/httptest"
)
// init forces the biscuit-go parser to build its underlying participle
@@ -390,8 +390,8 @@ func TestSelfHealingHTTPFallback(t *testing.T) {
mux.HandleFunc("/.well-known/openid-configuration", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]interface{}{
- "issuer": "http://" + r.Host,
- "token_endpoint": "http://" + r.Host + "/token",
+ "issuer": "http://" + r.Host,
+ "token_endpoint": "http://" + r.Host + "/token",
"authorization_endpoint": "http://" + r.Host + "/auth",
})
})
@@ -497,8 +497,8 @@ func TestSelfHealingHTTPFallback(t *testing.T) {
success := false
for i := 0; i < 50; i++ {
out = stdout.String()
- if strings.Contains(out, "Attempting to fetch updated hub addresses via HTTP") &&
- strings.Contains(out, "Fallback connection successful!") {
+ if strings.Contains(out, "Attempting to fetch updated hub addresses via HTTP") &&
+ strings.Contains(out, "Fallback connection successful!") {
success = true
break
}
diff --git a/tests/integration/login_test.go b/tests/integration/login_test.go
index 1a6ba395..acbd808d 100644
--- a/tests/integration/login_test.go
+++ b/tests/integration/login_test.go
@@ -39,8 +39,8 @@ func TestSamNodeJoin(t *testing.T) {
mux.HandleFunc("/.well-known/openid-configuration", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(map[string]interface{}{
- "issuer": "http://" + r.Host,
- "token_endpoint": "http://" + r.Host + "/token",
+ "issuer": "http://" + r.Host,
+ "token_endpoint": "http://" + r.Host + "/token",
"authorization_endpoint": "http://" + r.Host + "/auth",
}); err != nil {
t.Errorf("Failed to encode response: %v", err)
diff --git a/tests/integration/pubsub_test.go b/tests/integration/pubsub_test.go
index d1f4bfe8..2086a638 100644
--- a/tests/integration/pubsub_test.go
+++ b/tests/integration/pubsub_test.go
@@ -168,7 +168,7 @@ func TestPubSubTools(t *testing.T) {
addr2 := waitForPeerInfoInLog(t, filepath.Join(tmpHome2, "node2.log"))
t.Logf("Node 2 address: %s", addr2)
callTool(mcpAddr1, "connect_peer", map[string]any{"peer_addr": addr2})
-
+
// Node 1 broadcasts on topic "test-topic"
broadcastResult := callTool(mcpAddr1, "mesh_pubsub_broadcast", map[string]any{
"topic": "test-topic",