Hi guys and thanks in advance for your help! :)
I try to learn Go and wanna ask how I can access a variable defined in a struct in an own class. How do you make your models in go? I really wanna put the models in a own class.
When I do this I cant access the Variables of my struct Student.
package main
import (
"fmt"
"github.com/nikolastankovic/hello/models"
)
func main() {
var nikola models.Student
nikola.name = "nikola" // THIS DOESN'T WORK :(
fmt.Println(nikola)
}
Model Student in subpackage models:
package models
type Student struct {
name string
number int
}
You need to write the attribute name
with a capital letter N
and it will work. Like this:
package models
type Student struct {
Name string
Number int
}
Small letter means unexported (private) in Go and capital letter means exported (public).
Also see: A Tour of Go