So recently I was asked help get some API services built with go to be testable through service testing. By service testing I mean using `go test` to test JSON payloads coming from the running service.

The problem was that the service was designed with all the drivers put in a global struct variable in the main.go file.

./main.go

package mainimport (
"github.com/nats-io/nats"
...
)
var global struct {
nats *nats.Conn
...
}
func main() {
global.nats, err := nats.Connect("nats://127.0.0.1:4222")
...
}

Now in order to run this once its built we would need a running instance of a…


OK, so your asking yourself, why… that’s easy with os.File you can just use the Stat() method and get the os.FileInfo and inside the os.FileInfo struct there is a Size() method and that will return an int64.

file, err := os.Open("path/to/file")
if err != nil {// Do Something}
fInfo, err := file.Stat()
if err != nil {// Do Something}
fmt.Println(fInfo.Size())

That’s it! Done! post over…. right? Well No…

Getting the size from a file on your file system is trivial, but many of us are getting a file over an HTTP connection from an HTML form. To add to this…


-Migrated from my original blog

This is my fist post on this blog, so I decided to do something simple. Years ago when I switched to using Linux, I started using VirtualBox to test other Linux distros, and to run Window.

SOME BACKGROUND

VirtualBox is great and easy to use, but the preformance on lower powered machines is not so great. Granted you are running an operating system on top of another operating system (especially a GUI OS) is resource intensive as it is.

About 6 months ago I switched to using qemu/KVM, first with Gnome-Boxes, then Virt-Manager. While Gnome-Boxes has a…


-Migrated from my original blog

BACKGROUND:

Golang has really become my go to language, and has replaced Python as my main scripting language. I love how easy it is to write. I love how fast it is to compile, and is a compiled language, so I can just distribute a single binary instead of hoping that there is a Python run-time install (I.E. small container images). And with distributing these binaries, I can easily cross compile Golang to different architectures, and OS’s without installing a cumbersome tool-chain.

One big downside to the Go language is that it has very little GUI…


-Migrated from my original blog

BACKGROUND:

This post came from one of the challenges set by my local GoLang user group.

Problem 2:

Create an API with an endpoint that returns a PNG image containing the numeric representation of the number of times that endpoint has been hit.

A data URI is basically a base64 bit encoded string of characters. You can encode many different types of data including binary data such as images. Most modern browsers can decode data URIs automatically.

A great post on the basics of data URIs in web development is CSS-Tricks Data URI. This is where…


-Migrated from my original blog

BACKGROUND

This just started as a thought… What if I could compile an existing executable binary into a golang binary. So in my mind I toyed with the idea, and so far the best route I could find (after 10min of thinking), was convert the binary to a byte array. Now this seems very inefficient, and it is, but still fun and kind of cool.

WARNING

With this tutorial we will be using a simple small binary, but when I first thought of the idea I tried it with a NodeJS binary. The NodeJS binary is 28.8…

Daniel Toebe

JUST THE RAMBLINGS OF A PASSIONATE PROGRAMMER AND LINUX LOVER

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store