4
4
4sadly2020-05-04 17:57:51
go
4sadly, 2020-05-04 17:57:51

How to concatenate arrays of bytes into one array?

messageReturn := []byte("Your message is: ")+message
    fmt.Println(string(message)) //эта строка выводит пустую строку, хотя отправляется текст
    if err := conn.WriteMessage(websocket.TextMessage, messageReturn); err != nil {
      log.Println(err)
      return
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Mamonov, 2020-05-04
@4sadly

You can use bytes.Buffer (the fastest concatenation) for Go, like this:

messageReturn := bytes.NewBufferString("Your message is: ")
messageReturn.Write(message)
conn.WriteMessage(websocket.TextMessage, messageReturn.Bytes())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question