Skip to content

Instantly share code, notes, and snippets.

@Veejay Veejay/firstprog.go
Created Jan 11, 2013

Embed
What would you like to do?
First Go program. Iterates over a map and reads the content of a given directory.
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
You can’t perform that action at this time.