Author: jra

  • Gobs on the wire

    by

    in

    This week, I want to talk about how to use Go to write a client/server system with both synchronous requests and asynchronous event notifications. To help learn Go, I wrote a clone of the Conserver console server. Now, of course, the world didn’t need another console server, but it turned out to be an interesting…

  • The impatient producer

    by

    in

    Last week I showed how a channel could link a producer and a consumer, and I idly speculated on how you’d set the depth of the queue, relative to the rate and variability of the producer and the consumer’s need for new input. This weekend, I got to thinking about my next interesting Go project.…

  • Using a channel as a queue

    by

    in

    I try to write a Go article every Monday, but the holiday season has disrupted me a bit. So here’s a little something I dug out of my stocking to get things going again. I thought an interesting way to play with the exp/draw package, the http client, and the image decoder would be a…

  • A simpler way to embed data

    by

    in

    In my post about how to efficiently put data into a Go binary, I mentioned that strings are immutable, and can be accessed without causing the Go runtime to copy them. This turns out to be the key to a simpler way to achieve what I wanted to do. By simpler I mean, “no cgo”.…

  • RTM’s puzzle

    by

    in

    Here is a little program to that implements RTM’s series for Cliff Stoll. package main import “fmt” func count(s []int) int { i := 1 x := s[0] for ; i < len(s); i++ { if s[i] != x { break } } return i } func next(s []int) []int { res := []int{} for…

  • Where is bytes.NewReaderAt?

    by

    in

    I have a nice source of []byte slices (see last post), and now I’d like to do something with them that resembles a filesystem. I was planning on just using a map from name to file contents, which would work ok. But then I remembered seeing the archive/zip package, and I thought how much cooler…

  • Fat Constants, Thin Constants

    by

    in

    I play from time to time with a patch for Go that makes the Tiny runtime more capable. My current goal is to get a new backend for exp/draw working which writes to the SVGA screen. It would be cool to be able to decode the Go mascot and have him flying around the screen…

  • Passing function pointers through channels in Go

    by

    in

    Is is possible? Of course! package main func add(x, y int) int { return x + y } func mul(x, y int) int { return x * y } func runner(ch chan func(int, int)(int)) { for f := range ch { println(“f(1, 2) = “, f(1, 2)) } } func main() { ch := make(chan…

  • Where’s all the magic? In the linker…

    by

    in

    I have been trying to make a post per week about Go, but that requires learning something interesting during the week. I’m currently cycling between several little Go toys as I get the time. One is to make Go on raw hardware more useful/interesting. Another is a clone of the console server from conserver.com written…

  • Who said life is fair? The Go scheduler certainly didn’t…

    by

    in

    In my last post, I showed a program that had a strange behavior that caught my eye. I was trying to look at how Go handles shared access to globals, but the program also had the unintended effect of measuring the “fairness” of the Go scheduler. Here’s the program again, for context: When you run…