go - golang struct from other package -


super golang noob here.

this project structure

root     parser        parser.go     builtin         exit.go         hi.go     structs         base_structs.go     main.go 

my base_structs.go file looks like

package structs  type built_in_func func([] string)  type built_in struct {     s string     f built_in_func } 

then in main.go have imported package , i'm referencing struct structs.built_in_func.

this i'm trying do:

var builtin_list [] structs.built_in  builtin_list = append(builtin_list, structs.built_in{s:"exit", f:builtin.exit}) builtin_list = append(builtin_list, structs.built_in{s:"hi", f:builtin.hi}) 

but i'm getting error: unknown structs.built_in field 's' in struct literal

once again, i'm super golang noob. helps :)

in go, visibility of name outside package determined whether first character upper case.

so field s not visible outside package structs , error.

if define struct (note upper case):

type built_in struct {     s string     f built_in_func } 

then work (again upper case):

structs.built_in{s:"exit", f:builtin.exit} 

you can read more here:

https://golang.org/doc/effective_go.html#names


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -