Wrote A Go Program That Posts To Mastodon

This morning I had some fun writing a Go program which takes the latest blog post from my RSS feed and posts it to Mastodon. It is based on my twitter cli I wrote a while ago. It was fun to write some Go again, it has been far too long. I’ve been writing mostly Terraform and yaml recently and working a lot with infrastructure. I haven’t been doing any projects at home that required programming. But recently I started up my personal blog and completely re-architected my social media setup. ...

December 24, 2023 Â· Mischa van den Burg

Structs In Go - Similar To Classes In Python?

The Tour of Go is very clear: Go does not have classes. One benefit of learning multiple programming languages is that each language provides you with a set of “pegs” that you can use to refer to other languages. As I learned about structs in Go, I hung them to the “Python classes” peg and used that as a reference point. Using these reference points can help you to understand the object of study by looking at their differences and similarities. ...

April 10, 2023 Â· Mischa van den Burg

Use The %q Verb When Debugging In Go

I’m working on my twitter CLI and as I was writing a function to format the tweet I remembered something I picked up last week. After a quick search in my notes I remembered to use the %q with printf. slice := []string{feed.Items[0].Title, feed.Items[0].Link} result := strings.Join(slice, "\n") fmt.Printf("Testing printf %q", result) This is very useful when formatting output. Now I can actually see whether it is inserting the new line characters correctly: Testing printf "I Made My First Tweet Using My Go Program\nhttps://mischavandenburg.com/zet/go-first-tweet/"I Made My First Tweet Using My Go Program ...

April 9, 2023 Â· Mischa van den Burg

I Made My First Tweet Using My Go Program

I spent the evening learning about the Twitter API. It was not as straight forward as I thought. My goal was to do this project using only the standard library, and I hoped to get away with a few simple curls, but since the API requires OAuth 1 to create tweets, I had to revise my strategy. After struggling with Postman for a few hours to get the correct environment variables set up I managed to make my first tweet through Postman. Turns out that Twitter made some big changes in the free tier of their API, and it took me quite a while to figure out that the functions that are used as examples in the API documentation are not accessible to free accounts anymore. ...

April 8, 2023 Â· Mischa van den Burg

Outlining My First Go Project

When learning a programming language it is important to start building things quickly and to begin applying the theory. I have a tendency to dive into the books and lose myself in the theory, where I should be getting hands on experience. Over the past few months I’ve generated a bunch of ideas for projects that I want to write, and I selected my first project today. https://github.com/mischavandenburg/twitter-cli https://twitter.com/mischa_vdburg Twitter CLI Programs should solve a problem. My problem has to do with Twitter. I recently created a Twitter account, and I want to make a tweet whenever I publish something new on my website. I’m currently doing this by hand, and that needs to stop, obviously. ...

April 8, 2023 Â· Mischa van den Burg

I Wrote My First Go Program Today

I’m still at the beginning of my Go learning journey, but I worked through a few tutorials and guides by now. I’ve gathered lots of ideas for programs that I want to write, big and small, but I have to start somewhere. The best thing to do is to write little programs that solve a problem that you have. One problem I needed to solve was converting sentences to title case in vim. There are plugins for this, or elaborate macros, but I thought this was a nice opportunity to write my first program from scratch. You can view the program here: my go repo. ...

March 28, 2023 Â· Mischa van den Burg

Go - Reading from Standard Input Provided by User

I’m working through the “greet” challenge by rwxrob. It is amazing how such a relatively simple and small challenge can lead down to so many rabbit holes. The program should take input from the user and print it out. I worked through the challenge together with Rob in his video but I’m going to talk (write) myself through these functions to fully understand what’s going on. We have the following function in main.go: ...

March 26, 2023 Â· Mischa van den Burg

Go - Skillstak Beginner Boost Week 17 and 18 Notes

Beginner Boost Week 17 and 18 Notes Link to video Don’t forget to set GOBIN=~/.local/bin, GOPRIVATE, CGO_ENABLED=0 Go Testing - Example Tests func ExampleFoo() { foo() // Output: // Foo } The ExampleFoo indicates the test here. It needs to match the name exactly after Example. But it is capitalized. It runs that function and will compare the output to what is specified. It says “see if the program generates this output in std out”. ...

March 26, 2023 Â· Mischa van den Burg

What is the difference between a Go module and a package?

A module is generally associated with a single git repo. You can have a module with multiple packages, and each package would get its own subdirectory. You should always name your main file main.go creating a module Use the go mod init {{your path here}} command to initiate a module. multiple modules I was running into some trouble with this because I want to have one big repo where I will store all my go projects. ...

March 20, 2023 Â· Mischa van den Burg

How to continuously run a Go file while coding in the terminal

I do all my coding and note taking in the terminal using tmux and neovim. I picked up a nice trick from Rob Muhlenstein today. You can use this command in a split window to keep running a Go file. It will update when you save the file. entr -c bash -c "go run main.go" <<< main.go Entr runs commands when files change. Here we are feeding it only one file, but you can also feed it a directory like so: ...

March 19, 2023 Â· Mischa van den Burg