go

Using Google's Go Language to Write a Library for an iPhone App

I'm considering using Go as a low-level, performant language alternative to C/Objective-C to implement a library for an iPhone App. Could either of the Go compilers generate a library that could be linked into a native iPhone app with the Go runtime, etc.? Is there an ARM port for Go or does gccgo/gcc support this? I imagine that since g...

Trouble reading from a socket in go

I'm trying to learn the go language, and I'm writing a simple echo server. I'm having difficulty making it work, though. func listen(server string) { var buf []byte listener, ok := net.Listen("tcp", server) if ok != nil { fmt.Fprintf(os.Stderr, "Could not listen on socket: %s\n", ok.String()) return } ...

How to implement BitSet with Go?

I didn't find a BitSet package in Go, so I tried to implement it. I'd like to use a array of uint64 to store the bits. I need the number of bits to allocate the uint64 array. With Java, I can define a constructor that takes an integer. While Go doesn't provide constructor, how can I properly initialize the BitSet 'object' when user cal...

How to get a MD5 hash from a string in Golang?

I'm just starting with Golang and I am now stuck on MD5 creation. This is how I started to get a md5 hash from a string: import "crypto/md5" var original = "my string comes here" var hash = md5.New(original) But obviously this is not how it works. Can someone provide me a working sample for this? ...

Dereferencing pointers in Go

...

bytes.Split separator as []byte("...")

In bytes_test.go I see: a := Split([]byte(tt.s), []byte(tt.sep), tt.n) where tt.s and tt.sep are strings. But when I try to do a := bytes.Split([]byte("test"), []byte("e"), 0) I get: cannot convert "test" (type ideal string) to type []uint8 in conversion cannot convert "e" (type ideal string) to type []uint8 in conversion ...

basic json > struct question ( using 'Go')

I'm working with twitter's api, trying to get the json data from http://search.twitter.com/trends/current.json which looks like: {"as_of":1268069036,"trends":{"2010-03-08 17:23:56":[{"name":"Happy Women's Day","query":"\"Happy Women's Day\" OR \"Women's Day\""},{"name":"#MusicMonday","query":"#MusicMonday"},{"name":"#MM","query":"#MM...

Looking for Go equivalent of scanf.

I'm looking for the Go equivalent of scanf(). I tried with following code: 1 package main 2 3 import ( 4 "scanner" 5 "os" 6 "fmt" 7 ) 8 9 func main() { 10 var s scanner.Scanner 11 s.Init(os.Stdin) 12 s.Mode = scanner.ScanInts 13 tok := s.Scan() 14 for tok != scanner.EOF { 15 ...

Go: using a pointer to array

I'm having a little play with google's Go language, and I've run into something which is fairly basic in C but doesn't seem to be covered in the documentation I've seen so far When I pass a pointer to an array to a function, I presumed we'd have some way to access it as follows: func conv(x []int, xlen int, h []int, hlen int, y *[]int)...

Google's 'go' and scope/functions

In one of the example servers given at golang.org: package main import ( "flag" "http" "io" "log" "template" ) var addr = flag.String("addr", ":1718", "http service address") // Q=17, R=18 var fmap = template.FormatterMap{ "html": template.HTMLFormatter, "url+html": UrlHtmlFormatter, } var templ = templat...

Google Go: notwithstanding keyword

What does the notwithstanding keyword mean in Google Go? For background, see http://www.libertatia.org/blog/?p=247, which was linked from Reddit | Programming. ...

Cassandra datastore client in Go language

Is it possible to write client for Cassandra datastore in Go language? ...

Porting Java app to Go - any advice?

We want to rewrite kodingen.com backend with Go which currently is Java, running as daemon using jsvc. I have never touched any C in my life, am only experienced in Java so I don't know if this is something that I should even start. However, task is pretty simple read shell commands from mysql database queue and execute them in paral...

Go - Data types for validation

How to create a new data type for Go which to can check/validate its schema when is created a new variable (of that type)? By example, to validate if a string has 20 characters, I tried: // Format: 2006-01-12T06:06:06Z func date(str string) { if len(str) != 20 { fmt.Println("error") } } var Date = date() type Account struct { ...

Go - Example about crypto/rand

Could put a little example about the use of crypto/rand [1]? The function Read has as parameter an array of bytes. Why? If it access to /dev/urandom to get the random data. func Read(b []byte) (n int, err os.Error) [1] http://golang.org/pkg/crypto/rand/ ...

int from string in go

What's the function to create a int value from string i := ???.????( "10" ) ...

Why is go language so slow?

As we can see from The Computer Language Benchmarks Game: go is in average 10x slower then C go is 3x slower then Java !? How it can be bearing in mind that go compiler produces native code for execution? Immature compilers for go? Or there is some intrinsic problem with the go language? EDIT: Most answers deny intrinsic slowness...

How to pass arguments to Go program?

I can't see arguments for main() in package main. How to pass arguments from command line in Go? A complete program, possibly created by linking multiple packages, must have one package called main, with a function func main() { ... } defined. The function main.main() takes no arguments and returns no value. ...

Go - Get length to decoding Ascii85

ascii85 has a function to get the maximum length of an encoding MaxEncodedLen(). I think that it should have too a function to get the length at decoding like it has in Base64. http://golang.org/pkg/encoding/ascii85/ ...

How do I call C from Go using the "foreign function interface"

Hi, How do I use Go's "foreign function interface" to call out to a C function? This interface is mentioned on the FAQ, but I cannot see it mentioned elsewhere in the docs. ...