Go

Display File, Function, and Line Number in Go (Golang)

Jim Lawless
Years ago, I used a macro in C and C++ programs to provide information on the current line of code being executed. I used this in error handlers and exception traps in addition to other information. Displaying the file name and line number of a given exception in large projects was often helpful in the speedy remediation of issues. I also used this technique to home brew tracing function in the code.

A TCP Echo Server in Go (Golang)

Jim Lawless
I had the need to test connectivity between a couple of servers, recently. Netcat wasn’t available so we managed to cobble something together that worked for the particular situation. An “echo server” is a program that people often code as kind of a “kata” for practice. I decided to write an echo server in Go. I have not tested this code on all appropriate environments, yet, so I wouldn’t say that this code is completely stable.

An RPN Interpreter in Go (Golang)

Jim Lawless
I built a non-Turing-complete interpreter in Go whose current incarnation is simply named “rpnrepl”. rpnrepl is a very tiny stack-based, postfix language whose syntax is similar to that of the Forth programming language. rpnrepl can only perform four mathematical operations, display the topmost item on the stack, display a newline, and exit the running program. Unlike Forth whose grammar can change dynamically, rpnrepl does have a simple grammar. Words are separated by spaces unless bound by single quotation-marks or double quotation-marks.

Simulating Try-Catch in Go (Golang)

Jim Lawless
In the Go code I’ve been writing to help learn the language, I’ve been using a common function to deal with error conditions. The function terminateOnErr(err error) checks to see if the err parameter is nil. If not, it displays the paramter and calls os.Exit(1). func terminateIfError(err error) { if( err != nil ) { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } Later in the code, I use the following line after every error check that I need to perform:

Sending GMail with Go (Golang)

Jim Lawless
I needed a command-line e-mail sender utility that would send e-mail via my GMail account. I wanted the solution to work on Windows and OS/X for the time being. My solution is a utility named GSend. GitHub repo: https://github.com/jimlawless/gsend/ The Go source is as follows: // Copyright 2013 - by Jim Lawless // License: MIT / X11 // See: http://www.mailsend-online.com/license2013.php // // Bear with me ... I'm a Go noob. package main import ( "log" "flag" "net/smtp" "fmt" ) func main() { to := flag.

Variant Types in Go (Golang)

Jim Lawless
Here we Go again… I had corresponded with some seasoned Go programmers about variant types some time ago. I was searching for a way to keep a slice of data where each element might be a different data-type. The approach I had been taking was in trying to define a data-structure that could act as a wrapper for some of the basic data types. I then learned through the wisdom of these developers that Go could already accommodate my needs in a much simpler fashion.