package main
import (
"fmt"
"reflect"
)
type Student struct {
Id string
Name string
Age int
Score float64
}
func (this Student) Rank() string {
if this.Score >= 8 {
return "A"
} else if this.Score >= 7 {
return "B"
} else if this.Score >= 6 {
return "C"
} else if this.Score >= 5 {
return "D"
} else {
return "E"
}
}
func main() {
student := Student{
Id: "st01",
Name: "Name 1",
Age: 20,
Score: 5.6,
}
values := reflect.ValueOf(&student).MethodByName("Rank").Call([]reflect.Value{})
fmt.Println(values[0].String())
}
D