How to run golang program after encapsulating the app under mac

Hello everyone. I want to encapsulate the golang program into an app under mac (create the app directory structure manually), but it cannot run normally after clicking the app. The record in the mac system log is:

I tested it by writing a file, and the code is as follows:

func check(e error) { if e != nil { panic(e) } }

func main() {
index := 0   
f, err := os.Create("testdat.txt")
defer f.Close()   

for  {
    index += 1
    n3, err := f.WriteString("test app: ")
    t := strconv.Itoa(index)
    n3, err = f.WriteString(t)
    n3, err = f.WriteString("times \n")
    fmt.Printf("wrote %d bytes\n", n3)

    time.Sleep(1 * time.Second)

Excuse me, what is the cause of the problem after packaging the app? How to fix it? thanks.

I found the reason, because the file “testdat.txt” should use the full path.

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