Dalla Rosa

Posts tagged golang

3 notes &

Short Post: Writing cross-platform code in Go

Lately I’ve been working on this little project in Go that involves system calls and some other more low level features of the OS. The project is supposed to support both Linux and Mac OSX / BSD so I was wondering how to separate code for those platforms. I found the answer in the Go source: Just name the files according to the target platform!

Example: 

Let’s say we have a project called “Platform Test” and we create the folder platform_test for it. In that folder you’ll have the following files

test_darwin.go

package main
import "fmt" func main() {
fmt.Println("I'm on mac")
}

and

test_linux.go

package main
import "fmt"
func main() {
fmt.Println("I'm on linux")
}

Now, if you run 

go build

in platform_test from your mac, you’ll have an executable called “platform_test” that prints

I’m on mac

and 

I’m on linux

if compiled on  a linux machine

I gotta say, this was a pretty neat way to implement cross-platform support.

Filed under go golang tech cross-platform

0 notes &

Tokyo Golang Developers

Missing some real world community around the Go language in Tokyo, I’ve decided to create the Tokyo Golang Developers meetup. It is a meetup for anyone with interest in the go programming language, be it a super hacker or complete beginner. We’re having (hopefully) our first meetup on the 28th in Shibuya and welcome all of you Tokyo gophers!

Filed under golang go programming tech