adding more builds and they all can be piped to now.
This commit is contained in:
parent
1002905f56
commit
113efccc02
28
build.sh
28
build.sh
|
@ -1,3 +1,29 @@
|
||||||
#!/bin/bash
|
#!/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
|
||||||
|
|
146
go-glitch.go
146
go-glitch.go
|
@ -1,78 +1,94 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"io"
|
||||||
"strings"
|
"os"
|
||||||
"time"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Check that exactly one argument is passed (file path)
|
var reader io.Reader
|
||||||
if len(os.Args) != 2 {
|
var filePath string
|
||||||
fmt.Fprintf(os.Stderr, "Usage: %s <path to log file>\n", os.Args[0])
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
filePath := os.Args[1]
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
// Open the file
|
// Read content from the chosen input
|
||||||
file, err := os.Open(filePath)
|
scanner := bufio.NewScanner(reader)
|
||||||
if err != nil {
|
var content strings.Builder
|
||||||
fmt.Fprintf(os.Stderr, "Error opening file: %s\n", err)
|
for scanner.Scan() {
|
||||||
os.Exit(1)
|
content.WriteString(scanner.Text())
|
||||||
}
|
content.WriteString("\n") // Preserve line breaks
|
||||||
defer file.Close()
|
}
|
||||||
|
|
||||||
// Read file contents into a string
|
if err := scanner.Err(); err != nil {
|
||||||
scanner := bufio.NewScanner(file)
|
fmt.Fprintf(os.Stderr, "Error reading input: %s\n", err)
|
||||||
var content strings.Builder
|
os.Exit(1)
|
||||||
for scanner.Scan() {
|
}
|
||||||
content.WriteString(scanner.Text())
|
|
||||||
content.WriteString("\n") // Preserve line breaks
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := scanner.Err(); err != nil {
|
logMessage := content.String()
|
||||||
fmt.Fprintf(os.Stderr, "Error reading file: %s\n", err)
|
sendToSentry(logMessage)
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
logMessage := content.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{
|
|
||||||
Dsn: dsn,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "Error initializing Sentry: %s\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Defer a function to flush Sentry's buffer
|
|
||||||
defer func() {
|
|
||||||
success := sentry.Flush(5 * time.Second)
|
|
||||||
if !success {
|
|
||||||
fmt.Fprintf(os.Stderr, "Failed to flush Sentry buffer within the expected time.\n")
|
|
||||||
} else {
|
|
||||||
fmt.Println("Sentry buffer flushed successfully.")
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(os.Stderr, "Failed to send message to Sentry.\n")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := sentry.Init(sentry.ClientOptions{
|
||||||
|
Dsn: dsn,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error initializing Sentry: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
success := sentry.Flush(5 * time.Second)
|
||||||
|
if !success {
|
||||||
|
fmt.Fprintf(os.Stderr, "Failed to flush Sentry buffer within the expected time.\n")
|
||||||
|
} else {
|
||||||
|
fmt.Println("Sentry buffer flushed successfully.")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
eventID := sentry.CaptureMessage(logMessage)
|
||||||
|
if eventID != nil {
|
||||||
|
fmt.Printf("Sent message to Sentry with event ID: %s\n", *eventID)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(os.Stderr, "Failed to send message to Sentry.\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue