结构属性的动态标识符

A user has a number of id fields - one for each type of social login:

type User struct {
    Name         string
    Github_id    string
    Facebook_id  string
    Google_id    string
}

I have variables that store the provider and id:

provider := "github" //could be facebook or google too
id := "12345"

and a user:

var user User
user.Name = "Bob"

but how can I assign the id to the correct property? I've tried:

if provider == "github" {
    field := "Github_id"
    user.field = id //and also user[field] = id
}

but no success so far.

Additional Note

My users may have multiple social login accounts so I can't just use a single social_id property as a solution to this problem.

Performing reflection on the struct in order to fill-in the correct field seems like overkill, in this case.

I would recommend having a map field in your User struct to hold all of the social IDs. Example:

type User struct {
    Name string
    IDs  map[string]string
}

func NewUser() *User {
   return &User{
       IDs: make(map[string]string),
   }
}

Usage:

provider := "github" // could be facebook or google too
id := "12345"

user := NewUser()
user.Name = "Bob"
user.IDs[provider] = id