After reading https://golang.org/doc/code.html, and having a look at a few StackOverflow questions on the topic, I still can't build a program with several files in it.
My GOPATH is: C:/go_dev/
, and my directory structure is:
go_dev/
src/
github.com/
aurelienCastel/
crashTest/
main.go
parser/
parser.go
main.go:
package main
import "github.com/aurelienCastel/crashTest/parser"
func main() {
info := parser.get_info_from("file.go")
// ...
}
parser/parser.go:
package parser
// ...
func get_info_from(file_name string) Info {
// ...
}
When I run go install
in the crashTest
directory I get the following error:
undefined: parser.get_info_from
I know this is a recurrent question, but could someone tell me what I am doing wrong?
In order for an identifier to be accessible from an outside package, its name must begin with an uppercase letter. From the spec:
Exported identifiers
An identifier may be exported to permit access to it from another package. An identifier is exported if both:
- the first character of the identifier's name is a Unicode upper case letter (Unicode class "Lu"); and
- the identifier is declared in the package block or it is a field name or method name.
All other identifiers are not exported.
Additionally, it is Go convention to name identifiers using mixed case, rather than snake case.
package parser
// ...
func GetInfoFrom(filename string) Info {
// ...
}