receiverName을 인자로 받음

This commit is contained in:
2023-09-05 13:52:03 +09:00
parent 57464c6cf0
commit 0762d9311b

View File

@ -613,11 +613,13 @@ type HttpApiReceiver struct {
methods map[string]apiFuncType
}
func MakeHttpApiReceiver[T any](receiver *T) HttpApiReceiver {
func MakeHttpApiReceiver[T any](receiver *T, receiverName string) HttpApiReceiver {
methods := make(map[string]apiFuncType)
tp := reflect.TypeOf(receiver)
name := tp.Elem().Name()
if len(receiverName) == 0 {
receiverName = tp.Elem().Name()
}
writerType := reflect.TypeOf((*http.ResponseWriter)(nil)).Elem()
for i := 0; i < tp.NumMethod(); i++ {
method := tp.Method(i)
@ -646,7 +648,7 @@ func MakeHttpApiReceiver[T any](receiver *T) HttpApiReceiver {
p1 := unsafe.Pointer(&funcptr)
p2 := unsafe.Pointer(&p1)
testfunc := (*func(*T, http.ResponseWriter, *http.Request))(p2)
methods[name+"."+method.Name] = func(w http.ResponseWriter, r *http.Request) {
methods[receiverName+"."+method.Name] = func(w http.ResponseWriter, r *http.Request) {
(*testfunc)(receiver, w, r)
}
}