go build和go run之间的函数调用差异

I'm new to Golang and I'm trying out a few examples as part of my learning. I have 2 Go source files - hello.go and consts.go in my example. consts.go contains some constants which are used by the functions defined in hello.go. When I build both the source files like so: go build consts.go hello.go and run the output ./hello the function arrayDemo() is not called at all.

However, when I just run the file hello.go using go run hello.go, the function arrayDemo() is called.

What is the difference in both the approaches that's causing the function not to be called when building?

Here's the code for hello.go:

package main

import (
    "fmt"
    "os"
    "strconv"
    "strings"
)

func main() {
    fmt.Printf("Speed is %f
", computeSpeed(54.3, 3.4))
    fmt.Printf("%d
", arrayDemo())
}

func arrayDemo() int32 {
    fmt.Println("in arrayDemo")
    return 5
}

Code for consts.go:

package main

// Speed speed of a vehicle
type Speed float32

func computeSpeed(dist float32, t float32) Speed {
    return Speed(dist / t)
}

go run works because go run works based on file names, but go build works based on package names.

also

go help build says:

When compiling multiple packages or a single non-main package, build compiles the packages but discards the resulting object, serving only as a check that the packages can be built.

to my understanding this means you can not have multiple files in the main package and then get working executable by using go build