MCPcopy Index your code
hub / github.com/koding/kite / newRequest

Method newRequest

request.go:135–178  ·  view source on GitHub ↗

newRequest returns a new *Request from the method and arguments passed.

(method string, args *dnode.Partial)

Source from the content-addressed store, hash-verified

133
134// newRequest returns a new *Request from the method and arguments passed.
135func (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.

Callers 1

runMethodMethod · 0.95

Calls 7

contextMethod · 0.95
MustUnmarshalMethod · 0.80
OneMethod · 0.80
DoMethod · 0.80
CallMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected