// Communicate with the server engine to exchange data
350089
func (r *GoRequest) Get(key int) (value interface{}, err error) {
	switch key {
	case HTTP_SERVER_HEADER:
		value = r.GetHeader()
	case HTTP_MULTIPART_FORM:
		value, err = r.GetMultipartForm()
	case HTTP_QUERY:
		value = r.Original.URL.Query()
	case HTTP_FORM:
		value, err = r.GetForm()
	case HTTP_REQUEST_URI:
		value = r.Original.URL.String()
	case HTTP_REQUEST_CONTEXT:
		value = r.Original.Context()
	case HTTP_REMOTE_ADDR:
		value = r.Original.RemoteAddr
	case HTTP_METHOD:
		value = r.Original.Method
	case HTTP_PATH:
		value = r.Original.URL.Path
	case HTTP_HOST:
		value = r.Original.Host
	case HTTP_URL:
		value = r.Original.URL
	case HTTP_BODY:
		value = r.Original.Body
	default:
		err = ENGINE_UNKNOWN_GET
	}

	return
}
116081
func (sc *serverConn) send(m *msg) error {
	m.Magic = magicSend
	m.ExtraLen = sizeOfExtras(m.iextras)
	m.KeyLen = uint16(len(m.key))
	m.BodyLen = uint32(m.ExtraLen) + uint32(m.KeyLen) + uint32(len(m.val))
	m.Opaque = sc.opq
	sc.opq++

	// Request
	err := binary.Write(sc.buf, binary.BigEndian, m.header)
	if err != nil {
		return wrapError(StatusNetworkError, err)
	}

	for _, e := range m.iextras {
		err = binary.Write(sc.buf, binary.BigEndian, e)
		if err != nil {
			return wrapError(StatusNetworkError, err)
		}
	}

	_, err = io.WriteString(sc.buf, m.key)
	if err != nil {
		return wrapError(StatusNetworkError, err)
	}

	_, err = io.WriteString(sc.buf, m.val)
	if err != nil {
		return wrapError(StatusNetworkError, err)
	}

	// Make sure write does not block forever
	sc.conn.SetWriteDeadline(time.Now().Add(sc.config.ConnectionTimeout))
	_, err = sc.buf.WriteTo(sc.conn)
	if err != nil {
		return wrapError(StatusNetworkError, err)
	}

	return nil
}
199781
func (rm *ReceivedMessage) acknowledge(status uint64) error {
	return rm.receiver.(*receiver).engine().Inject(func() {
		// Deliveries are valid as long as the connection is, unless settled.
		rm.pDelivery.SettleAs(uint64(status))
	})
}
47131
func (c *Connection) Server() (ServerResponse, error) {
	var response ServerResponse

	_, cur, err := c.Query(c.contextFromConnectionOpts(), Query{
		Type: p.Query_SERVER_INFO,
	})
	if err != nil {
		return response, err
	}

	if err = cur.One(&response); err != nil {
		return response, err
	}

	if err = cur.Close(); err != nil {
		return response, err
	}

	return response, nil
}
686556
func (c *Config) Exchange(code string) (*oauth2.Token, error) {
	config := c.getConfig()
	token, err := config.Exchange(c.getContext(), code)
	return token, fromError(err)
}
530097
func (mdcli2 *Mdcli2) Send(service string, request ...string) (err error) {
	//  Prefix request with protocol frames
	//  Frame 0: empty (REQ emulation)
	//  Frame 1: "MDPCxy" (six bytes, MDP/Client x.y)
	//  Frame 2: Service name (printable string)

	req := make([]string, 3, len(request)+3)
	req = append(req, request...)
	req[2] = service
	req[1] = MDPC_CLIENT
	req[0] = ""
	if mdcli2.verbose {
		log.Printf("I: send request to '%s' service: %q\n", service, req)
	}
	_, err = mdcli2.client.SendMessage(req)
	return
}
768733
func (e *ExchangeMessage) BindJSON(v interface{}) error {
	switch t := e.body.(type) {
	case string:
		return json.Unmarshal([]byte(t), &v)
	case []byte:
		return json.Unmarshal(t, &v)
	case error:
		return t
	default:
		return errors.New("Invalid datatype")
	}
}
416245
func (t *Transport) Exchange(code string) (*Token, error) {
	if t.Config == nil {
		return nil, OAuthError{"Exchange", "no Config supplied"}
	}

	// If the transport or the cache already has a token, it is
	// passed to `updateToken` to preserve existing refresh token.
	tok := t.Token
	if tok == nil && t.TokenCache != nil {
		tok, _ = t.TokenCache.Token()
	}
	if tok == nil {
		tok = new(Token)
	}
	err := t.updateToken(tok, url.Values{
		"grant_type":   {"authorization_code"},
		"redirect_uri": {t.RedirectURL},
		"scope":        {t.Scope},
		"code":         {code},
	})
	if err != nil {
		return nil, err
	}
	t.Token = tok
	if t.TokenCache != nil {
		return tok, t.TokenCache.PutToken(tok)
	}
	return tok, nil
}
728970
func (service *Service) Send(ctx context.Context, code int, body interface{}) error {
	r := ContextResponse(ctx)
	if r == nil {
		return fmt.Errorf("no response data in context")
	}
	r.WriteHeader(code)
	return service.EncodeResponse(ctx, body)
}
665335
func (swap *Swap) send() {
	if swap.local.BuyAt != nil && swap.balance < 0 {
		amount := big.NewInt(int64(-swap.balance))
		amount.Mul(amount, swap.remote.SellAt)
		promise, err := swap.Out.Issue(amount)
		if err != nil {
			log.Warn(fmt.Sprintf("<%v> cannot issue cheque (amount: %v, channel: %v): %v", swap.proto, amount, swap.Out, err))
		} else {
			log.Warn(fmt.Sprintf("<%v> cheque issued (amount: %v, channel: %v)", swap.proto, amount, swap.Out))
			swap.proto.Pay(-swap.balance, promise)
			swap.balance = 0
		}
	}
}
1273886
func SendMessage(serverID, to, method, message string) error {
	buffer := []byte(message)
	return SendtBytes(serverID, to, method, buffer)
}
396445
func (s *ConfigService) GetServerInfo() (*ServerInfo, *Response, error) {
	u := "config/server/info"

	req, err := s.client.NewRequest("GET", u, nil)
	if err != nil {
		return nil, nil, err
	}

	v := new(ServerInfo)
	resp, err := s.client.Do(req, v)
	if err != nil {
		return nil, resp, err
	}

	return v, resp, err
}
440046
func (s *StdoutClient) send(stat string, format string, value interface{}) error {
	stat = strings.Replace(stat, "%HOST%", Hostname, 1)
	// if sending tcp append a newline
	format = fmt.Sprintf("%s%s:%s\n", s.prefix, stat, format)
	_, err := fmt.Fprintf(s.FD, format, value)
	return err
}
580341
func WriteServerMessage(w io.Writer, op ws.OpCode, p []byte) error {
	return WriteMessage(w, ws.StateServerSide, op, p)
}
334689
func (e *ExchangeMessage) SetHeader(k, v string) {
	e.head.Add(k, v)
}
511683
func (a Authenticator) Exchange(code string) (*oauth2.Token, error) {
	return a.config.Exchange(a.context, code)
}
882532
func (client *rateClient) SendExchangeUpdate(update *dcrrates.ExchangeRateUpdate) (err error) {
	for i := range client.exchanges {
		if client.exchanges[i] == update.Token {
			err = client.stream.Send(update)
			return
		}
	}
	return
}