Top "Go" questions

Go is an open-source programming language.

Correct way to initialize empty slice

To declare an empty slice, with a non-fixed size, is it better to do: mySlice1 := make([]int, 0) or: mySlice2 := []int{} …

arrays go slice
Convert string to integer type in Go?

I'm trying to convert a string returned from flag.Arg(n) to an int. What is the idiomatic way to …

string go type-conversion
What is the idiomatic Go equivalent of C's ternary operator?

In C/C++ (and many languages of that family), a common idiom to declare and initialize a variable depending on …

go ternary-operator conditional-operator
Converting Go struct to JSON

I am trying to convert a Go struct to JSON using the json package but all I get is {}. I …

json go
Parsing date string in Go

I tried parsing the date string "2014-09-12T11:45:26.371Z" in Go. Code layout := "2014-09-12T11:45:26.371Z" str := "2014-11…

date go
How to get JSON response from http.Get

I'm trying read JSON data from web, but that code returns empty result. I'm not sure what I'm doing wrong …

json go
How to generate a random string of a fixed length in Go?

I want a random string of characters only (uppercase or lowercase), no numbers, in Go. What is the fastest and …

string random go
Convert time.Time to string

I'm trying to add some values from my database to a []string in Go. Some of these are timestamps. I …

string time go
How to get the directory of the currently running file?

In nodejs I use __dirname . What is the equivalent of this in Golang? I have googled and found out this …

go
go get results in 'terminal prompts disabled' error for github private repo

I created the private repo examplesite/myprivaterepo using the Github UI from my browser. Then I went to my go …

git go