Search/run.sh
partisan c8a5ae02c0
Some checks failed
Run Integration Tests / test (push) Failing after 12s
added tests
2024-12-05 00:24:47 +01:00

62 lines
1.2 KiB
Bash
Executable file

#!/bin/sh
# Initialize variables
SKIP_CONFIG=""
PORT=""
DOMAIN=""
BUILD_MODE=false
BUILD_OUTPUT="qgato"
# Parse arguments
while [ $# -gt 0 ]; do
case $1 in
--port)
PORT=$2
shift 2
;;
--domain)
DOMAIN=$2
shift 2
;;
--skip-config-check)
SKIP_CONFIG="--skip-config-check"
shift
;;
--build)
BUILD_MODE=true
shift
;;
*)
echo "Unknown argument: $1"
exit 1
;;
esac
done
# Get the directory of the script
SCRIPT_DIR=$(dirname "$0")
# List all Go files in the script directory (excluding test files)
GO_FILES=$(find "$SCRIPT_DIR" -name '*.go' ! -name '*_test.go' -print)
if $BUILD_MODE; then
# Build mode
echo "Building application..."
go build -o "$SCRIPT_DIR/$BUILD_OUTPUT" $GO_FILES
if [ $? -eq 0 ]; then
echo "Build successful! Output: $SCRIPT_DIR/$BUILD_OUTPUT"
else
echo "Build failed!"
exit 1
fi
else
# Run mode
CMD="go run $GO_FILES $SKIP_CONFIG"
[ -n "$PORT" ] && CMD="$CMD --port $PORT"
[ -n "$DOMAIN" ] && CMD="$CMD --domain $DOMAIN"
echo "Starting application with command: $CMD"
# Run the Go program with the constructed command
eval $CMD
fi