如果您尝试获取字符串“Female”和“VIP”


var genders = map[uint8]string{

    2: "Male",

    5: "Female",

}


var memberTypes = map[uint8]string{

    2: "Standard",

    5: "VIP",

}

或者:


var genders = map[Gender]string{

    Male: "Male",

    Female: "Female",

}


var memberTypes = map[MemberType]string{

    Standard: "Standard",

    VIP: "VIP",

}

然后你会有类似的东西


 id := 5

 fmt.Println(genders[id]) // "Female"

 fmt.Println(memberTypes[id]) // "VIP"

 // or...

 fmt.Println(genders[Gender(id)]) // "Female"

 fmt.Println(memberTypes[MemberType(id)]) // "VIP"