You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iggy.apache.org by "chengxilo (via GitHub)" <gi...@apache.org> on 2025/07/16 15:19:55 UTC

[PR] chore(sdk): add go getting-started example and test script [iggy]

chengxilo opened a new pull request, #2017:
URL: https://github.com/apache/iggy/pull/2017

   # Description
   
   1. add getting-started go example
   2. add script to test go example
   3. add lint for go example in CI


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@iggy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] chore(sdk): add go getting-started example and test script [iggy]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2017:
URL: https://github.com/apache/iggy/pull/2017#discussion_r2211282333


##########
examples/go/go.mod:
##########
@@ -0,0 +1,12 @@
+module github.com/apache/iggy/examples/go
+
+go 1.23.0

Review Comment:
   [nitpick] The `go` directive usually specifies major.minor (e.g., `go 1.23`) rather than including a patch version; consider changing to `go 1.23`.
   ```suggestion
   go 1.23
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@iggy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] chore(sdk): add go getting-started example and test script [iggy]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2017:
URL: https://github.com/apache/iggy/pull/2017#discussion_r2211034369


##########
scripts/run-go-examples-from-readme.sh:
##########
@@ -0,0 +1,172 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); 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
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -euo pipefail
+
+# Script to run Go examples from examples/go/README.md files
+# Usage: ./scripts/run-go-examples-from-readme.sh [OPTIONS]
+#
+# --goos   - Optional target OS (e.g., linux, darwin)
+# --goarch - Optional target architecture (e.g., amd64, arm64)
+# --target - Optional target architecture for rust (e.g., x86_64-unknown-linux-musl)
+# If not provided, uses the default target
+#
+# This script will run all the commands from examples/go/README.md files
+# and check if they pass or fail.
+# If any command fails, it will print the command and exit with non-zero status.
+# If all commands pass, it will remove the log file and exit with zero status.
+#
+# Note: This script assumes that the iggy-server is not running and will start it in the background.
+#       It will wait until the server is started before running the commands.
+#       It will also terminate the server after running all the commands.
+#       Script executes every command in examples/go/README.md files which is enclosed in backticks (`) and starts
+#       with `go run`. Other commands are ignored.
+#       Order of commands in README files is important as script will execute them from top to bottom.
+#
+
+readonly LOG_FILE="iggy-server.log"
+readonly PID_FILE="iggy-server.pid"
+readonly TIMEOUT=300
+
+GOOS="" # Go target OS
+GOARCH="" # Go target architecture
+TARGET="" # Iggy server target architecture
+
+# Get GOOS, GOARCH, and Cargo --target values from arguments or use defaults
+while [[ $# -gt 0 ]]; do
+    case "$1" in
+        --goos)
+            GOOS="$2"
+            shift 2
+            ;;
+        --goarch)
+            GOARCH="$2"
+            shift 2
+            ;;
+        --target)
+            TARGET="$2"
+            shift 2
+            ;;
+        *)
+            echo "Unknown option: $1"
+            echo "Usage: $0 [--goos GOOS] [--goarch GOARCH] [--target TARGET]"
+            exit 1
+            ;;
+    esac
+done
+
+if [ -n "${GOOS}" ]; then
+    echo "Using GOOS=${GOOS}"
+fi
+if [ -n "${GOARCH}" ]; then
+    echo "Using GOARCH=${GOARCH}"
+fi
+if [ -n "${TARGET}" ]; then
+    echo "Using cargo --target ${TARGET}"
+fi
+
+# Remove old server data if present
+test -d local_data && rm -fr local_data
+test -e ${LOG_FILE} && rm ${LOG_FILE}
+test -e ${PID_FILE} && rm ${PID_FILE}
+
+# Build binaries
+echo "Building binaries..."
+if [ -n "${TARGET}" ]; then
+    cargo build --target "${TARGET}"
+else
+    cargo build
+fi
+
+# Run iggy server and let it run in the background
+if [ -n "${TARGET}" ]; then
+    cargo run --target "${TARGET}" --bin iggy-server &>${LOG_FILE} &
+else
+    cargo run --bin iggy-server &>${LOG_FILE} &
+fi
+echo $! >${PID_FILE}
+
+# Wait until "Iggy server has started" string is present inside iggy-server.log
+SERVER_START_TIME=0
+while ! grep -q "Iggy server has started" ${LOG_FILE}; do
+    if [ ${SERVER_START_TIME} -gt ${TIMEOUT} ]; then
+        echo "Server did not start within ${TIMEOUT} seconds."
+        ps fx
+        cat ${LOG_FILE}
+        exit 1
+    fi
+    echo "Waiting for Iggy server to start... ${SERVER_START_TIME}"
+    sleep 1
+    ((SERVER_START_TIME += 1))
+done
+
+cd examples/go
+
+# Execute all example commands from examples/go/README.md and check if they pass or fail

