Category "go"

Why would return parameters be named?

What benefits arise from naming a function's return parameter(s)? func namedReturn(i int) (ret int) { ret = i i += 2 return } func anonReturn(i in

How to flush Stdin after fmt.Scanf() in Go?

Here's an issue that's bedeviling me at the moment. When getting input from the user, I want to employ a loop to ask the user to retry until they enter valid in

cannot convert data (type interface {}) to type string: need type assertion

I am pretty new to go and I was playing with this notify package. At first I had code that looked like this: func doit(w http.ResponseWriter, r *http.Request)

How to get the pointer of return value from function call?

I just need a pointer to time.Time, so the code below seems invalid: ./c.go:5: cannot take the address of time.Now() I just wonder why? Is there any way t

How to bulk remove objects in minio with golang

I'm trying to bulk remove objects in minio as described here: objectsCh := make(chan minio.ObjectInfo) // Send object names that are needed to be removed to ob

Is there an efficient way to calculate execution time in golang?

I'm looking for the best way to calculate execution time in go. func main() { start := time.Now() time.Sleep(time.Second * 2) //something doing he

Check if a value is in a list

Does Go have something similar to Python's in keyword? I want to check if a value is in a list. For example in Python: x = 'red' if x in ['red', 'green', 'ye

Assign Golang variable to Javascript

Currently I am having an issue related to assign a Golang variable to a Javascript variable. I am using the Golang templates, so, from the backend I sent a JSON

How to overwrite file content in golang

I have a empty file called a.txt, I want to output a value(int) to it in a loop, and overwrite last content in file a.txt. For example, // open a file

Declare a constant array

I have tried: const ascii = "abcdefghijklmnopqrstuvwxyz" const letter_goodness []float32 = { .0817,.0149,.0278,.0425,.1270,.0223,.0202, .0609,.0697,.0015,.0077

Trim string's suffix or extension?

For example, I have a string, consists of "sample.zip". How do I remove the ".zip" extension using strings package or other else?

"package XXX is not in GOROOT" when building a Go project

I have a weird issue that arose when I took a break from this project. Upon starting up Goland, I'm riddled with errors when trying to run my project. The spe

Go StartsWith(str string)

Is there a StartsWith(str1, str2 string) function that can check if str1 is a prefix of str2 in Go language? I want a function similar to the Java's startsWith

How to view full dependency tree for nested Go dependencies

I'm trying to debug the following build error in our CI where "A depends on B which can't build because it depends on C." I'm building my data service which doe

Go XML Marshalling and the Root Element

In Go, you can marshall a struct to XML, e.g.: package main import ( "encoding/xml" "fmt" ) type person struct { Name string Starsign str

Cannot use "a" (type string) as type in array element in go

I'm pretty new to Golang and I have an issue with adding items to Array. I use this link as a reference golang-book. I have this struct: package models type Fi

How to list installed go packages

To my knowledge go distribution comes with some sort of package manager. After go 1.4.1 installation I've run go help in order to find any sub-command capable o

"undefined" function declared in another file?

I'm trying to write a basic go program that calls a function on a different file, but a part of the same package. However, it returns: undefined: NewEmployee

How can I efficiently download a large file using Go?

Is there a way to download a large file using Go that will store the content directly into a file instead of storing it all in memory before writing it to a fil

How to use go-vcr with githubv4 ? - getting httpClient Transport

Looking at the set up for go-vcr // Start our recorder r, err := recorder.New("fixtures/etcd") if err != nil { log.Fatal(err) } defer r.