Why I cannot access a field in a returned struct?

This is a very stupid question, but I cannot get my head around it.

I am trying to use an old package for a very simple task.
The package in question is bitbucket.org/proteinspector/ms/unthermo

All I need to do is to use unthermo.Open to read a specific file and get some info out of it.
Now, when I look at the source code of unthermo I can see that Open is implemented as:

func Open(fn string) (file File, err error) {
	f, err := os.Open(fn)
// more stuff...

//the info I need for now
	scanindex := make(ScanIndex, nScans)
	readBetween(f, rh.ScanindexAddr, rh.ScantrailerAddr, ver, scanindex)
// more stuff...
	return File{f: f, scanevents: scanevents, scanindex: scanindex}, err

however in my application I cannot access the field scanindex

func main() {
//open file
	file, _ := unthermo.Open("somefile")
	defer file.Close()
//this does not compile
	info := file.scanindex


Ho @Pisistrato
The names of the public fields should start with upper case letter.

An identifier starting with an Unicode upper case letter is called an exported identifier. The word exported can be interpreted as public in many other languages. The identifiers which don’t start with an Unicode upper case letter are called non-exported identifiers. The word non-exported can be interpreted as private in many other languages.


Ok, I always thought that if the struct its public, also its field will be. Learning something new everyday :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.