Review Comment:
   Initialize `exit_code=0` before entering the loop to ensure it's always set before being checked at the end of the script.
   ```suggestion
   # Execute all example commands from examples/go/README.md and check if they pass or fail
   exit_code=0
   ```



##########
examples/go/getting-started/producer/main.go:
##########
@@ -0,0 +1,130 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); 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
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package main
+
+import (
+	"flag"
+	"fmt"
+	"github.com/apache/iggy/examples/go/common"
+	iggcon "github.com/apache/iggy/foreign/go/contracts"
+	"log"
+	"net"
+	"time"
+
+	"github.com/apache/iggy/foreign/go/iggycli"
+	"github.com/apache/iggy/foreign/go/tcp"
+)
+
+var (
+	StreamId     = uint32(1)
+	TopicId      = uint32(1)
+	PartitionId  = uint32(1)
+	BatchesLimit = uint32(5)
+)
+
+func main() {
+	client, _ := iggycli.NewIggyClient(
+		iggycli.WithTcp(
+			tcp.WithServerAddress(getTcpServerAddr()),
+		),
+	)

Review Comment:
   Avoid ignoring the error returned by `NewIggyClient`; handle it to prevent a nil or misconfigured client from being used.
   ```suggestion
   	client, err := iggycli.NewIggyClient(
   		iggycli.WithTcp(
   			tcp.WithServerAddress(getTcpServerAddr()),
   		),
   	)
   	if err != nil {
   		log.Fatalf("Failed to create Iggy client: %v", err)
   	}
   ```



##########
.github/changed-files-config.json:
##########
@@ -28,6 +28,7 @@
     "foreign/go/go.mod",
     "foreign/go/go.sum",
     "bdd/go/.*\\.go",
+    "examples/go/.*\\.go",

Review Comment:
   Consider adding patterns for `examples/go/go.mod` and `examples/go/go.sum` so changes to module files also trigger CI checks.
   ```suggestion
       "examples/go/.*\\.go",
       "examples/go/go.mod",
       "examples/go/go.sum",
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@iggy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] chore(sdk): add go getting-started example and test script [iggy]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2017:
URL: https://github.com/apache/iggy/pull/2017#discussion_r2211262241


##########
scripts/run-go-examples-from-readme.sh:
##########
@@ -0,0 +1,173 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); 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
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -euo pipefail
+
+# Script to run Go examples from examples/go/README.md files
+# Usage: ./scripts/run-go-examples-from-readme.sh [OPTIONS]
+#
+# --goos   - Optional target OS (e.g., linux, darwin)
+# --goarch - Optional target architecture (e.g., amd64, arm64)
+# --target - Optional target architecture for rust (e.g., x86_64-unknown-linux-musl)
+# If not provided, uses the default target
+#
+# This script will run all the commands from examples/go/README.md files
+# and check if they pass or fail.
+# If any command fails, it will print the command and exit with non-zero status.
+# If all commands pass, it will remove the log file and exit with zero status.
+#
+# Note: This script assumes that the iggy-server is not running and will start it in the background.
+#       It will wait until the server is started before running the commands.
+#       It will also terminate the server after running all the commands.
+#       Script executes every command in examples/go/README.md files which is enclosed in backticks (`) and starts
+#       with `go run`. Other commands are ignored.
+#       Order of commands in README files is important as script will execute them from top to bottom.
+#
+
+readonly LOG_FILE="iggy-server.log"
+readonly PID_FILE="iggy-server.pid"
+readonly TIMEOUT=300
+
+GOOS="" # Go target OS
+GOARCH="" # Go target architecture
+TARGET="" # Iggy server target architecture
+
+# Get GOOS, GOARCH, and Cargo --target values from arguments or use defaults
+while [[ $# -gt 0 ]]; do
+    case "$1" in
+        --goos)
+            GOOS="$2"
+            shift 2
+            ;;
+        --goarch)
+            GOARCH="$2"
+            shift 2
+            ;;
+        --target)
+            TARGET="$2"
+            shift 2
+            ;;
+        *)
+            echo "Unknown option: $1"
+            echo "Usage: $0 [--goos GOOS] [--goarch GOARCH] [--target TARGET]"
+            exit 1
+            ;;
+    esac
+done
+
+if [ -n "${GOOS}" ]; then
+    echo "Using GOOS=${GOOS}"
+fi
+if [ -n "${GOARCH}" ]; then
+    echo "Using GOARCH=${GOARCH}"
+fi
+if [ -n "${TARGET}" ]; then
+    echo "Using cargo --target ${TARGET}"
+fi
+
+# Remove old server data if present
+test -d local_data && rm -fr local_data
+test -e ${LOG_FILE} && rm ${LOG_FILE}
+test -e ${PID_FILE} && rm ${PID_FILE}
+
+# Build binaries
+echo "Building binaries..."
+if [ -n "${TARGET}" ]; then
+    cargo build --target "${TARGET}"
+else
+    cargo build
+fi
+
+# Run iggy server and let it run in the background
+if [ -n "${TARGET}" ]; then
+    cargo run --target "${TARGET}" --bin iggy-server &>${LOG_FILE} &
+else
+    cargo run --bin iggy-server &>${LOG_FILE} &
+fi
+echo $! >${PID_FILE}
+
+# Wait until "Iggy server has started" string is present inside iggy-server.log
+SERVER_START_TIME=0
+while ! grep -q "Iggy server has started" ${LOG_FILE}; do
+    if [ ${SERVER_START_TIME} -gt ${TIMEOUT} ]; then
+        echo "Server did not start within ${TIMEOUT} seconds."
+        ps fx
+        cat ${LOG_FILE}
+        exit 1
+    fi
+    echo "Waiting for Iggy server to start... ${SERVER_START_TIME}"
+    sleep 1
+    ((SERVER_START_TIME += 1))
+done
+
+cd examples/go
+
+# Execute all example commands from examples/go/README.md and check if they pass or fail
+exit_code=0
+if [ -f "README.md" ]; then
+    while IFS= read -r command; do
+        # Remove backticks and comments from command
+        command=$(echo "${command}" | tr -d '`' | sed 's/^#.*//')
+        # Skip empty lines
+        if [ -z "${command}" ]; then
+            continue
+        fi
+        # Add GOOS/GOARCH env if specified
+       [ -n "${GOOS}" ] && command="GOOS=${GOOS} ${command}"
+       [ -n "${GOARCH}" ] && command="GOARCH=${GOARCH} ${command}"

