Technical requirements

  • Have the error
  • *cry in golang*
  • Be motivated to fix it and Go forward

And so it started

Today I wanted to try out a hot reloading tool Air and noticed that it didn’t work out of the box and was constantly returning this error:

error obtaining VCS status: directory "DIR_PATH" is not using a known version control system
        Use -buildvcs=false to disable VCS stamping.
failed to build, error: exit status 1

This was very unusual for me as the project was in a sub directory of a git repo hosted in GitLab. My first idea and most basic solution was to create a git repo in the project sub-directory(which might not be a very good idea for monorepos):

git init
git add .
git commit -m "Debug Commit"
air . 
# And the error was there again silently looking at me right after the New Years.
# I've felt it looking at me while I was desperately trying to reload my super awesome hello-world rest api.

Unfortunately at the time of writing I didn’t find any good solutions as I brute-forced through some of the listed ones in any related projects located at GitHub, StackOverflow or GitLab.

My Solution

After some research, brute-force attempts and reading I managed to fix the issue by initializing the Go Module in the repo with:

go mod init gitlab.com/m0sh1x2/demos/golang/postgres_gorm
go mod tidy

And surprise it just worked out of the box:

❯ air

  __    _   ___  
 / /\  | | | |_) 
/_/--\ |_| |_| \_ 1.27.8, built with Go 1.17.3

watching .
!exclude tmp
building...
running...
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /v1/list/                 --> main.GetLogs (3 handlers)
[GIN-debug] POST   /v1/crawl/                --> main.CrawlAndLog (3 handlers)
[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details.
[GIN-debug] Listening and serving HTTP on :8081

After that I decided to make a coffee and stay up for 2 days writing code and infrastructure(as code of course, you build your infra on hand - are you mad?).

Thanks for reading and happy holidays!