// InvokeMethod invokes user code via HTTP
InvokeMethod invokes user code via HTTP
// InvokeMethod invokes user code via HTTP
func (h *Channel) InvokeMethod(invokeRequest *channel.InvokeRequest) (*channel.InvokeResponse, error) {
	req := fasthttp.AcquireRequest()
	uri := fmt.Sprintf("%s/%s", h.baseAddress, invokeRequest.Method)
	req.SetRequestURI(uri)
	req.SetBody(invokeRequest.Payload)
	if val, ok := invokeRequest.Metadata[QueryString]; ok {
		req.URI().SetQueryString(val)
	}
	if invokeRequest.Metadata != nil {
		if val, ok := invokeRequest.Metadata["headers"]; ok {
			headers := strings.Split(val, "&__header_delim__&")
			for _, h := range headers {
				kv := strings.Split(h, "&__header_equals__&")
				req.Header.Set(kv[0], kv[1])
			}
		}
	}
	contentType := getContentType(invokeRequest.Metadata)
	req.Header.SetContentType(contentType)
	method := invokeRequest.Metadata[HTTPVerb]
	if method == "" {
		method = Post
	}
	req.Header.SetMethod(method)
	resp := fasthttp.AcquireResponse()
	if h.ch != nil {
		h.ch <- 1
	}
	err := h.client.Do(req, resp)
	if h.ch != nil {
		<-h.ch
	}
	if err != nil {
		return nil, err
	}
	body := resp.Body()
	arr := make([]byte, len(body))
	copy(arr, body)
	statusCode := resp.StatusCode()
	headers := []string{}
	resp.Header.VisitAll(func(key []byte, value []byte) {
		headers = append(headers, fmt.Sprintf("%s&__header_equals__&%s", string(key), string(value)))
	})
	metadata := map[string]string{HTTPStatusCode: fmt.Sprintf("%v", statusCode)}
	if len(headers) > 0 {
		metadata["headers"] = strings.Join(headers, "&__header_delim__&")
	}
	fasthttp.ReleaseRequest(req)
	fasthttp.ReleaseResponse(resp)
	return &channel.InvokeResponse{
		Metadata: metadata,
		Data:     arr,
	}, nil
}
func ( h * Channel ) InvokeMethod ( invokeRequest * channel . InvokeRequest ) ( * channel . InvokeResponse , error ) { req := fasthttp . AcquireRequest ( ) uri := fmt . Sprintf ( " " , h . baseAddress , invokeRequest . Method ) req . SetRequestURI ( uri ) req . SetBody ( invokeRequest . Payload ) if val , ok := invokeRequest . Metadata [ QueryString ] ; ok { req . URI ( ) . SetQueryString ( val ) } if invokeRequest . Metadata != nil { if val , ok := invokeRequest . Metadata [ " " ] ; ok { headers := strings . Split ( val , " " ) for _ , h := range headers { kv := strings . Split ( h , " " ) req . Header . Set ( kv [ 0 ] , kv [ 1 ] ) } } } contentType := getContentType ( invokeRequest . Metadata ) req . Header . SetContentType ( contentType ) method := invokeRequest . Metadata [ HTTPVerb ] if method == " " { method = Post } req . Header . SetMethod ( method ) resp := fasthttp . AcquireResponse ( ) if h . ch != nil { h . ch <- 1 } err := h . client . Do ( req , resp ) if h . ch != nil { <- h . ch } if err != nil { return nil , err } body := resp . Body ( ) arr := make ( [ ] byte , len ( body ) ) copy ( arr , body ) statusCode := resp . StatusCode ( ) headers := [ ] string { } resp . Header . VisitAll ( func ( key [ ] byte , value [ ] byte ) { headers = append ( headers , fmt . Sprintf ( " " , string ( key ) , string ( value ) ) ) } ) metadata := map [ string ] string { HTTPStatusCode : fmt . Sprintf ( " " , statusCode ) } if len ( headers ) > 0 { metadata [ " " ] = strings . Join ( headers , " " ) } fasthttp . ReleaseRequest ( req ) fasthttp . ReleaseResponse ( resp ) return & channel . InvokeResponse { Metadata : metadata , Data : arr , } , nil }
InvokeMethod invokes user code via HTTP
InvokeMethod invokes user code via HTTP