receiverName을 인자로 받음
This commit is contained in:
@ -613,11 +613,13 @@ type HttpApiReceiver struct {
|
|||||||
methods map[string]apiFuncType
|
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)
|
methods := make(map[string]apiFuncType)
|
||||||
|
|
||||||
tp := reflect.TypeOf(receiver)
|
tp := reflect.TypeOf(receiver)
|
||||||
name := tp.Elem().Name()
|
if len(receiverName) == 0 {
|
||||||
|
receiverName = tp.Elem().Name()
|
||||||
|
}
|
||||||
writerType := reflect.TypeOf((*http.ResponseWriter)(nil)).Elem()
|
writerType := reflect.TypeOf((*http.ResponseWriter)(nil)).Elem()
|
||||||
for i := 0; i < tp.NumMethod(); i++ {
|
for i := 0; i < tp.NumMethod(); i++ {
|
||||||
method := tp.Method(i)
|
method := tp.Method(i)
|
||||||
@ -646,7 +648,7 @@ func MakeHttpApiReceiver[T any](receiver *T) HttpApiReceiver {
|
|||||||
p1 := unsafe.Pointer(&funcptr)
|
p1 := unsafe.Pointer(&funcptr)
|
||||||
p2 := unsafe.Pointer(&p1)
|
p2 := unsafe.Pointer(&p1)
|
||||||
testfunc := (*func(*T, http.ResponseWriter, *http.Request))(p2)
|
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)
|
(*testfunc)(receiver, w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user