How do packages with multiple files work in golang?


This repo has 3 go files all begin with “package lumber”.
To use this package, I’m supposed to put this in my GOROOT and simply

import lumber

in my program. How do variables and types in this package connect with each other across multiple files? How does the go compiler know which file to begin reading first?

In case I want to read the package, where should I begin reading to understand the package? What exactly is the flow of things here?


No, you’re not “supposed to put this in my GOROOT”. You’re supposed to execute

$ go get

which will clone the repository into $GOPATH/src/ Then you can use the package by importing it in your code as

import ""

About the scoping rules: Declarations and scope

Answered By – zzzz

Answer Checked By – Pedro (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.