TIL: How to Debug a Test in Golang With Build Tags in Neovim

TIL: How to Debug a Test in Golang With Build Tags in Neovim I was having issues with my debugger today (well technically yesterday because I am publishing this a day later to spread out my blog posts but same difference) and it took me a few hours to realise what was going on. In my case, I was trying to debug a test written in Golang using nvim-dap-go on Neovim. ...

TIL: How to Disable Linters in Golangci Lint for Test Files

TIL: How to Disable Linters in Golangci Lint for Test Files Today (for once), I ran golangci-lint run and it failed on CI with the following error: internal/options/parser_test.go:13: Function 'TestParse' is too long (69 > 60) (funlen) func TestParse(t *testing.T) { task: Failed to run task "lint": exit status 1 Where my .golangci.yml file looked like this: run: timeout: 5m skip-dirs: - direnv linters: enable: - bodyclose - dogsled - dupl - errcheck - exportloopref - funlen - gochecknoinits - goconst - gocritic - gocyclo - gofmt - goimports - gomnd - goprintffuncname - gosec - gosimple - govet - ineffassign - lll - misspell - nakedret - noctx - nolintlint - revive - staticcheck - stylecheck - typecheck - unconvert - unparam - unused - whitespace So basically we want the ability to turn off funlen for our tests (and other linters). ...

How to Use Neotest Dap With Lazyvim for Golang Development

In this blog post, I will show you how you can easily setup Neotest to make testing easier in neovim and DAP to make debugging your tests is a lot easier. I am using the LazyVim neovim distribution, where these two come as easily installed extra plugins. However, it should be easy enough for you to copy the config over to your neovim lua config. LazyVim even has the config available on its website, you don’t even need to deep dive into the code 😄. ...

TIL: How to Set a Relationship on Golang Pocketbase

TIL: How to Set a Relationship on Golang Pocketbase Pocketbase is a backend as a service, it is very nice because it is written in Golang it can compile down to a single binary. It also allows us to extend it using Golang and use it as a framework. In my case, I needed some extra logic before adding data to the database so I decided to extend Pocketbase and write some of my business logic. ...

TIL: How To Add Custom Syntax Highlighting Rules in VS Code

TIL: How To Add Custom Syntax Highlighting Rules in VS Code The other day (a few months ago) I was comparing Goland and VS Code for Golang development. I noticed Goland by default seemed to have nicer syntax highlighting, so I started looking at what I could do in VS Code to do this. Before After It turns out we can do this with our own custom rules using editor.tokenColorCustomizations. To do this go to our settings (settings. ...

TIL: How to Use Prettier with Hugo/Golang Templates

TIL: How to Use Prettier with Hugo/Golang Templates If you try to use prettier on a (Hugo) Golang HTML template you may get something that looks like this: {{- if or .Params.author site.Params.author }} {{- $author := (.Params.author | default site.Params.author) }} {{- $author_type := (printf "%T" $author) }} {{- if (or (eq $author_type "[]string") (eq $author_type "[]interface {}")) }} {{- (delimit $author ", " ) }} {{- else }} {{- $author }} {{- end }} {{- end -}} into this ...

TIL: How to Separate our Golang Tests

TIL: How to Separate our Golang Tests Sometimes we want to be able to run our unit tests and integration tests separately. In Golang we can do this using build tags, build tags are used to tell the compiler important information when we run go build 1. Let say we have a file called package_test.go. By adding // +build integration to the top of the file without any whitespace. This test file will only be run when we specify the tags in our test command go test --tags=integration. ...

How to create a Golang Web Application using Fizz

Background A bit of background before we start the article. When I develop a Python web service I use the Connexion library created by Zalando. It’s a great library which is built on top of Flask. It uses an OpenAPI Specification (OAS) file to handle input validation and routing for you. Therefore reducing the boilerplate code you need to write. The main advantage of this is that we have a design-first approach to developing our API. ...

Golang & MongoDB with "Polymorphism" and BSON Unmarshal

Recently I’ve been working on a new personal project called Banter Bus, a browser-based multiplayer game. I’ve been working on a REST API to add new questions to the game. The API is built in Golang and uses MongoDB as the database. Since Golang is a strongly typed language, we will need to specify the structure of the data we expect from the database. This can get tricky if the data varies, such as one field changing. ...