T
T
to_east2018-03-20 00:19:09
go
to_east, 2018-03-20 00:19:09

Structure field not found, connected package?

Greetings Toaster Members!
The code:

// ~/go/src/example/foobar/foobar.go
package foobar


// ...

type FooBar struct {
    table map[string]*Relation
}

func NewFooBar() *FooBar {
    fb := new(FooBar)
    fb.table = make(map[string]*Relation)
    return fb
}

// ------------------------ //

// ~/go/src/example/main.go
package main


import (
    "fmt"
    "example/foobar"
)


func main() {
    fb := foobar.NewFooBar()
    fmt.Println(fb.table)
}

The compiler complains about the undefined fb.table field in the main function. I'll assume in advance that we probably need to add a getter action over the FooBar structure, which returns a pointer to fb.table.
Requesting support from the gophers, check my assumptions

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
uvelichitel, 2018-03-20
@to_east

Go exports capitalized names, small private https://golang.org/ref/spec#Exported_identifiers

type FooBar struct {
    Table map[string]*Relation   // здесь нужно Table вместо table чтобы имя/поле можно было импортировать 
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question