github.com/status-im/status-go@v1.1.0/node/rpc.go (about)

     1  package node
     2  
     3  import (
     4  	"reflect"
     5  	"unicode"
     6  )
     7  
     8  // firstCharToLower converts to first character of name to lowercase.
     9  func firstCharToLower(name string) string {
    10  	ret := []rune(name)
    11  	if len(ret) > 0 {
    12  		ret[0] = unicode.ToLower(ret[0])
    13  	}
    14  	return string(ret)
    15  }
    16  
    17  // addSuitableCallbacks iterates over the methods of the given type and adds them to
    18  // the methods list
    19  // This is taken from go-ethereum services
    20  func addSuitableCallbacks(receiver reflect.Value, namespace string, methods map[string]bool) {
    21  	typ := receiver.Type()
    22  	for m := 0; m < typ.NumMethod(); m++ {
    23  		method := typ.Method(m)
    24  		if method.PkgPath != "" {
    25  			continue // method not exported
    26  		}
    27  		name := firstCharToLower(method.Name)
    28  		methods[namespace+"_"+name] = true
    29  	}
    30  }