主golang中的自定义包[关闭]

Package main no look my package.

Struct project:

struct

Sunrise.go have name package sunrise

Sunrise.go have function;

func getSunriseConst() [64]struct {
    x float64
    y float64
    z float64
} {
    return sunrise
}

I want call function in main.go, but main no view my package. Help guys

in order to export functions in packages you need change the name to start with uppercase, so rename the function to GetSunriseConst in your main should be something like

import "sunrise"

...

sunrise.GetSunriseConst()

Make your function start with an upper-case letter.

For example, in root package you have main.go with "func main" and you have package "custom" in this root with custom.go and with func hello(){}.

If you want to use this function in your main.go you need to import it as "import "./custom"" and change function name on Hello(){}, then you can use your function as custom.Hello().