0

Say I have got code for a project spread across multiple files. Is there any other way to reference such code within files in the project without going through the whole build and install process? For example within a single project, I might have an implementation of a type Foo in file A and I might want to use such type in file B within the same project. Is there anyway to go about doing that

1
  • can you add some code to explain your situation more clearly Commented Dec 15, 2012 at 13:10

1 Answer 1

3

It's not clear to me what exactly you're asking about, but this part of the language specs about "Declarations and scope" might be related and/or helpful. Another, more prosaic source of related information might probably be "How to Write Go Code".

EDIT - Expanding on now expanded question:

If "package a" declares type Foo - then, b/c Foo starts with an upper case letter - Foo is exported by a. Then in "package b" one would write import "a" and can then refer to that type as a.Foo inside "package b".

Sign up to request clarification or add additional context in comments.

3 Comments

Thats not exactly my problem. I am referring to a situation where you have two files within the same project or package and one is using say a type declared within the other
That's the package scope case from the first link above, i.e. any top level declaration is visible through the whole package == all of the package files.
just to put it another way, if file a and file b are in the same directory with the same package name, and type Foo is in file a, then you implicitly have access to Foo in file b. Nothing else is needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.