Skip to content

Instantly share code, notes, and snippets.

@kaneshin
Last active February 1, 2020 05:29
Show Gist options
  • Save kaneshin/96b5a1cdd3cbaddbacdc87129abce49f to your computer and use it in GitHub Desktop.
Save kaneshin/96b5a1cdd3cbaddbacdc87129abce49f to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"
)
func init() {
flag.Parse()
}
func run() error {
var filename string
if args := flag.Args(); len(args) > 0 {
filename = args[0]
}
var r io.Reader
switch filename {
case "", "-":
r = os.Stdin
default:
f, err := os.Open(filename)
if err != nil {
return err
}
defer f.Close()
r = f
}
t, err := ioutil.ReadAll(r)
if err != nil {
return err
}
fmt.Print(string(t))
return nil
}
func main() {
err := run()
if err != nil {
log.Print(err.Error())
os.Exit(1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment