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) { notify.Post(“my_event”, “Hello World!”) fmt.Fprint(w, “+OK”) } I wanted to append newline to Hello World! but not in the function doit above, because that would be pretty … Read more

Application auto build versioning

Is it possible to increment a minor version number automatically each time a Go app is compiled? I would like to set a version number inside my program, with an autoincrementing section: $ myapp -version MyApp version 0.5.132 Being 0.5 the version number I set, and 132 a value that increments automatically each time the … Read more

Stack vs heap allocation of structs in Go, and how they relate to garbage collection

I’m new to Go and I’m experiencing a bit of cognitive dissonance between C-style stack-based programming where automatic variables live on the stack and allocated memory lives on the heap and Python-style stack-based-programming where the only thing that lives on the stack are references/pointers to objects on the heap. As far as I can tell, … Read more

Is it OK to leave a channel open?

Is it OK to leave a Go channel open forever (never close the channel) if I never check for its state? Will it lead to memory leaks? Is the following code OK? func (requestCh chan<- Request) GetResponse(data RequestData) Response { reply := make(chan Response) requestCh <- Request{data: data, replyCh: reply} return <-reply } 6 Answers … Read more

List directory in Go

I’ve been trying to figure out how to simply list the files and folders in a single directory in Go. I’ve found filepath.Walk, but it goes into sub-directories automatically, which I don’t want. All of my other searches haven’t turned anything better up. I’m sure that this functionality exists, but it’s been really hard to … Read more