Skip to content

Instantly share code, notes, and snippets.

@fasterthanlime
Created September 23, 2019 14:43
Show Gist options
  • Save fasterthanlime/ec8177b114fa9f711d90b95b49a0e236 to your computer and use it in GitHub Desktop.
Save fasterthanlime/ec8177b114fa9f711d90b95b49a0e236 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
)
func usage() {
fmt.Printf("Usage: gostat file|os PATH")
os.Exit(1)
}
func main() {
if len(os.Args) <= 2 {
usage()
}
method := os.Args[1]
name := os.Args[2]
switch method {
case "file":
fmt.Println("Using os.Open(), then file.Stat()")
file, err := os.Open(name)
if err != nil {
panic(err)
}
s, err := file.Stat()
if err != nil {
panic(err)
}
fmt.Printf("%#v\n", s)
case "os":
fmt.Println("Using os.Stat() directly")
s, err := os.Stat(name)
if err != nil {
panic(err)
}
fmt.Printf("%#v\n", s)
default:
usage()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment