github.com/ovechkin-dm/go-dyno@v0.0.23/pkg/dyno/api.go (about)

     1  //go:build go1.18
     2  
     3  package dyno
     4  
     5  import (
     6  	proxy2 "github.com/ovechkin-dm/go-dyno/proxy"
     7  	"reflect"
     8  )
     9  
    10  type Method struct {
    11  	Num          int
    12  	ReflectValue reflect.Value
    13  	Type         reflect.Method
    14  	Name         string
    15  }
    16  
    17  type ProxyHandler interface {
    18  	Handle(m *Method, values []reflect.Value) []reflect.Value
    19  }
    20  
    21  func Dynamic[T any](handler ProxyHandler) (T, error) {
    22  	return proxy2.Create[T](func(m *proxy2.MethodInfo, values []reflect.Value) []reflect.Value {
    23  		method := &Method{
    24  			Num:          m.Num,
    25  			ReflectValue: m.ReflectValue,
    26  			Type:         m.Type,
    27  			Name:         m.Name,
    28  		}
    29  		return handler.Handle(method, values)
    30  	})
    31  }