I import a struct defined in another package, when try to use it to construct a literal, get a "not a type" error.
In publish.go
type Book struct {
Name string
Author string
Published bool
}
In store.go
import "publish"
func Init() {
var reading publish.Book
b := &reading {
Name: "Learn Go Lang",
Author: "Rob",
Published: true
}
}
Error: reading is not a type
Here you try to make a struct of Type "reading"
b := &reading {
Name: "Learn Go Lang",
Author: "Rob",
Published: true
}
What you want is a struct of type publish.Book
b := & publish.Book {
Name: "Learn Go Lang",
Author: "Rob",
Published: true,
}
plus you also need a comma at the end of the last in a multi-line struct declaration.