Ramzi A.
Posted on March 6, 2023
Over the years I have dealt with different ways to setup a project for Python & Go. I am sharing how I setup my personal and work projects for extensibility and modularity.
There are a lot of ways to setup Python dev environments and Go but this is what works best for me and how I get higher adoption at work for my projects. (This can be extended for any language btw Node or Rust even).
I will write up how I setup Go projects in this post & then follow up with a Python version which adopts a lot the same concepts.
Assumptions:
- You have homebrew homebrew install
- You are using MacOS or Linux.
Step 1: Pre-reqs:
- asdf: Installing asdf this is how you can manage different versions of languages and use them across projects ~~2. Installing Poetry (for Python only) is a way to manage dependencies & virtual environments in Python. This was shown to me by Data Scientist at work and I would never go back using any other method. ~~ this will be relevant for the Python blog post
Step 1: Setup for both install asdf & add to your shell (I use zsh, so adjust if you use bash or something else).
brew install asdf
echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ~/.zsh_profile
Step 2: Go Setup
In asdf the order of operations is adding a 1. language plugin, 2. adding a version(s) and 3.then setting the language locally or globally for your projects
Setup Langauge Plugin
- Setting up asdf for go run
asdf plugin add golang
- adding different go versions if you want the latest run
asdf install golang latest
- OR install a specific version running
asdf install golang 1.19
Setup Local & Global Version
In this case I have a hello-go directory that i want to use Go 1.19 in order to do that you would run
-
asdf local golang 1.19
Init a baseline project.
Get the current directory and init a go project
- run
pwd
which will output the directory/Users/ramzi/documents/projects/hello-go
in my case. - run
go mod init documents/projects/hello-go
Closing Thoughts
The purpose of this is when you need to have multiple version of a language across different projects and you want to keep this binaries separate. With asdf you can set a global version (which I do not recommend) but to do so you will run asdf global golang 1.19
for example.
This is especially important as a Python developer which I will share in an upcoming blog post.
Posted on March 6, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.