feat: mock gateway
This commit is contained in:
103
scripts/run-mock-gateway.sh
Normal file
103
scripts/run-mock-gateway.sh
Normal file
@@ -0,0 +1,103 @@
|
||||
#!/bin/bash
|
||||
|
||||
# SPORE Mock Gateway Runner
|
||||
# Builds and runs the mock gateway with common configurations
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Default values
|
||||
PORT="${PORT:-3001}"
|
||||
MOCK_NODES="${MOCK_NODES:-5}"
|
||||
HEARTBEAT_RATE="${HEARTBEAT_RATE:-5}"
|
||||
LOG_LEVEL="${LOG_LEVEL:-info}"
|
||||
ENABLE_WS="${ENABLE_WS:-true}"
|
||||
|
||||
# Parse command line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-p|--port)
|
||||
PORT="$2"
|
||||
shift 2
|
||||
;;
|
||||
-n|--nodes)
|
||||
MOCK_NODES="$2"
|
||||
shift 2
|
||||
;;
|
||||
-h|--heartbeat)
|
||||
HEARTBEAT_RATE="$2"
|
||||
shift 2
|
||||
;;
|
||||
-l|--log-level)
|
||||
LOG_LEVEL="$2"
|
||||
shift 2
|
||||
;;
|
||||
--no-ws)
|
||||
ENABLE_WS="false"
|
||||
shift
|
||||
;;
|
||||
--help)
|
||||
echo "SPORE Mock Gateway Runner"
|
||||
echo ""
|
||||
echo "Usage: $0 [options]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -p, --port PORT HTTP server port (default: 3001)"
|
||||
echo " -n, --nodes NUM Number of mock nodes (default: 5)"
|
||||
echo " -h, --heartbeat SECONDS Heartbeat interval (default: 5)"
|
||||
echo " -l, --log-level LEVEL Log level: debug, info, warn, error (default: info)"
|
||||
echo " --no-ws Disable WebSocket support"
|
||||
echo " --help Show this help message"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 -p 8080 -n 10 # Run on port 8080 with 10 nodes"
|
||||
echo " $0 -l debug -h 2 # Debug logging with 2s heartbeats"
|
||||
echo " $0 --no-ws # Run without WebSocket"
|
||||
echo ""
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
echo "Use --help for usage information"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo -e "${BLUE}================================================${NC}"
|
||||
echo -e "${BLUE} SPORE Mock Gateway${NC}"
|
||||
echo -e "${BLUE}================================================${NC}"
|
||||
echo ""
|
||||
echo -e "${GREEN}Configuration:${NC}"
|
||||
echo -e " Port: ${YELLOW}$PORT${NC}"
|
||||
echo -e " Mock Nodes: ${YELLOW}$MOCK_NODES${NC}"
|
||||
echo -e " Heartbeat Rate: ${YELLOW}${HEARTBEAT_RATE}s${NC}"
|
||||
echo -e " Log Level: ${YELLOW}$LOG_LEVEL${NC}"
|
||||
echo -e " WebSocket: ${YELLOW}$ENABLE_WS${NC}"
|
||||
echo ""
|
||||
|
||||
# Check if Go is installed
|
||||
if ! command -v go &> /dev/null; then
|
||||
echo -e "${YELLOW}Error: Go is not installed${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Build the mock gateway
|
||||
echo -e "${GREEN}Building mock gateway...${NC}"
|
||||
go build -o mock-gateway cmd/mock-gateway/main.go
|
||||
|
||||
echo -e "${GREEN}Starting mock gateway...${NC}"
|
||||
echo ""
|
||||
|
||||
# Run the mock gateway
|
||||
./mock-gateway \
|
||||
-port "$PORT" \
|
||||
-mock-nodes "$MOCK_NODES" \
|
||||
-heartbeat-rate "$HEARTBEAT_RATE" \
|
||||
-log-level "$LOG_LEVEL" \
|
||||
-enable-ws="$ENABLE_WS"
|
||||
Reference in New Issue
Block a user