Functional Options

I was looking at ways to do method chaining in Go and found this article from Jon Calhoun about functional options. He made some really good points. I read through it probably three times, and being the dull knife that I am had trouble wrapping my head around it. So I sat down and tried to figure it out. I figured I’d put this post together for anyone who is in the same boat as me and wants a nice simple example of how functional options work.

Continue reading

Contributing to projects on GitHub is a great way to learn, contribute, and help make the software you use better. Normally, you would just make a fork of the project and then clone your fork and do your work. Then you would push to a branch in your fork and open a pull request for that branch. Go is a little different however. Since the imports are specific paths to GitHub/GitLab/etc projects you can’t necessarily just fork the project and do work in your fork.

Continue reading

The defacto Alerting tool used with Prometheus is Alertmanager. Prometheus sends a notification to Alertmanager whenever a rule is triggered. Alertmanager then takes that notification and sends it to whatever receiver(s) you have defined in your config. It supports quite a few options: email, hipchat, pagerduty, pushover, slack, opsgenie, victorops, webhook, and wechat. For this post I’m focusing on the webhook receiver. First let’s set up our Alert struct: type Alert struct { Receiver string `json:"receiver"` Status string `json:"status"` Alerts []struct { Status string `json:"status"` Labels struct { Alertname string `json:"alertname"` Service string `json:"service"` Severity string `json:"severity"` } `json:"labels"` Annotations struct { Summary string `json:"summary"` } `json:"annotations"` StartsAt string `json:"startsAt"` EndsAt time.

Continue reading

Since Ansible 2.2 you can use binary applications as modules for Ansible. This means you can write modules in languages other than Python. The downside is that the modules aren’t integrated as well as if they were written in Python with Ansiballz. The binary modules only takes the filename as an argument which is a temporary file containing the JSON data of the modules parameters. I took the boilerplate code that Ansible had here and created a small module to generate a random password.

Continue reading

Directory Server using Go

I’ve been spending time learning Go and here’s a small utility I wrote that’s similar to Python’s SimpleHTTPServer. This utility just creates a small HTTP server serving the directory you define: package main import ( "log" "net/http" "os" ) func main() { if len(os.Args) < 2 { log.Fatal("You must enter a path") } path := os.Args[1] http.Handle("/", http.FileServer(http.Dir(path))) http.ListenAndServe(":8000", nil) } Then just do: go build main.go ./serve /etc

Continue reading

Author's picture

John Hooks

I do stuff with Linux.

System Architect