newRequest returns a new *Request from the method and arguments passed.
(method string, args *dnode.Partial)
| 133 | |
| 134 | // newRequest returns a new *Request from the method and arguments passed. |
| 135 | func (c *Client) newRequest(method string, args *dnode.Partial) (*Request, func(interface{}, *Error)) { |
| 136 | // Parse dnode method arguments: [options] |
| 137 | var options callOptions |
| 138 | args.One().MustUnmarshal(&options) |
| 139 | |
| 140 | // Notify the handlers registered with Kite.OnFirstRequest(). |
| 141 | if _, ok := c.session.(*sockjsclient.WebsocketSession); !ok { |
| 142 | c.firstRequestHandlersNotified.Do(func() { |
| 143 | c.m.Lock() |
| 144 | c.Kite = options.Kite |
| 145 | c.m.Unlock() |
| 146 | c.LocalKite.callOnFirstRequestHandlers(c) |
| 147 | }) |
| 148 | } |
| 149 | |
| 150 | request := &Request{ |
| 151 | ID: utils.RandomString(16), |
| 152 | Method: method, |
| 153 | Args: options.WithArgs, |
| 154 | LocalKite: c.LocalKite, |
| 155 | Client: c, |
| 156 | Auth: options.Auth, |
| 157 | Context: c.context(), |
| 158 | } |
| 159 | |
| 160 | // Call response callback function, send back our response |
| 161 | callFunc := func(result interface{}, err *Error) { |
| 162 | if options.ResponseCallback.Caller == nil { |
| 163 | return |
| 164 | } |
| 165 | |
| 166 | // Only argument to the callback. |
| 167 | response := Response{ |
| 168 | Result: result, |
| 169 | Error: err, |
| 170 | } |
| 171 | |
| 172 | if err := options.ResponseCallback.Call(response); err != nil { |
| 173 | c.LocalKite.Log.Error(err.Error()) |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | return request, callFunc |
| 178 | } |
| 179 | |
| 180 | // authenticate tries to authenticate the user by selecting appropriate |
| 181 | // authenticator function. |
no test coverage detected