Not today...

Filed under golang...

comments

Snippet

Viper Multi Config

This post will explain how to overload configurations in Golang using viper and cobra libraries. The use case may be a niche one, but I find this to be an easy to understand and pretty clear way to do configuration merge. The problem and the expectation I am deploying most of my application on Kubernetes nowadays (I also moved my personal infrastructure to it a few weeks ago). This solution come with a big tooling ecosystem and a really opiniated way to deploy. Read More...

Tagged golang , dev , cli

comments

Project

Introducing Janus (SSH Agent written in Go)

Why this project I am currently using gopass to store and share my passwords. I was relying on GPG to handle the encryption side of the process. Then a colleague of mine introduced me to age. This encryption specification allows the use of SSH keys and specifically the ED25519 ones. I decided to make the switch and moved all my stores to age encryption. I am protecting my private key with a password and only loading it inside my agent. Read More...

Tagged dev , golang

comments

Snippet

Golang SSH tunneling

I already did an article around Golang and SSH previously, since it is a huge part of my current work. Today, I will share a small snippet which can be quite handy when automating stuff. This is how to perform a SSH tunnel using Golang. I will not explain what it is or what it is useful for, if you need more details please check the doc. In this tutorial, I will use the official SSH library from Google. Read More...

Tagged dev , golang

comments

Snippet

RSA OAEP in Go and Openssl equivalent

From time to time you write some code to deal with data that will be stored somewhere on a drive. When debugging it may be nice to have “shell” commands to mimic code and help understanding what is going on. When it comes to encryption the swiss army knife you will most probably have in your shell environment is openssl. But reading and understanding the documentation can sometimes be “challenging”. Read More...

Tagged golang , bash

comments

Snippet

Golang SSH, marshalling, unmarshalling

Golang is a wonderful language to deal with the SSH protocol. It’s mostly due to the SSH library which is pretty exhaustive. However, when I had to deal with external requirements like SSH Agent or OpenSSH I experienced a lack of example and struggled a bit interfacing. In this article we will see how to exchange keys between a program written in Go and those tools using files. This means to output our keys in a proper format (marshaling) and being able to read them (unmarshalling) from the external tool format. Read More...

Tagged golang , dev

comments

Snippet

Parallel runners with teardown in go

From time to time in go I have to start multiple small services acting in parallel. For example, a ssh server tied to an administration console (one is running on port 80 the other on port 22), or a kafka consumer pushing to a database and a website to serve those informations. You can decouple this in multiple programs, or run them through some kind of a manager and handle everything at the same place. Read More...

Tagged golang , dev

comments

Snippet

Filepath Walk bug?

During the development of a small project I noticed something strange with golang’s function filepath.Walk. If you are going over a directory, and return filepath.SkipDir error on a file entry. The walker will stop. Setup directory First, set up a simple directory to walk mkdir -p foo/baz touch foo/bar touch foo/baz/qux Run the script Now, let’s run this example script, with the previous directory as the entry argument. I will reuse the example from golang documentation website with small changes. Read More...

Tagged golang

comments

Snippet

Cancel copy of huge file in Go

I recently came across this video on Golang programming. I think this was the moment I finally fully understood the power of Go. It is smart, simple and elegant, I love it. Then, a few days later, I was coding on a toy project and I was doing some stuff around the io package to copy huge files. I wanted to achieve copy cancelation during the processing, basically, being able to interrupt. Read More...

Tagged dev , golang

comments

Snippet

Golang err shadowing

A feature I like in golang is the hability to declare a variable at the assignation time. Something like this: foo := "bar" Here the variable foo will automatically set up as a string with the value “bar”. One more feature is to be able to allocate on same line as doing a comparison. Like this: if foo := "bar"; foo == "baz" { // do something } else { // do something else } This is really handy when it comes to catch errors from an other function: Read More...

Tagged golang , dev