type BufferedBrokerWriter interface {
io.Writer
}
// иначе нужно будет писать вот так
type BufferedBrokerWriter interface {
Write(p []byte) (n int, err error)
}
package main
import (
"bytes"
"io"
)
type BufferedBrokerWriter struct {
buffer bytes.Buffer
}
func NewBufferedBrokerWriter() *BufferedBrokerWriter {
return &BufferedBrokerWriter{}
}
func (bw *BufferedBrokerWriter) Write(p []byte) (n int, err error) {
return bw.buffer.Write(p)
}
func (bw *BufferedBrokerWriter) Read(p []byte) (n int, err error) {
return bw.buffer.Read(p)
}
func main() {
// подключаетесь к вашему брокеру сообщений,
bw := NewBufferedBrokerWriter()
SetStdout(bw)
scanner := bufio.NewScanner(bw)
linesCnt := 0
for scanner.Scan() {
fmt.Println(`line:`, scanner.Text()) // для примера (чтобы вы увидели, что данные приходят корректно)
linesCnt++
if linesCnt >= 20 {
// пишите в брокер
linesCnt = 0
}
}
}
var name string
rows.Scan(&name);
type Slice struct {
Data uintptr
Len int
Cap int
}
package main
import (
"fmt"
"reflect"
)
func modify(input *[]int, newLen int) {
val := reflect.Indirect(reflect.ValueOf(input))
val.SetLen(newLen)
}
func main() {
input := []int{1, 2, 3}
fmt.Printf("Before: %p, value: %v\n", &input, input)
modify(&input, len(input) - 1)
fmt.Printf("After: %p, value: %v\n", &input, input)
}
Before: 0xc00000c060, value: [1 2 3]
After: 0xc00000c060, value: [1 2]
body, hasBody := response[`body`].([]yourStruct)
package main
import (
"encoding/json"
"fmt"
)
func main() {
jsonBytes := []byte(`{
"header": "test header",
"body": {
"code": 10,
"message": "response message"
}
}`)
response := map[string]interface{}{}
err := json.Unmarshal(jsonBytes, &response)
if err != nil {
panic(err.Error())
}
header, hasHeader := response[`header`].(string)
if hasHeader {
fmt.Printf("Response header: %s\n", header)
}
body, hasBody := response[`body`].(map[string]interface{})
if hasBody {
message, hasMessage := body[`message`].(string)
if hasMessage {
fmt.Printf("Response message: %s\n", message)
}
}
}
log.Println("===========================")
log.Printf("entity: %+v\n", entity.Header)
log.Printf("entity: %+v\n", entity.Header.Get("X-Yandex-Sender-Uid"))
log.Printf("entity: %+v\n", entity.Header.Values("From"))
log.Println("===========================")
ffmpeg file1.mp3 file2.mp3 silence1sec.mp3 silence1sec.mp3 output.mp3