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