Last active
February 1, 2020 05:29
-
-
Save kaneshin/96b5a1cdd3cbaddbacdc87129abce49f to your computer and use it in GitHub Desktop.
This file contains 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
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