Skip to content

Instantly share code, notes, and snippets.

@Veejay
Created January 11, 2013 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Veejay/4514964 to your computer and use it in GitHub Desktop.
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.
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