Created
August 24, 2025 12:45
-
-
Save andig/c042d36a5e4c770d7994bb09f3a81e09 to your computer and use it in GitHub Desktop.
Check for data on stdin in Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if fi, _ := os.Stdin.Stat(); fi.Mode()&os.ModeNamedPipe != 0 || fi.Mode()&os.ModeCharDevice == 0 { | |
data, err := io.ReadAll(os.Stdin) | |
if err != nil { | |
log.Fatal(err) | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment