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 Nats service. For normal running this is typically fine. …


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 complexity, what if we are not persistently saving the file to the file system on our service, but pushing it to a 3rd party storage such as AWS S3. …


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 really nice interface, Virt-Manager allows for more detailed configuration of your virtual machine. …

About

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