Sharing Golang packages to C and Go

The latest Go 1.5 version is out. As part of the new features, Go compiler can compile packages as a shared libraries. It accepts -buildmode argument that determines how a package is compiled. These are the following options: archive: Build the listed non-main packages into .a files. Packages named main are ignored. c-archive: Build the listed main package, plus all packages it imports, into a C archive file. c-shared: Build the listed main packages, plus all packages that they import, into C shared libraries....

August 23, 2015 · 4 min · Svetlin Ralchev

Conditional compilation in Golang

When developing Go package or application that depends on specific features of the underlying platform or architecture it is often necessary to use a specialised implementation. There are two parts of Go conditional compilation system, which we will now explore in more detail. Build constraints A build constraints (known as build tags) is an optional top line comment that starts with // +build package api Declaration of build constraints follows the following rules:...

August 16, 2015 · 4 min · Svetlin Ralchev

Delve: Next generation debugger for Golang

In my previous post I demonstrated how you can debug golang applications with LLDB. In this article I will illustrate the most recent debugger for Go: Delve The debugger is a community effort to bring a debugger in the toolchain of every Go developer. It’s written in Go to debug Go code. It’s still in active development, but we can still benefit from its basic features. Installation You should install Delve with the following command:...

August 8, 2015 · 4 min · Svetlin Ralchev

Debug Golang applications: LLDB

Even that ease and simplicity of using go are one of its main advanatages, there are difficulties in debugging applications written in go. The lack of mature tools (like supported vim plugin) push most of us to use logging techniques to inspect and track down issues. In this article, I will demonstrates how you can use vim and lldb to debug a go application. Before that you should make the application capable for debugging....

August 1, 2015 · 3 min · Svetlin Ralchev

SSH tunneling in Golang

In my previous post, I illustrated the basic usage of ssh package. In this article I will demonstrate how we should use it to implement SSH tunneling. We will forward connection to localhost:9000 through example.com:22 to localhost:8080. The tunneling protocol allows a network user to access or provide a network service that the underlying network does not support or provide directly. We have four actors in this scenario: client - the client that needs resource from remote server local server - a server accessible by the client intermediate server - a server accessible by the local server and remote/target server remote/target server - a server running behind the intermediate server network Each of this server endpoints can be represented by the following struct:...

July 26, 2015 · 3 min · Svetlin Ralchev