logger := log.New(logFile, "", log.LstdFlags)
package main import ( "fmt" "log" "os" "time" "net" ) golang portable windows
go build -ldflags="-s -w" -o tool.exe You can also use UPX (Ultimate Packer for Executables) to shrink further, but stripped builds are usually enough. Go 1.20+ supports Windows 7 and later. Set environment variables for older compatibility: logger := log
for _, err := net.DialTimeout("tcp", target+":80", 2*time.Second) if err != nil msg := fmt.Sprintf("❌ %s is DOWN: %v", target, err) fmt.Println(msg) logger.Println(msg) else msg := fmt.Sprintf("✅ %s is UP", target) fmt.Println(msg) logger.Println(msg) time.Sleep(10 * time.Second) Stripped Go binaries are 2–10 MB
go build -ldflags="-H=windowsgui" Perfect for tray icons or background tools. Stripped Go binaries are 2–10 MB. For tiny tools, use:
func main() os.O_WRONLY, 0644) if err != nil log.Fatal(err)
To build a (no console window), use:
logger := log.New(logFile, "", log.LstdFlags)
package main import ( "fmt" "log" "os" "time" "net" )
go build -ldflags="-s -w" -o tool.exe You can also use UPX (Ultimate Packer for Executables) to shrink further, but stripped builds are usually enough. Go 1.20+ supports Windows 7 and later. Set environment variables for older compatibility:
for _, err := net.DialTimeout("tcp", target+":80", 2*time.Second) if err != nil msg := fmt.Sprintf("❌ %s is DOWN: %v", target, err) fmt.Println(msg) logger.Println(msg) else msg := fmt.Sprintf("✅ %s is UP", target) fmt.Println(msg) logger.Println(msg) time.Sleep(10 * time.Second)
go build -ldflags="-H=windowsgui" Perfect for tray icons or background tools. Stripped Go binaries are 2–10 MB. For tiny tools, use:
func main() os.O_WRONLY, 0644) if err != nil log.Fatal(err)
To build a (no console window), use: