Compare commits

..

2 Commits

2 changed files with 8 additions and 27 deletions

View File

@@ -30,7 +30,14 @@ build:
@# @echo "CGO_CFLAGS is: '$(CGO_CFLAGS)'"
@# @echo "CGO_LDFLAGS is: '$(CGO_LDFLAGS)'"
@# CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)"
go build -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/$(APP_NAME) ./
@go build -trimpath -ldflags "-w -s $(LDFLAGS)" -o $(BIN_DIR)/$(APP_NAME) ./
@if ! command -v upx >/dev/null 2>&1; then \
echo "upx not found, skipping compression."; \
elif upx -t $(BIN_DIR)/$(APP_NAME) >/dev/null 2>&1; then \
echo "$(BIN_DIR)/$(APP_NAME) already compressed, skipping."; \
else \
upx $(BIN_DIR)/$(APP_NAME) >/dev/null 2>&1 || true; \
fi
run: build
@echo "Running!"

View File

@@ -3,38 +3,14 @@ package utils
import (
"log"
"runtime"
"strings"
"golang.org/x/net/context"
)
// temportary solution, pls dont judge
func trimStackPaths(stack []byte, folderName string) []byte {
lines := strings.Split(string(stack), "\n")
for i, line := range lines {
idx := strings.Index(line, folderName)
if idx != -1 {
indentEnd := strings.LastIndex(line[:idx], "\t")
if indentEnd == -1 {
indentEnd = 0
} else {
indentEnd++
}
start := idx + len(folderName) + 1
if start > len(line) {
start = len(line)
}
lines[i] = line[:indentEnd] + line[start:]
}
}
return []byte(strings.Join(lines, "\n"))
}
func CatchPanic() {
if err := recover(); err != nil {
stack := make([]byte, 8096)
stack = stack[:runtime.Stack(stack, false)]
stack = trimStackPaths(stack, "GoSally-mvp")
log.Printf("recovered panic:\n%s", stack)
}
}
@@ -43,7 +19,6 @@ func CatchPanicWithCancel(cancel context.CancelFunc) {
if err := recover(); err != nil {
stack := make([]byte, 8096)
stack = stack[:runtime.Stack(stack, false)]
stack = trimStackPaths(stack, "GoSally-mvp")
log.Printf("recovered panic:\n%s", stack)
cancel()
}
@@ -53,7 +28,6 @@ func CatchPanicWithFallback(onPanic func(any)) {
if err := recover(); err != nil {
stack := make([]byte, 8096)
stack = stack[:runtime.Stack(stack, false)]
stack = trimStackPaths(stack, "GoSally-mvp")
log.Printf("recovered panic:\n%s", stack)
onPanic(err)
}