Category: Go

  • Go – Finding and removing duplicate files on a Mac

    My laptop’s hard drive is plagued with the same family pics stored in different folders. So, I wrote a simple app in Go to take care of this for me. The app does this by comparing MD5 hashes of files. Usage Assuming you saved the code in a file called main.go, here is how you…

  • Gogland build expired (renamed to Goland)

    This confused me for a few minutes so I am writing this for those who have the same issue. Jetbrains renamed Gogland Goland. They also expired Gogland build. So you have to go to their site and download Goland and use that. Remove Gogland completely from your computer

  • Why Golang/Go is so awesome

    I have been working with Go for quite some time now and know more about it. My initial thoughts about it were accurate, I think with some variations. Go really can do almost everything. It can be run like any interpreted language for development and compiled for production This is something I love about Go…

  • Golang: Restart web server on file change

    A great feature of scripting languages like PHP, Python and Ruby is that you don’t need to re-compile the app or restart a web server every time you change something. With Go, you need to restart the web server for your changes to take affect. This can be a pretty daunting task. We can, however,…

  • Golang: Get the function caller’s name

    Problem Consider this code: package main import “fmt” func foo() { // foo() wants to know who called it fmt.Println(“HI”) } func main() { foo() } In the function foo, we want to get the name of the function (and preferably file name and number ) that called it. Solution We can get this information…

  • Golang: Connect to Postgres and selecting data from a table

    You will need to get the Postgres driver first. In the terminal type: go get github.com/lib/pq Connecting to Postgres package main import ( _ “github.com/lib/pq” “database/sql” “fmt” ) func main() { // Connect to the DB, panic if failed db, err := sql.Open(“postgres”, “postgres://user:password@localhost/dbName?sslmode=disable”) if err != nil { fmt.Println(`Could not connect to db`) panic(err)…