I’m writing my first serious Go application and running into what must be a very silly issue.
I have a file: “engine.go” which is package main and does 80% of what I need. But it is a little disorganized and littered with functions and would benefit from being split into different files.
Thanks.
To be honest I’m getting nowhere fast though. I’ve stripped things right back to a super simple example of what I want to do then once I understand that properly I will revisit the func library in my main project.
Here is the scenario for the super simple example.
I have, in a folder named “gotest”, the following files:-
test.go and libs.go
test.go is:
package main
import (
"fmt"
)
func main() {
fmt.Println("This is a message from main.go")
SaySomething()
}
libs.go is:
package main
import (
"fmt"
)
// FATAL: Just a token fatal message
func SaySomething() {
fmt.Println("This is from the lib!!")
}
Yet, when I try to run test.go all I get is:
>go run test.go
# command-line-arguments
.\test.go:11: undefined: SaySomething
>
Forgive me, but I had thought that if both files were in the main package then this should work okay without the need to import anything else?
Much appreciated. Till now I have avoided placing any of my Go code into the src directory. It sounds like I just need to get over it and start using that path for my projects.
My application is going to be called “guess” and will need to work with several different types of data including json, connection strings, results paths and other items.
So I made a folder called guess in the root of C: and it looks like this:
The folders are filled with datasources that the tool needs to run properly. Its basically an industrial sized query poster which collects lots of responses from loads of different services and endpoints and collates all the results according to how the user has configured their instructions.json in the instructions folder.
I wanted to run engine.go and call functions that are located in the funcslib.go file. And that does work just fine since my “'D’oh” moment about how I was calling ‘go run’ and ‘go build’. Since learning that I have to reference both files, it works just great.