I'm doing a simple exercise in Go, which is comprised of 2 files:
A main.go file that runs the program
A deck.go file that holds a custom type deck, and a function called print() to be called from main.
So far, nothing unseen in other programming languages.
main.go:
func main(){
variable := deck{"element1", "element2"} // if correctly imported, `deck` is a mnemonic type alias for `[]string`
cards.print()
}
deck.go:
import "fmt"
type deck []string // now 'deck' is a type alias for `[]string`
func (x deck) string {
for i, card := range d { // for index and element ’card’ in all indexes in slice ‘cards’, print index and element
fmt.Println(i, card)
}
|
However, when hitting M-return x x to invoke go-run-main, I get an error message:
# command line arguments
./main.go:8:11: undefined: deck
This may happen because go-run-main is running go run main.go, without additional files.
Thing is, for a correct output, what should be run is go run main.go deck.go, as apparently VSCode does, since the latter shows the expected output: a printout of elements via the mentioned print() function above.
My question is: how can the go-run-main be customized, so that additional files can be added (or detected) as parameters?
I'm doing a simple exercise in Go, which is comprised of 2 files:
main.go
file that runs the programdeck.go
file that holds a custom typedeck
, and a function calledprint()
to be called frommain
.So far, nothing unseen in other programming languages.
main.go
:deck.go
:|
However, when hitting
M-return x x
to invokego-run-main
, I get an error message:This may happen because
go-run-main
is runninggo run main.go
, without additional files. Thing is, for a correct output, what should be run isgo run main.go deck.go
, as apparently VSCode does, since the latter shows the expected output: a printout of elements via the mentionedprint()
function above.My question is: how can the
go-run-main
be customized, so that additional files can be added (or detected) as parameters?