Skip to content

Instantly share code, notes, and snippets.

@clandry94
Created September 25, 2018 00:45
Show Gist options
  • Save clandry94/9fac4dce0bf08a3f7caedf3881cc95b9 to your computer and use it in GitHub Desktop.
Save clandry94/9fac4dce0bf08a3f7caedf3881cc95b9 to your computer and use it in GitHub Desktop.
import (
"fmt"
"io/ioutil"
"os"
"sync"
)
var wg sync.WaitGroup
func main() {
b, err := ioutil.ReadAll(os.Stdin)
if err != nil {
panic(err)
}
wg.Add(1)
go func(b []byte) {
fmt.Fprintf(os.Stdout, string(b))
wg.Done()
}(b)
if os.Args[1] != "" {
f, err := os.OpenFile(os.Args[1], os.O_RDWR|os.O_CREATE, 0755)
if err != nil {
panic(err)
}
wg.Add(1)
go func(b []byte) {
f.Write(b)
wg.Done()
}(b)
}
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment