Last week I started to learn Go (Golang) programming language, made by Google. For a first learning resource about the language I picked An introduction to programming in Go, which turned out to be a great starting point in learning this language. As soon as I finished with familiarizing with its basic concepts (types, variables, control structures and functions) I decided to write my first program which renames files. During writing a program I discovered that Go has an easy to follow documentation.
package main import ( "io/ioutil" "os" "strings" "path" ) func main() { dir, _ := os.Getwd() dirFiles, _ := ioutil.ReadDir(dir) for _, fileInfo := range dirFiles { fileName := fileInfo.Name() if path.Ext(fileName) != ".txt" { continue } if newFileName := strings.Replace(fileName, " ", "-", -1); fileName != newFileName { os.Rename(path.Join(dir, fileName), path.Join(dir, newFileName)) } } }
My next step in learning Go is going though Go Programming Blueprints. It’s book containing couple of projects which are a legitimate real-world applications. I expect from the book to get a good feeling about the way applications in Go are built. Currently I’m past first 2 chapters and so far I love it.