Our today coding kata is a website heartbeat system.
It checks the correct
<title> for a bunch of domains.
If a site is down, or the title is wrong, it should send a email.
Of course it will do the job in parallel.
I’ll try it with Elixir and Go for fun and learning - and to have a bit of monitoring my sites.
Code on GitHub: ronnyhartenstein/site-heartbeat-elixir
- build mix targets using
- prepare stuff for escript (
cli.ex) and use it for one-file-deployment (
- read a text (the domains and titles) file as a stream with
- parallel processing with
- fetch sites body with
- tried to send mails with
- try hard to do it the functional way!
Code on GitHub: ronnyhartenstein/site-heartbeat-golang
- read a plain text file (the domains and titles) with
- use goroutines for parallel processing and sync it with
- fetch and parse sites body with goquery - a jQuery like lib
- use regexp to check the
- read a JSON config (the mailer config) as a Go struct with
- send a mail TLS secured with
- for program organisation it is a good practise to split it into some files, but each is in package “main”
- cross compile for linux from a mac via
env GOOS=linux GOARCH=386 go build github.com/ronnyhartenstein/site-heartbeat-golang
- try hard to do it the pragmatic getting-stuff-done-way
This kata was quite a lot of fun! I’m surprised how many diffent things I could touch on this small use case. Working with files, parsing configs, query websites, parsing body, sending mails, dealing with errors.