go

Go Language Compared to Python

I am interested in hearing the differences between Go and Python and reading an overview of the similarities. I know that Google has heavy usage of Python and Go looks to be a bit related. I was searching around a bit for a comparison and discussion of the influences of Python in Go and the goals of the Go language but I did not find a ...

Reading the inner text of an XML element using Go

I'm trying to read an XML file in Go using the xml package (http://golang.org/pkg/xml/). My problem is that I'm not sure how to read an element's inner text. I load the document in the xml.Parser and then call parser.Token() to move through the file. I check to see what the token is using the following: token, err := parser.Token() if ...

What's Go's equivalent of argv[0]?

How can I get my own program's name at runtime? What's Go's equivalent of C/C++'s argv[0]? To me it is useful to generate the usage with the right name. Update: added some code. package main import ( "flag" "fmt" "os" ) func usage() { fmt.Fprintf(os.Stderr, "usage: myprog [inputfile]\n") flag.PrintDefaults() o...

Go string to ascii byte array

How can i encode my string as ascii byte array? In go ...

Reading utf8-encoded data from a connection, using Go.

I can easily write a string to a connection using io.WriteString. However, I can't seem to easily read a string from a connection. The only thing I can read from the connection are bytes, which, it seems, I must then somehow convert into a string. Assuming the bytes represent a utf8-encoded string, how would I convert them to string fo...

Customizing an existing handler in Go's http library.

With the following being defined as is noted in the http library: func Handle(pattern string, handler Handler) type Handler interface { ServeHTTP(*Conn, *Request) } How can I improve upon an existing handler (say, websocket.Draft75Handler for instance) by giving it an additional argument (and tell it what to do with the argument)? I'...

How to implement resizable arrays in Go

I come from a C++ background and I'm used to using the std::vector class for things like this. Lets assume i want a dynamic array of these: type a struct { b int c string } What is the standard way of doing this? A snippet would be very useful ...

Checking if a channel has a ready-to-read value, using Go.

How do I check if a channel has a value for me to read? I don't want to block when reading a channel. I want to see if it has a value. If it does have one, I'll read it. If it doesn't have one (yet), I'll do something else and check back again later. Thanks! ...

Debugging a program written in the go language.

How do I debug a go program? I have been using the Gedit go IDE, but it doesn't have debugging. Is there a way to step though my code and inspect memory? Or am I stuck with print statements? Can I use OutputDebugString? ...

Panic recover in Go v.s. try catch in other languages

I've just read this post about Panic/Recover in Go and I'm not clear on how this differs from try/catch in other mainstream languages. ...

What's wrong with my Priority Queue's Pop method?

Based on Rob Pike's load balancer demo, I implemented my own priority queue, but my Pop method is not right, can anyone tell me what's wrong? package main import ( "fmt" "container/heap" ) type ClassRecord struct { name string grade int } type RecordHeap []*ClassRecord func (p RecordHeap) Len() int { return len(p) }...

Are there any go librarys that provide associative array capability?

I'm looking for a go language capability similar to the "dictionary" in python to facilitate the conversion of some python code. EDIT: Maps worked quite well for this de-dupe application. I was able to condense 1.3e6 duplicated items down to 2.5e5 unique items using a map with a 16 byte string index in just a few seconds. The map-rela...

Are there mechanisms similar to Go's defer in other languages?

I am not familiar with mechanisms similar to Go's "defer" in other languages. Are there similar mechanisms in other languages? ...

What does the asterisk do in "Go".

I'm a web developer looking to expand my horizons in order to get better at programming as a whole. I've done a bit Java and some simple Android applications. I'm now looking into lower level languages like C and Go (which I must say has some beautiful syntax and great ideas thus far, though I'm maybe too inexperienced to comment). So y...

D versus Go comparison

It would be interesting to contrast these two new languages by several aspects: What are their design influences? Where do they intersect in their goals / where do they rival? Where are they distinct? For which tasks is one or the other better suited? What is your outlook on these languages? That is, which niche will D resp. Go fill? ...

How to access other client connections from a Go WebSocket handler?

Note: I'm more interested in understanding general Go concepts/patterns, rather than solving this contrived example. The Go (golang) WebSocket package provides a trivial echo server example, which condenses down to something like this: func EchoServer(ws *websocket.Conn) { io.Copy(ws, ws); } func main() { http.Handle("/echo", websock...

Signal Processing in Go

I have come up with an idea for an audio project and it looks like Go is a useful language for implementing it. However, it requires the ability to apply filters to incoming audio, and Go doesn't appear to have any sort of audio processing package. I can use cgo to call C code, but every signal processing library I find uses C++ classes ...

Getting a reflect.Type from a name

If I have a name of a type (i.e "container/vector"), is there a way to lookup the reflect.Type that has the given name? I'm trying to write a simple database-backed workqueue system and this it would be very difficult without this feature. ...

Can we have function pointers in Google Go?

I was learning about pointers in Google Go. And managed to write something like, func hello(){ fmt.Println("Hello World") } func main(){ pfunc := hello //pfunc is a pointer to the function "hello" pfunc() //calling pfunc prints "Hello World" similar to hello function } Is there a way to declare t...

Which languages to look into?

Yes, I know these kinds of questions have been asked a million times, but it just seems no matter how much research I do, there are great arguments for every side you can think of. I know the standard/best practice would be to just 'try them all, and see which one you like', but I really would rather have a better idea before I dedicate ...