Go noob, I cannot seem to figure out how to structure my project with packages. What I want is this:
dart.go
package main
import (
...
)
func main () {
...
// call functions declared in functions.go
...
}
functions.go
package dart
import (
...
)
func Function1() {
...
}
func Function2() {
...
}
A package is a file or a group of files with a namespace and some code or related code. This means that a package could live in a file such as math.go or across multiple files such as add.go , subctract.go , multiply.go , this would many files or the singular file will be namespaced as package math for example.
If you are trying to run multiple files on localhost using gorilla mux in go as per latest version(1.11). Try using any of the following 2 commands. go install && FolderName -port 8081 . go build && ./FolderName -port 8081.
In Go, a package is a directory of .go files, and packages form the basic building blocks of a Go program. Using packages, you organize your code into reusable units. A module, on the other hand, is a collection of Go packages, with dependencies and versioning built-in.
if all you want to do is access functions in a different file, have functions.go also start with package main
instead of package dart
. That way, you are working within a single package but with your code divided into multiple files. Make sure they're in the same directory so that they're considered in the same package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With