bubusi
bubusi2mo ago

# Go Script Package Conflict Error

Getting consistent build errors when trying to run any Go script in Windmill:
exit code for "go build": 1
main.go:7:5: found packages main (inner_main.go) and inner (runner.go) in /tmp/windmill/.../go/inner
main.go:7:5: import "mymod/inner" is a program, not an importable package
exit code for "go build": 1
main.go:7:5: found packages main (inner_main.go) and inner (runner.go) in /tmp/windmill/.../go/inner
main.go:7:5: import "mymod/inner" is a program, not an importable package
What I've tried: - package main with func main() - package inner with func Main() - No package declaration - // +build ignore directive - Even simplest scripts fail Example script:
package main

import "fmt"

func main(name string) (string, error) {
return fmt.Sprintf("Hello, %s!", name), nil
}
package main

import "fmt"

func main(name string) (string, error) {
return fmt.Sprintf("Hello, %s!", name), nil
}
Questions: 1. What's the correct package/function signature for Go in Windmill? 2. How should dependencies be declared? 3. Any working Go script examples? The error mentions inner_main.go and runner.go - are these Windmill-generated? How should my script interact with them? Context: Trying to migrate performance-critical DB connectors from TS to Go. TypeScript/Python work fine, only Go has issues. Thanks!
7 Replies
Pyra
Pyra2mo ago
Hello this works:
- package main
+ package inner

import "fmt"

func main(name string) (string, error) {
return fmt.Sprintf("Hello, %s!", name), nil
}
- package main
+ package inner

import "fmt"

func main(name string) (string, error) {
return fmt.Sprintf("Hello, %s!", name), nil
}
bubusi
bubusiOP2mo ago
Thanks but I keep on getting the error: ExecutionErr: exit code for "go build": 1, last log lines: job=0197ad0c-a11a-82e2-dc4c-1718aee48506 tag=go worker=wk-default-x98kj-dGNof hostname=windmill-workers-default-647755dcd8-x98kj --- GO DEPENDENCIES SETUP --- go: no module dependencies to download main.go:7:5: found packages main (inner_main.go) and inner (runner.go) in /tmp/windmill/wk-default-x98kj-dGNof/0197ad0c-a11a-82e2-dc4c-1718aee48506/go/inner main.go:7:5: import "mymod/inner" is a program, not an importable package
Pyra
Pyra2mo ago
Can you provide the script that fails @bubusi ? The snippet I provided seems to be fully functional. (I tested on cloud)
bubusi
bubusiOP2mo ago
Sure. Many thanks for looking into it
Pyra
Pyra2mo ago
I cannot reproduce the error with this script. Can you verify this works:
package inner

import "fmt"

func main(name string) (string, error) {
return fmt.Sprintf("Hello, %s!", name), nil
}
package inner

import "fmt"

func main(name string) (string, error) {
return fmt.Sprintf("Hello, %s!", name), nil
}
^^^ should work. What is the versions you are running?
bubusi
bubusiOP2mo ago
Progress! The error is now just an unused variable. However, discovered major limitation: Windmill Go requires ALL code in single main() function - no helper functions allowed. This makes complex scripts unmaintainable. Thanks for your help!
Pyra
Pyra2mo ago
This seems to work @bubusi
package inner

func main(x string) (string, error) {
// v, _ := wmill.GetVariable("f/examples/secret")
return helper()
}

func helper () (string, error) {
return "hey", nil
}
package inner

func main(x string) (string, error) {
// v, _ := wmill.GetVariable("f/examples/secret")
return helper()
}

func helper () (string, error) {
return "hey", nil
}

Did you find this page helpful?