1
1
Fork 0

adding more builds and they all can be piped to now.

This commit is contained in:
Colin 2024-04-16 20:09:16 -04:00
parent 1002905f56
commit 113efccc02
6 changed files with 108 additions and 66 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -1,3 +1,29 @@
#!/bin/bash
GOOS=linux GOARCH=amd64 go build
# Default architecture
DEFAULT_ARCH="linux/amd64"
# Supported architectures (adjust as needed)
ARCHITECTURES=("linux/amd64" "linux/arm64" "linux/arm/v7")
# Build function
build_binary() {
os=$1
arch=$2
output_name="go-glitch"
if [[ "$os/$arch" != "$DEFAULT_ARCH" ]]; then
output_name="${output_name}_${os}_${arch}"
fi
echo "Building for ${os}/${arch} -> ${output_name}"
GOOS=${os} GOARCH=${arch} go build -o ${output_name}
}
# Main Build Process
for arch in "${ARCHITECTURES[@]}"; do
IFS='/' read -r -a parts <<< "$arch" # Split architecture string
os=${parts[0]}
arch=${parts[1]}
build_binary $os $arch
done

BIN
go-glitch

Binary file not shown.

View File

@ -3,6 +3,7 @@ package main
import (
"bufio"
"fmt"
"io"
"os"
"strings"
"time"
@ -11,24 +12,30 @@ import (
)
func main() {
// Check that exactly one argument is passed (file path)
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "Usage: %s <path to log file>\n", os.Args[0])
os.Exit(1)
}
var reader io.Reader
var filePath string
filePath := os.Args[1]
// Open the file
// Determine the source of input
if len(os.Args) == 2 {
// Read from the file specified in the argument
filePath = os.Args[1]
file, err := os.Open(filePath)
if err != nil {
fmt.Fprintf(os.Stderr, "Error opening file: %s\n", err)
os.Exit(1)
}
defer file.Close()
reader = file
} else if len(os.Args) == 1 && !isInputFromPipe() {
fmt.Fprintf(os.Stderr, "Usage: %s <path to log file> OR pipe input\n", os.Args[0])
os.Exit(1)
} else {
// Read from stdin if data is being piped
reader = os.Stdin
}
// Read file contents into a string
scanner := bufio.NewScanner(file)
// Read content from the chosen input
scanner := bufio.NewScanner(reader)
var content strings.Builder
for scanner.Scan() {
content.WriteString(scanner.Text())
@ -36,20 +43,32 @@ func main() {
}
if err := scanner.Err(); err != nil {
fmt.Fprintf(os.Stderr, "Error reading file: %s\n", err)
fmt.Fprintf(os.Stderr, "Error reading input: %s\n", err)
os.Exit(1)
}
logMessage := content.String()
sendToSentry(logMessage)
}
// Helper function to check if there is data being piped to stdin
func isInputFromPipe() bool {
fileInfo, err := os.Stdin.Stat()
if err != nil {
return false
}
return fileInfo.Mode()&os.ModeCharDevice == 0
}
// Function to handle sending data to Sentry
func sendToSentry(logMessage string) {
dsn := os.Getenv("SENTRY_DSN")
if dsn == "" {
fmt.Fprintf(os.Stderr, "Error: SENTRY_DSN environment variable is not set.\n")
os.Exit(1)
}
// Initialize Sentry with the DSN
err = sentry.Init(sentry.ClientOptions{
err := sentry.Init(sentry.ClientOptions{
Dsn: dsn,
})
if err != nil {
@ -57,7 +76,6 @@ func main() {
os.Exit(1)
}
// Defer a function to flush Sentry's buffer
defer func() {
success := sentry.Flush(5 * time.Second)
if !success {
@ -67,7 +85,6 @@ func main() {
}
}()
// Capture the message and output the event ID
eventID := sentry.CaptureMessage(logMessage)
if eventID != nil {
fmt.Printf("Sent message to Sentry with event ID: %s\n", *eventID)
@ -75,4 +92,3 @@ func main() {
fmt.Fprintf(os.Stderr, "Failed to send message to Sentry.\n")
}
}

BIN
go-glitch_linux_arm Executable file

Binary file not shown.

BIN
go-glitch_linux_arm64 Executable file

Binary file not shown.