suitableCallbacks iterates over the methods of the given type. It will determine if a method satisfies the criteria for a RPC callback or a subscription callback and adds it to the collection of callbacks or subscriptions. See server documentation for a summary of these criteria.
(rcvr reflect.Value, typ reflect.Type)
| 108 | // for a RPC callback or a subscription callback and adds it to the collection of callbacks or subscriptions. See server |
| 109 | // documentation for a summary of these criteria. |
| 110 | func suitableCallbacks(rcvr reflect.Value, typ reflect.Type) (callbacks, subscriptions) { |
| 111 | callbacks := make(callbacks) |
| 112 | subscriptions := make(subscriptions) |
| 113 | |
| 114 | METHODS: |
| 115 | for m := 0; m < typ.NumMethod(); m++ { |
| 116 | method := typ.Method(m) |
| 117 | mtype := method.Type |
| 118 | mname := formatName(method.Name) |
| 119 | if method.PkgPath != "" { // method must be exported |
| 120 | continue |
| 121 | } |
| 122 | |
| 123 | var h callback |
| 124 | h.isSubscribe = isPubSub(mtype) |
| 125 | h.rcvr = rcvr |
| 126 | h.method = method |
| 127 | h.errPos = -1 |
| 128 | |
| 129 | firstArg := 1 |
| 130 | numIn := mtype.NumIn() |
| 131 | if numIn >= 2 && mtype.In(1) == contextType { |
| 132 | h.hasCtx = true |
| 133 | firstArg = 2 |
| 134 | } |
| 135 | |
| 136 | if h.isSubscribe { |
| 137 | h.argTypes = make([]reflect.Type, numIn-firstArg) // skip rcvr type |
| 138 | for i := firstArg; i < numIn; i++ { |
| 139 | argType := mtype.In(i) |
| 140 | if isExportedOrBuiltinType(argType) { |
| 141 | h.argTypes[i-firstArg] = argType |
| 142 | } else { |
| 143 | continue METHODS |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | subscriptions[mname] = &h |
| 148 | continue METHODS |
| 149 | } |
| 150 | |
| 151 | // determine method arguments, ignore first arg since it's the receiver type |
| 152 | // Arguments must be exported or builtin types |
| 153 | h.argTypes = make([]reflect.Type, numIn-firstArg) |
| 154 | for i := firstArg; i < numIn; i++ { |
| 155 | argType := mtype.In(i) |
| 156 | if !isExportedOrBuiltinType(argType) { |
| 157 | continue METHODS |
| 158 | } |
| 159 | h.argTypes[i-firstArg] = argType |
| 160 | } |
| 161 | |
| 162 | // check that all returned values are exported or builtin types |
| 163 | for i := 0; i < mtype.NumOut(); i++ { |
| 164 | if !isExportedOrBuiltinType(mtype.Out(i)) { |
| 165 | continue METHODS |
| 166 | } |
| 167 | } |
no test coverage detected