Created
September 23, 2019 14:43
-
-
Save fasterthanlime/ec8177b114fa9f711d90b95b49a0e236 to your computer and use it in GitHub Desktop.
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
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