Packages in golang

So you have a directory that looks like this:

hashing/main.go (File starts with package main)

hashing/modulus/modulus.go (File starts with package modulus)

Then while you are in hashing/ you do go build. This will create a binary called hashing which you can execute with ./hashing.

Is the above correct?

Which operating system are you using by the way?

I do not understand what do you mean by modulus.go running. If modulus.go starts with package modulus then it cannot run because it is a package. Packages get used by other code that can run (like main). So in your main.go somewhere you would have a function call like modulus.FunctionName() so that main can use your modulus package.

Notice that you cannot have 2 different packages in the same folder.

2 Likes