Review Comment:
   Inconsistent indentation using spaces instead of tabs. The line should use tabs to match the rest of the shell script indentation style.
   ```suggestion
   		[ -n "${GOARCH}" ] && command="GOARCH=${GOARCH} ${command}"
   ```



##########
scripts/run-go-examples-from-readme.sh:
##########
@@ -0,0 +1,173 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); 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
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -euo pipefail
+
+# Script to run Go examples from examples/go/README.md files
+# Usage: ./scripts/run-go-examples-from-readme.sh [OPTIONS]
+#
+# --goos   - Optional target OS (e.g., linux, darwin)
+# --goarch - Optional target architecture (e.g., amd64, arm64)
+# --target - Optional target architecture for rust (e.g., x86_64-unknown-linux-musl)
+# If not provided, uses the default target
+#
+# This script will run all the commands from examples/go/README.md files
+# and check if they pass or fail.
+# If any command fails, it will print the command and exit with non-zero status.
+# If all commands pass, it will remove the log file and exit with zero status.
+#
+# Note: This script assumes that the iggy-server is not running and will start it in the background.
+#       It will wait until the server is started before running the commands.
+#       It will also terminate the server after running all the commands.
+#       Script executes every command in examples/go/README.md files which is enclosed in backticks (`) and starts
+#       with `go run`. Other commands are ignored.
+#       Order of commands in README files is important as script will execute them from top to bottom.
+#
+
+readonly LOG_FILE="iggy-server.log"
+readonly PID_FILE="iggy-server.pid"
+readonly TIMEOUT=300
+
+GOOS="" # Go target OS
+GOARCH="" # Go target architecture
+TARGET="" # Iggy server target architecture
+
+# Get GOOS, GOARCH, and Cargo --target values from arguments or use defaults
+while [[ $# -gt 0 ]]; do
+    case "$1" in
+        --goos)
+            GOOS="$2"
+            shift 2
+            ;;
+        --goarch)
+            GOARCH="$2"
+            shift 2
+            ;;
+        --target)
+            TARGET="$2"
+            shift 2
+            ;;
+        *)
+            echo "Unknown option: $1"
+            echo "Usage: $0 [--goos GOOS] [--goarch GOARCH] [--target TARGET]"
+            exit 1
+            ;;
+    esac
+done
+
+if [ -n "${GOOS}" ]; then
+    echo "Using GOOS=${GOOS}"
+fi
+if [ -n "${GOARCH}" ]; then
+    echo "Using GOARCH=${GOARCH}"
+fi
+if [ -n "${TARGET}" ]; then
+    echo "Using cargo --target ${TARGET}"
+fi
+
+# Remove old server data if present
+test -d local_data && rm -fr local_data
+test -e ${LOG_FILE} && rm ${LOG_FILE}
+test -e ${PID_FILE} && rm ${PID_FILE}
+
+# Build binaries
+echo "Building binaries..."
+if [ -n "${TARGET}" ]; then
+    cargo build --target "${TARGET}"
+else
+    cargo build
+fi
+
+# Run iggy server and let it run in the background
+if [ -n "${TARGET}" ]; then
+    cargo run --target "${TARGET}" --bin iggy-server &>${LOG_FILE} &
+else
+    cargo run --bin iggy-server &>${LOG_FILE} &
+fi
+echo $! >${PID_FILE}
+
+# Wait until "Iggy server has started" string is present inside iggy-server.log
+SERVER_START_TIME=0
+while ! grep -q "Iggy server has started" ${LOG_FILE}; do
+    if [ ${SERVER_START_TIME} -gt ${TIMEOUT} ]; then
+        echo "Server did not start within ${TIMEOUT} seconds."
+        ps fx
+        cat ${LOG_FILE}
+        exit 1
+    fi
+    echo "Waiting for Iggy server to start... ${SERVER_START_TIME}"
+    sleep 1
+    ((SERVER_START_TIME += 1))
+done
+
+cd examples/go
+
+# Execute all example commands from examples/go/README.md and check if they pass or fail
+exit_code=0
+if [ -f "README.md" ]; then
+    while IFS= read -r command; do
+        # Remove backticks and comments from command
+        command=$(echo "${command}" | tr -d '`' | sed 's/^#.*//')
+        # Skip empty lines
+        if [ -z "${command}" ]; then
+            continue
+        fi
+        # Add GOOS/GOARCH env if specified
+       [ -n "${GOOS}" ] && command="GOOS=${GOOS} ${command}"

Review Comment:
   Inconsistent indentation using spaces instead of tabs. The line should use tabs to match the rest of the shell script indentation style.
   ```suggestion
   	[ -n "${GOOS}" ] && command="GOOS=${GOOS} ${command}"
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@iggy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] chore(go): add go getting-started example and test script [iggy]

Posted by "spetz (via GitHub)" <gi...@apache.org>.
spetz merged PR #2017:
URL: https://github.com/apache/iggy/pull/2017


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@iggy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org