Answer the question
In order to leave comments, you need to log in
What is the correct way to store different types in one structure field?
There are User, Subscriber and Admin structures
type Admin struct {
Permissions map[string]interface{}
}
type Subscriber struct {
Online bool
Status string
SubscriptedTo []int
}
type User struct {
ID int
Login string
Role string // "subscriber"/"admin"
RoleModel ??? // здесь должен быть Admin{} или Subscriber{}
}
Answer the question
In order to leave comments, you need to log in
I think you're upside down... Maybe so?
type Admin struct {
Permissions map[string]interface{}
User
}
type Subscriber struct {
Online bool
Status string
SubscriptedTo []int
User
}
type User struct {
ID int
Login string
}
You can use typed constants to enumerate a type.
const (
NewUserType userType = "NEW"
AdminType userType = "ADMIN"
)
type User struct {
ID int
Login string
Type userType
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question