Follow these instructions to write a Go
program.
Create a directory to work in:
workDir=$(mktemp -d --tmpdir mdrip_example_XXXXX)
pushd $workDir
Make a file with an add
function:
cat - <<EOF >add.go
package main
func add(x, y int) (int) { return x + y }
EOF
Write a main program to call it:
cat - <<EOF >main.go
package main
import "fmt"
func main() {
comment this line to avoid compiler error
fmt.Printf("Calling add on 1 and 2 yields %d.\n", add(1, 2))
}
EOF
go mod init myAdder
go mod tidy
echo Dependencies defined.
badecho Enter go build
go build .
Now you can run main:
./myAdder
Copy/paste the above into a shell to build and run your program.
Clean up with this command:
popd
/bin/rm -rf ${workDir}
greeting="Hello world!"