github.com/cloudwego/dynamicgo@v0.2.6-0.20240519101509-707f41b6b834/proto/test_util.go (about)

     1  package proto
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/cloudwego/dynamicgo/internal/util_test"
     8  )
     9  
    10  // GetFnDescFromFile get a fucntion descriptor from idl path (relative to your git root) and
    11  // the function name
    12  func GetFnDescFromFile(filePath, fnName string, opts Options, includeDirs ...string) *MethodDescriptor {
    13  	svc, err := opts.NewDescriptorFromPath(context.Background(), util_test.MustGitPath(filePath), includeDirs...)
    14  	if err != nil {
    15  		panic(fmt.Errorf("%s:%s", util_test.MustGitPath(filePath), err))
    16  	}
    17  	fn := svc.LookupMethodByName(fnName)
    18  	if fn == nil {
    19  		return nil
    20  	}
    21  	return fn
    22  }
    23  
    24  // FnRequest get the normal requestDescriptor
    25  func FnRequest(fn *MethodDescriptor) *TypeDescriptor {
    26  	request := fn.Input()
    27  	if request == nil {
    28  		return nil
    29  	}
    30  	return request
    31  }
    32  
    33  // FnResponse get hte normal responseDescriptor
    34  func FnResponse(fn *MethodDescriptor) *TypeDescriptor {
    35  	response := fn.Output()
    36  	if response == nil {
    37  		return nil
    38  	}
    39  	return response
    40  }