it is fine:
Exported identifiers:
An identifier may be exported to permit access to it from another
package. An identifier is exported if both:
- the first character of the identifier's name is a Unicode upper case
letter (Unicode class "Lu"); and
- the identifier is declared in the
package block or it is a field name or method name. All other
identifiers are not exported.
ref: https://golang.org/ref/spec
and even you can use Getters:
Go doesn't provide automatic support for getters and setters. There's
nothing wrong with providing getters and setters yourself, and it's
often appropriate to do so, but it's neither idiomatic nor necessary
to put Get into the getter's name. If you have a field called owner
(lower case, unexported), the getter method should be called Owner
(upper case, exported), not GetOwner. The use of upper-case names for
export provides the hook to discriminate the field from the method. A
setter function, if needed, will likely be called SetOwner. Both names
read well in practice:
owner := obj.Owner()
if owner != user {
obj.SetOwner(user)
}
ref: https://golang.org/doc/effective_go.html
so if you do not want to export Name
make it lower case, like this working sample codes and use Getter/Setter :
package first
type person struct {
name string
}
var Per = person{
name: "Jack",
}
func (p *person) SetName(name string) {
p.name = name
}
func (p *person) Name() string {
return p.name
}
main.go (with commented output):
package main
import "first"
import "fmt"
func main() {
person := first.Per
fmt.Println(person.Name()) //Jack
person.SetName("Alex")
fmt.Println(person.Name()) //Alex
}
another use cases: