// newRequest returns a new *Request from the method and arguments passed. func (c *Client) newRequest(method string, args *dnode.Partial) (*Request, func(interface{}, *Error)) { // Parse dnode method arguments: [options] var options callOptions args.One().MustUnmarshal(&options) // Notify the handlers registered with Kite.OnFirstRequest(). if _, ok := c.session.(*sockjsclient.WebsocketSession); !ok { c.firstRequestHandlersNotified.Do(func() { c.m.Lock() c.Kite = options.Kite c.m.Unlock() c.LocalKite.callOnFirstRequestHandlers(c) }) } request := &Request{ ID: utils.RandomString(16), Method: method, Args: options.WithArgs, LocalKite: c.LocalKite, Client: c, Auth: options.Auth, Context: cache.NewMemory(), } // Call response callback function, send back our response callFunc := func(result interface{}, err *Error) { if options.ResponseCallback.Caller == nil { return } // Only argument to the callback. response := Response{ Result: result, Error: err, } if err := options.ResponseCallback.Call(response); err != nil { c.LocalKite.Log.Error(err.Error()) } } return request, callFunc }
func NewMemKeyPairStorage() *MemKeyPairStorage { return &MemKeyPairStorage{ id: cache.NewMemory(), public: cache.NewMemory(), } }