Documentation ¶
Overview ¶
Package reflect provides a simple reflection on the grpc server.
Index ¶
- Constants
- func IsNil(v interface{}) bool
- func IsPtr(v interface{}) bool
- func IsSlice(v interface{}) bool
- func New(v interface{}) interface{}
- func NewSlicePtr(value interface{}) interface{}
- func NewValue(value interface{}) interface{}
- func NewZero(v interface{}) interface{}
- func ParseRegisterFunc(v interface{}) (grpc.ServiceDesc, interface{})
- func PtrValue(v interface{}) interface{}
- func SetPtrValue(ptr interface{}, v interface{})
- func UnwrapPtrSliceType(v interface{}) (reflect.Type, error)
- func UnwrapType(v interface{}) reflect.Type
- func UnwrapValue(v interface{}) reflect.Value
- type ServiceMethod
Constants ¶
const ( // ErrPtrIsNil indicates that the pointer is nil. ErrPtrIsNil err = "ptr is nil" // ErrIsNotPtr indicates that the given value is not a pointer. ErrIsNotPtr err = "not a pointer" // ErrIsNotSlice indicates that the given value is not a slice. ErrIsNotSlice err = "not a slice" // ErrIsNotFunc indicates that the given value is not a function. ErrIsNotFunc err = "not a function" // ErrIsNotRegisterFunc indicates that the given value is not a register function. ErrIsNotRegisterFunc err = "not a register function" // ErrIsNotSameType indicates that the type of the given values are not the same. ErrIsNotSameType err = "not same type" // ErrCouldNotReadServiceDesc indicates that reflect could not read the service description. ErrCouldNotReadServiceDesc = "could not read service description" )
Variables ¶
This section is empty.
Functions ¶
func IsNil ¶ added in v0.7.0
func IsNil(v interface{}) bool
IsNil checks whether the given value is nil.
func IsPtr ¶ added in v0.8.0
func IsPtr(v interface{}) bool
IsPtr checks whether the input is a pointer and not nil.
func IsSlice ¶ added in v0.2.1
func IsSlice(v interface{}) bool
IsSlice checks whether the input is a slice.
func New ¶
func New(v interface{}) interface{}
New creates a pointer to a new object of a given type.
func NewSlicePtr ¶ added in v0.9.0
func NewSlicePtr(value interface{}) interface{}
NewSlicePtr creates a pointer to a slice of the pointer of the unwrapped value.
func NewValue ¶ added in v0.3.0
func NewValue(value interface{}) interface{}
NewValue creates a pointer to the unwrapped value.
func NewZero ¶
func NewZero(v interface{}) interface{}
NewZero creates a pointer to a nil object of a given type.
func ParseRegisterFunc ¶ added in v0.4.0
func ParseRegisterFunc(v interface{}) (grpc.ServiceDesc, interface{})
ParseRegisterFunc parses te register function and returns the service description and the interface of the server.
func PtrValue ¶
func PtrValue(v interface{}) interface{}
PtrValue ensures the value is a pointer. If it is not, a new pointer to the value is returned.
func SetPtrValue ¶
func SetPtrValue(ptr interface{}, v interface{})
SetPtrValue sets value for a pointer.
func UnwrapPtrSliceType ¶ added in v0.7.0
UnwrapPtrSliceType checks whether the given value is a pointer of a slice and return the type.
func UnwrapType ¶
UnwrapType returns a reflect.Type of the given input. If the type is a pointer, UnwrapType will return the underlay type.
func UnwrapValue ¶
UnwrapValue returns a reflect.Value of the given input. If the value is a pointer, UnwrapValue will return the underlay value.
Types ¶
type ServiceMethod ¶ added in v0.4.0
type ServiceMethod struct { Name string Input interface{} Output interface{} IsClientStream bool IsServerStream bool }
ServiceMethod provides all information about a service method.
func FindServiceMethods ¶ added in v0.4.0
func FindServiceMethods(svc interface{}) []ServiceMethod
FindServiceMethods finds all the service methods using reflection on the server.
reflect.FindServiceMethods((*grpctest.ItemServiceServer)(nil))