Created
January 11, 2013 23:43
-
-
Save Veejay/4514964 to your computer and use it in GitHub Desktop.
First Go program. Iterates over a map and reads the content of a given directory.
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 "fmt" | |
import "os" | |
func main() { | |
m := make(map[string]int) | |
m["foo"] = 1 | |
m["blah"] = 2 | |
for i := range m { | |
value, _ := m[i] | |
fmt.Printf("Value for key %s: %d\n", i, value) | |
} | |
file, err := os.Open("/Users/Bertrand") | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
currDirFiles, err := file.Readdir(0) | |
// Quite redundant | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
for _, elem := range currDirFiles { | |
fmt.Printf("Name of the file: %s\n", elem.Name()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment