Same package calling another func in main

I have package udamy
under udamy i have to two source files
-------------main.go------------------
package main
import “fmt”
func main(){
fmt.println(“main”)
ss() //calling ss() function
}
---------hey.go--------------------------
package main
import “fmt”
func ss(){
fmt.println(“ss”)
ss() //calling ss() function
}

Both are in the same package but if try to call ss func from main func its showing undfined

Are you sure you want to call ss() from inside ss()? This will result in an infinite recursion.

After the recursion is removed, your code works fine. I’ve put both files into a directory named forum.

// hey.go
package main

import "fmt"

func ss() {
    fmt.Println("ss")
}
// main.go
package main

import "fmt"

func main() {
    fmt.Println("main")
    ss() //calling ss() function
}
$ go build
$ ./forum
main
ss

----------------print.go------------------------
package main

import “fmt”

func ss(){
fmt.Println(“heloo…”)
}

still showing same

You try to run a single file main.go but you have a package. To run the package, do

$ go run .

inside the package directory.

See the documentation of the go run command for details.

Note: Please don’t post screenshots of code or command line output. Please also use the </> button at the top of the edit window on code snippets. This will render your code in a readable way.

Okay Thank you…go run . worked for me

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.