1.4 KiB
1.4 KiB
extras
-
to get type of variable
fmt.Println(reflect.TypeOf(student)) -
for signals
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)- sc — a chan os.Signal (must be buffered, e.g. make(chan os.Signal, 1)) that will receive the signal values.
- syscall.SIGINT — interrupt from the keyboard (Ctrl+C).
- syscall.SIGTERM — polite termination request (e.g. kill or what Kubernetes sends on pod shutdown).
- os.Interrupt — a platform-agnostic alias; on Unix it's the same as syscall.SIGINT, on Windows it also covers Ctrl+Break.
for deeply mested objects printing in console
data, _ := json.MarshalIndent(m, "", " ")
fmt.Printf("detected: %v\n", string(data))
go equivalent to fs.mkdirSync(dirPath,{recursive: true}
this will create directories recurselovely and wont throw error if it exist
err := os.MkdirAll(dirPath, 0755)
creating a build for all platfoms
script
#!/bin/bash
# Iterate through all supported GOOS/GOARCH combinations
go tool dist list | while read platform; do
# Split platform into OS and ARCH
GOOS=${platform%/*}
GOARCH=${platform#*/}
# Define output filename
output_name="myapp-${GOOS}-${GOARCH}"
if [ "$GOOS" = "windows" ]; then
output_name+=".exe"
fi
# Build the binary
env GOOS=$GOOS GOARCH=$GOARCH go build -o "$output_name" .
done