发送带有标题文本的二进制数据

I am making a service in Golang & Gorilla WebSocket which will convert speech to text, by using Microsoft Bing speech service. For reference

https://docs.microsoft.com/en-us/azure/cognitive-services/speech/api-reference-rest/websocketprotocol

javascript implementation

https://github.com/Azure-Samples/SpeechToText-WebSockets-Javascript

Here we need to send text data as well as audio data with headers. I am able to send text data but unable to send audio binary data with headers.

Please suggest me how to send data

Thanks Dinesh Gupta

After a lot of Googling, I make below solution whether it good or worst. Please provide where I may make improvements.

I have created 2 bytes for a header, then the length of the header string and finally the length of the buffered data. The code is below:

import(
   "encoding/binary"
   "fmt"
   "time"
   "strings"
   "encoding/json"
)
func BufferToBytes(buffer *[]byte, requestId string) *[]byte{
   headersString := GetHeaders("audio", requestId, "audio/x-wav")
   headersString = strings.Replace(headersString, "
", "
", -1)
   headerInt8Array := []byte(headersString)
   payload := make([]byte,2)
   binary.BigEndian.PutUint16(payload, uint16(len(headerInt8Array)))//till 1st part
   t := make([]byte, len(headerInt8Array))
   for i := 0; i < len(headerInt8Array); i++ {
    t[i] = headerInt8Array[i];
   }
   payload = append(payload, t...)//till 2nd part
   payload = append(payload, *buffer...)//final part
   return &payload;
}

func GetHeaders(params... string) string{
    header := fmt.Sprintf("path: %s
", params[0])
    header += fmt.Sprintf("x-requestid: %s
",params[1])//request id
    header += fmt.Sprintf("x-timestamp: %s
",GetTimestamp())// timestamp
    header += fmt.Sprintf("content-type: %s
",params[2])////content type
    return header
}

func GetTimestamp() string {
   format := "2006-01-02T15:04:05.000Z"
   return time.Now().UTC().Format(format)
}

Then this data is accepted by MS bing.

Thanks